Problems > Race to N

Race to N

Difficulty: 1200 2000 ms 128 MB

math games

Players alternately add 1, 2 or 3 to a running total starting at 0; whoever says exactly N wins. Who wins with perfect play?

Input: one integer N.

Output: FIRST or SECOND.

Constraints:

  • 1 ≤ N ≤ 1018

Sample Tests

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