Nim Game Without Repeats
Time limit2sMemory limit512 MB
Nim with piles of size up to 60, but each specific removal size can be used at most once per pile; decide the winner under optimal play.
- Level
Hard9 of 10
- Topics
- Game theory, Dynamic programming, Bit manipulation, Combinatorics
- Solved
- No attempts yet
Statement
Koosaga and Cubelover are about to play a Nim game. The game uses piles of stones, and the -th pile contains stones. The two players take turns. Each turn consists of choosing one pile and removing one or more stones from that pile.
Koosaga moves first, and the player who cannot remove any stone on their turn loses.
They have played this game so many times that today they are adding one new rule.
The new rule is that the same number of stones cannot be removed from a pile twice. For example, if a player has taken 4 stones from a pile, then no one may take 4 stones from that pile again. This rule applies to both players and applies to each pile independently.
Write a program that determines who wins when both players play optimally.
Input
The first line gives the number of piles . The second line gives the numbers of stones in the piles .
Output
Print "koosaga" if Koosaga wins the game, and "cubelover" if Cubelover wins.