Problems > Subtraction Game {2,5}

Subtraction Game {2,5}

Difficulty: 1800 5000 ms 128 MB

game-theory grundy

Several piles; a move removes from one pile a number of stones in {2, 5}. A player who cannot move loses. With both playing optimally and the first player moving first, who wins?

Input: the first line has the number of piles K; the second line has the pile sizes.

Output: First or Second.

Constraints:

  • 1 ≤ K ≤ 105
  • 0 ≤ pile size ≤ 104

Sample Tests

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

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.