This page is still under construction.

Parts of this page are still being built. What you see may change.

Cups and Beans

Time limit1sMemory limit256 MB

Summary
Beans sit in cups 1 through N-1, each with a move limit C_i; players alternate sliding one bean to a lower cup and whoever cannot move loses. Decide the winner.
Level

Hard8 of 10

Topics
Game theory, Dynamic programming, Combinatorics, Math
Solved
No attempts yet

Problem

There are NN cups numbered 0 through N−1N-1. For each ii (1≤i≤N−11 \leq i \leq N-1), cup ii contains AiA_i beans, and this cup is labeled with an integer CiC_i.

Two people play the following game:

  • In each turn, the player chooses a bean from one of the cups except cup 00.
  • If he chooses a bean from cup ii, he must move it to one of the cups i−Ci,…,i−1i-C_i, \ldots, i-1.
  • The players take turns alternately. If a player can't choose a bean, he loses.

Who wins if both players play optimally?

Input

NN
C1C_1 A1A_1
C2C_2 A2A_2
⋮\vdots
CN−1C_{N-1} AN−1A_{N-1}

Output

Print the name of the winner: "First" or "Second".

Constraints

  • 2≤N≤1052 \leq N \leq 10^5
  • 1≤Ci≤i1 \leq C_i \leq i
  • 0≤Ai≤1090 \leq A_i \leq 10^9
  • At least one of AiA_i is nonzero.
  • All values in the input are integers.

Hint

Notes on Sample 1:

  • In the first turn, the first player must move a bean from 22 to 11.
  • In the second turn, the second player must move a bean from 11 to 00.
  • In the third turn, the first player can't choose a bean and loses.

Examples3

  1. Example 1

    Input
    3
    1 0
    1 1
    
    Expected output
    Second
    
  2. Example 2

    Input
    7
    1 1
    2 0
    1 0
    2 0
    4 1
    3 0
    
    Expected output
    First
    
  3. Example 3

    Input
    7
    1 1
    2 0
    1 9
    2 10
    4 3
    3 5
    
    Expected output
    Second