TLE '17 Contest 5 P4 - Cloning
View as PDF
Dankey Kang, Croneria's most fearsome villain, has decided to increase the size of his gang by creating many clone soldiers. Each clone can be one of two types, type 0 or type 1.
There are two possible methods of cloning, which can be described as a string of clone types  and 
. That is, 
 and 
 are strings only containing 
0 and 1.
Initially, there is one clone of type 0 in the line. Then, the following process will continue indefinitely:
- The first clone in the line will leave the front of the line to fight.
 - If that clone's type is 
0, a string of clones matchingwill be added to the end of the line, in order.
 - If that clone's type is 
1, a string of clones matchingwill be added to the end of the line, in order.
 
Dankey Kang is then interested in  of the clones. In particular, he wants to know the type of the 
 clone that leaves the line, indexed starting at 
.
Constraints
For all subtasks:
| Subtask | Points | Additional Constraints | 
|---|---|---|
| 1 | 5 | |
| 2 | 15 | |
| 3 | 20 | |
| 4 | 25 | |
| 5 | 25 | |
| 6 | 10 | No additional constraints. | 
Input Specification
The first line will contain string .
The second line will contain string .
The third line will contain the integer .
On the next  lines, the 
 line will contain integer 
.
Output Specification
Output  lines. The 
 line of output will contain the type of the 
 clone that leaves the line.
Sample Input
100
10
9
1
2
3
4
5
6
7
8
9
Sample Output
0
1
0
0
1
0
1
0
0
Comments