Problems > Misere Nim

Misere Nim

Difficulty: 2000 4000 ms 128 MB

game-theory nim

Misere Nim: same moves as Nim, but the player who takes the last stone LOSES. Who wins with optimal play?

Input: the first line has the pile count K; the second line has the pile sizes.

Output: First or Second.

Constraints:

  • 1 ≤ K ≤ 105
  • 0 ≤ pile ≤ 109

Sample Tests

Input 1
2
1 1
Output 1
First
Input 2
3
1 2 3
Output 2
Second
Input 3
2
1 1
Output 3
First
Input 4
1
1
Output 4
Second

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.