Alice and Bob are playing a modified game of Nim. Initially, there are some non-empty piles of stones in front of them. They take turns, and Alice takes the first turn.
On a single turn, a player must do the following actions in order:
- Remove some number of piles of stones — at least one but no more than half the number of piles.
- Choose the same number of piles of remaining stones, and split each of those piles into two non-empty piles.
Notice that after each valid move, there should be the same number of non-empty piles of stones as at the start of the game. A player who cannot perform all the actions on their turn loses the game.
You are given many games, and for each one, you’d like to determine who would win if both players play optimally.