Problem A
Hackenbush Bamboo
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 Hackenbush bamboo. This is a position in the game Hackenbush where all edges are green (can be chopped by either player) and all edges are on straight paths from the ground, which do not split.
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 single integer $0 \leq n \leq 10^3$, the number of bamboo stalks in the game. The next line contains $n$ integers $1 \leq h_i \leq 10^9$, the height of the $i$-th stalk.
Output
If the value of the game is $\ast k$ then print *k. The value of the game is always of this form.
Sample Input 1 | Sample Output 1 |
---|---|
5 2 3 2 1 4 |
*6 |
Sample Input 2 | Sample Output 2 |
---|---|
5 3 3 1 2 3 |
*0 |