HIM
**Attention! This problem is presented in demonstration mode.**
**Currently, there are no tests in the system.**
The game of Nim involves two players and is played with between 2 and 100 piles of stones. Players alternate turns, and the winner is the one who takes the last stone. During each turn, a player can remove stones from up to K piles (where 1 ≤ K ≤ N), but must take at least one stone. Initially, each pile contains between 1 and 999,999,999 stones.
**Task**: Develop a program that plays Nim and aims to win if possible.
**Technical Conditions**: During evaluation, your program will be linked with a module named CHECK.* (available in PAS, C, or CPP). This module includes three functions: 'InitGame', 'JudgeTurn', and 'PartTurn'.
- The 'InitGame' function reads input data from a test file. It has four output parameters: 'N' and 'K' (the number of piles and the maximum number of piles from which stones can be taken), an array 'H' (the number of stones in each pile), and 'First' (indicating who plays first). After calling this function, 'N' and 'K' will be set to their respective values, the first 'N' elements of the array 'H' will reflect the stone counts in the piles, and 'First' will be 0 if the jury's program plays first, or 1 if the participant's program does. Your program should not read input data directly; this should only be done using the 'InitGame' function.
- Use the 'JudgeTurn' function to obtain the jury's next move. The function outputs an array 'T', where the first 'N' elements indicate the number of stones the jury's program takes from each pile. The move will always comply with the game rules.
- Use the 'PartTurn' function to communicate your move to the jury's program. Record your move in the first 'N' elements of the array 'T'.
Each function returns 1 if successful, or 0 if an error occurs, at which point your program can terminate.
You will receive a diskette containing the CHECK module and a main module (NIM_KBD.*) to help you start working on the solution without technical delays. The CHECK module reads data from the keyboard, verifies the participant's moves and function call sequences, but plays poorly. The jury will use a different module during evaluation. The NIM_KBD module calls the CHECK module's functions in the required order but reads the participant's next move from the keyboard instead of calculating it. Your task is to implement the 'MakeTurn' function to compute the next move. While using the provided files is not mandatory, your solution must correctly interact with the CHECK module.
**Note**: During evaluation, the tests will include specific cases such as:
1) N=2, K=1; 2) N=3, K=1; 3) N > 3, K=1.
Solution program files: NIM.PAS, NIM.CPP, NIM.C.
**Example**
- Participant: (1,1,0,0), remaining (2,3,5,6) - Jury: (0,0,1,1), remaining (2,3,4,5) - Participant: (0,0,1,1), remaining (2,3,3,4) - Jury: (1,1,0,0), remaining (1,2,3,4) - Participant: (0,0,0,4), remaining (1,2,3,0) - Jury: (0,0,1,0), remaining (1,2,2,0) - Participant: (1,2,0,0), remaining (0,0,2,0) - Jury: (0,0,2,0), remaining (0,0,0,0)
The jury won (but the participant had a chance!).