Submit | All submissions | Best solutions | Back to list |
HS09NLG2 - Nim-like game 2 |
It's time to help Julia to play with Robert again. This time the players pick up sticks from four stacks. A move consists of taking away a positive number of sticks from exactly two chosen stacks.
Players take turns to move. The one who cannot make a move loses. Write a program which determines if for a given set of starting sizes of stacks Julia who moves first can force a win. If so help her making the winning move.
If there are several possibilities of such a move, then choose the one which is lexicographically last, i.e. in which you use the stack with the smallest possible index, taking the largest number of sticks.
Input
In the first line of input there is one integer C (1 ≤C ≤ 1 000), representing the number of test cases. Each test case is described by four integers a[1], a[2], a[3], a[4] (0<= a[i]<= 1 000 000), where a[i] denotes the number of sticks in the i-th stack.
Output
For each testcase write a sentence of the form: '$name wins.' as in the example. And if Julia can win write out four numbers two of which are nonzero - the numbers of sticks to take from each stack. Print a blank line after each testcase.
Example
Input:
2
1 1 1 1
2 2 3 4
Output:
Robert wins.
Julia wins.
0 0 1 2
Scoring
For solving this problem you will score 10 points.
Added by: | Adam Dzedzej |
Date: | 2010-03-15 |
Time limit: | 0.200s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: CLOJURE NODEJS OBJC PERL6 SQLITE VB.NET |
Resource: | High School Programming League (thanks to Talent Association) |