Problem C
Green Hackenbush
Languages
en
is

Hackenbush is a game played on edges of three colours which all connect to each other or the ground. The edges are all red, green or blue. The first player can hack red and green edges and the second blue and green edges. When a player hacks an edge it is deleted. Any edges that can’t reach the ground are discarded.
The value of a Hackenbush game with only green edges is simply the Grandy-Sprague number of that game.
You are given a position in Green Hackenbush. This is a position in the game Hackenbush where all edges are green (can be chopped by either player).
You need to determine the value of the game. As the game only has green edges this will always be an integral nimber.
Input
The first line contains a two integer
Output
If the value of the game is
Sample Input 1 | Sample Output 1 |
---|---|
10 12 -1 1 1 2 1 3 2 4 3 4 4 5 5 6 6 7 5 8 8 9 8 9 9 10 |
*2 |
Sample Input 2 | Sample Output 2 |
---|---|
1 6 -1 -1 -1 -1 -1 1 1 1 1 1 1 1 |
*2 |