atcoder#ARC105D. [ARC105D] Let's Play Nim
[ARC105D] Let's Play Nim
Score : points
Problem Statement
We have bags numbered through and dishes numbered through . Bag contains coins, and each dish has nothing on it initially.
Taro the first and Jiro the second will play a game against each other. They will alternately take turns, with Taro the first going first. In each player's turn, the player can make one of the following two moves:
- When one or more bags contain coin(s): Choose one bag that contains coin(s) and one dish, then move all coins in the chosen bag onto the chosen dish. (The chosen dish may already have coins on it, or not.)
- When no bag contains coins: Choose one dish with coin(s) on it, then remove one or more coins from the chosen dish.
The player who first becomes unable to make a move loses. Determine the winner of the game when the two players play optimally.
You are given test cases. Solve each of them.
Constraints
- All values in input are integers.
- In one input file, the sum of does not exceed .
Input
Input is given from Standard Input in the following format:
Each case is in the following format:
Output
Print lines. The -th line should contain First
if Taro the first wins in the -th test case, and Second
if Jiro the second wins in the test case.
3
1
10
2
1 2
21
476523737 103976339 266993 706803678 802362985 892644371 953855359 196462821 817301757 409460796 773943961 488763959 405483423 616934516 710762957 239829390 55474813 818352359 312280585 185800870 255245162
Second
First
Second
- In test case , Jiro the second wins. Below is one sequence of moves that results in Jiro's win:- In Taro the first's turn, he can only choose Bag and move the coins onto Dish .
- In Jiro the second's turn, he can choose Dish and remove all coins from it, making Taro fail to make a move and lose.
- In Taro the first's turn, he can only choose Bag and move the coins onto Dish .
- In Jiro the second's turn, he can choose Dish and remove all coins from it, making Taro fail to make a move and lose.
- Note that when there is a bag that contains coin(s), a player can only make a move in which he chooses a bag that contains coin(s) and moves the coin(s) onto a dish.
- Similarly, note that when there is no bag that contains coin(s), a player can only make a move in which he chooses a dish and removes one or more coins.