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 Oracle

Subtraction Game Oracle

Difficulty: 1800 6000 ms 128 MB

dp games

A single pile of n stones; a move removes exactly s stones for some s in the allowed set S; last to move wins. For each query n, print the winner.

Input: the first line has |S| and Q; the second line has the set S; each of the next Q lines has a pile size n.

Output: one line per query: FIRST or SECOND.

Constraints:

  • 1 ≤ |S| ≤ 10
  • 1 ≤ Q ≤ 104
  • 0 ≤ n ≤ 104
  • 1 ≤ s ≤ 20

Sample Tests

Input 1
2 3
1 2
0
3
4
Output 1
SECOND
SECOND
FIRST
Input 2
1 1
2
5
Output 2
SECOND

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