Submit | All submissions | Best solutions | Back to list |
HS09GAME - Strategy game |
Julia and Robert are playing a game, in which they pick up sticks from heaps. The game starts with n heaps, the i-th heap contains a[i] sticks. In each turn the players choose a heap and take away 2, 3 or 5 sticks from it (removed sticks do not return to the game). Julia starts the game making the first move. The one, who cannot make a move, loses the game, and the other player wins. Can you decide who will win the game, assuming that both players follow a perfect strategy ? If Julia is the winner, point out her winning move! If there are several possibilities for such a move, then choose the one in which the largest number of sticks is taken away. If there are still several such moves, choose the one, in which sticks are taken from the heap of the smallest number.
Input
An integer T, denoting the number of testcases (T <= 1000). Each testcase contains one integer n, the number of heaps, followed by n non-negative integers: a[1], a[2], ..., a[n], where a[i] is the number of sticks of the i-th heap.
Constraints:
1 <= n <= 1000,
0 <= a[i] <= 1000000000.
Output
Please consult the example below for a specification of the required output format. Print a blank line after each testcase.
Example
Input: 5 1 5 1 7 4 1 2 3 4 10 1 2 3 4 5 6 7 8 9 10 2 1000000 1000001 Output: Julia wins. Take 5 sticks from heap number 1. Robert wins. Julia wins. Take 3 sticks from heap number 4. Julia wins. Take 5 sticks from heap number 6. Julia wins. Take 5 sticks from heap number 1.
Added by: | Robert Gerbicz |
Date: | 2009-09-02 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 CLOJURE PERL6 |
Resource: | High School Programming League |