Problems > Classic Nim

Classic Nim

Difficulty: 1500 3000 ms 128 MB

math bitwise games

N piles of stones. Players alternate removing any positive number of stones from ONE pile; taking the last stone wins. Who wins with perfect play?

Input: the first line has N; the second line has the N pile sizes.

Output: FIRST or SECOND.

Constraints:

  • 1 ≤ N ≤ 105
  • 1 ≤ piles ≤ 109

Sample Tests

Input 1
3
1 2 3
Output 1
SECOND
Input 2
2
5 5
Output 2
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.