atcoder#AGC048D. [AGC048D] Pocky Game
[AGC048D] Pocky Game
Score : points
Problem Statement
There are piles of stones lying in a row. The -th pile from the left contains stones.
Two players, FirstLeft and SecondRight, play a game. They alternately play a turn, with FirstLeft going first. In each turn, the player does the following operation:
- In FirstLeft's turn: he removes one or more stones from the leftmost pile with one or more stones.
- In SecondRight's turn: he removes one or more stones from the rightmost pile with one or more stones.
The player who becomes unable to play his turn loses. Determine the winner of the game when the players act optimally.
Solve test cases in an input file.
Constraints
Input
Input is given from Standard Input in the following format. The first line of input is as follows:
Then, test cases follow, each of which is in the following format:
Output
For each test case, print First
if FirstLeft wins, and print Second
if SecondRight wins.
Use one line for each case.
3
1
10
2
3 2
3
2 1 2
First
First
Second
For example, in the third game, one possible scenario is as follows:
- FirstLeft takes stones from the leftmost pile. The piles now contain stone(s).
- SecondRight takes stone from the rightmost pile. The piles now contain stone(s).
- FirstLeft takes stone from the middle pile. The piles now contain stone(s).
- SecondRight takes stone from the rightmost pile. The piles now contain stones.
- FirstLeft is unable to do his operation and loses.