Game Theory Again
There are 'N' piles of stones where the ith pile has 'xi' stones in it. Kanhaiya and Nitish play the following game:
- Kanhaiya starts, and they alternate turns.
- In a turn, a player can choose any one of the piles of stones and divide the stones in it into any number of unequal piles such that no two of the piles you create should have the same number of stones. For example, if there 8 stones in a pile, it can be divided into one of these set of piles: (1,2,5), (1,3,4), (1,7), (2,6) or (3,5).
- The player who cannot make a move (because all the remaining piles are indivisible) loses the game.
Given the starting set of piles, who wins the game assuming both players play optimally?
The first line contains the number of test cases T. T test cases follow. The first line for each test case contains N, the number of piles initially. The next line contains N space delimited numbers, the number of stones in each of the piles.
Output T lines, one corresponding to each test case containing "KANHAIYA" if Kanhaiya wins the game and "NITISH" otherwise.
1 <= T <= 50
1 <= N <= 50
1 <= xi <= 50
1 3 4
26 48 10 28 39 40 25
For the first case, the only possible move for Kanhaiya is (4) -> (1,3). Now Nitish breaks up the pile with 3 stones into (1,2). At this point Kanhaiya cannot make any move and has lost.
Problem Setter: Rounak Tibrewal