Game with stones
Time limit1sMemory limit256 MB
Count the ways to color each of n piles black or white so that Bob wins the Steins;Game under optimal play, modulo 1000000007.
- Level
Hard9 of 10
- Topics
- Game theory, Bit manipulation, Combinatorics, Dynamic programming
- Solved
- No attempts yet
Problem
Have you ever heard of the Nim game? Most likely, yes. But you have probably never heard of a newer game called "Steins;Game". It is played with many piles of stones, and Stein means stone in German.
Alice and Bob want to play this game. The game is played as follows:
There are piles of stones arranged in a row. Each pile is colored either white or black. The -th pile has stones. Starting with Alice, the two players take turns doing one of the following:
- take any positive number of stones from the smallest black pile (the smallest one among all black piles); or
- take any positive number of stones from any white pile.
The game ends when no stones remain, and the player who makes the next move loses the game.
All piles of stones are now fixed, but they are not yet colored. Bob has bribed the referee to get the chance to paint all the piles himself. How many ways can he paint the piles so that he wins, assuming Alice and Bob both play optimally? Since the answer may be very large, output it modulo .
Input
The first line contains one integer , the number of piles in the game.
The second line contains integers , the number of stones in each pile.
Output
Print one integer on a line, the number of ways to paint the piles so that Bob wins, modulo .
Hint
For the first test case, Bob wins under any of the four ways to paint the piles.
For the second test case, the only way for Bob to win is to paint both piles black. Alice is then forced to take from the first pile on her first move, and Bob takes the whole second pile and wins.
For the third test case, no matter how Bob paints the only pile, Alice takes the whole pile and wins.