atcoder#AGC045A. [AGC045A] Xor Battle
[AGC045A] Xor Battle
Score : points
Problem Statement
There are two persons, numbered and , and a variable whose initial value is . The two persons now play a game. The game is played in rounds. The following should be done in the -th round ():
- Person does one of the following:- Replace with , where represents bitwise XOR.
- Do nothing.
- Replace with , where represents bitwise XOR.
- Do nothing.
Person aims to have at the end of the game, while Person aims to have at the end of the game.
Determine whether becomes at the end of the game when the two persons play optimally.
Solve test cases for each input file.
Constraints
- is a string of length consisting of
0
and1
. - All numbers in input are integers.
Input
Input is given from Standard Input in the following format. The first line is as follows:
Then, test cases follow. Each test case is given in the following format:
Output
For each test case, print a line containing 0
if becomes at the end of the game, and 1
otherwise.
3
2
1 2
10
2
1 1
10
6
2 3 4 5 6 7
111000
1
0
0
In the first test case, if Person replaces with , we surely have at the end of the game, regardless of the choice of Person .
In the second test case, regardless of the choice of Person , Person can make with a suitable choice.