Hiring process8 levels
  1. 1 IQ Test
  2. 2 Additional Online Test (If Required)
  3. 3 Office Interview with Hiring Manager
  4. 4 Unpaid Test Task (Motivation Check)
  5. 5 Paid Test Task and Follow-Up Interview
  6. 6 Iterative Paid Test Tasks
  7. 7 Office Verification
  8. 8 Final Interview with the Founder

Problems > Subtraction Game {1,4}

Subtraction Game {1,4}

Difficulty: 1800 5000 ms 128 MB

game-theory grundy

Several piles; a move removes from one pile a number of stones in {1, 4}. 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 Statistics

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.
Ctrl+Enter submit · Ctrl+Space autocomplete · F11 fullscreen