Classic Nim
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
Discussion (opens after you solve — no spoilers before)
No comments yet.