Problems > Bounded Nim

Bounded Nim

Difficulty: 2100 4000 ms 128 MB

math games

N piles; a move removes between 1 and K stones from ONE pile; last to move wins. Determine the winner under perfect play.

Input: the first line has N and K; the second line has the N pile sizes.

Output: FIRST or SECOND.

Constraints:

  • 1 ≤ N ≤ 105
  • 1 ≤ K ≤ 100
  • 0 ≤ piles ≤ 109

Sample Tests

Input 1
2 2
4 5
Output 1
FIRST
Input 2
1 3
3
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.