#D685. Tournament
Tournament
Tournament
Problem statement
A human-player match-up game tournament is about to take place in front of Kyoto University Camphor Tree.
There are participants in this tournament, numbered from to .
Winning or losing when of participants fight is represented by the string consisting of and .
When people and people fight
- When , the person wins,
- When , the person wins
I know that.
The tournament begins with a line of participants and proceeds as follows:
- Make a pair of people from the beginning of the column. For every pair, people in the pair fight.
- Those who win the match in 1 will remain in the line, and those who lose will leave the line.
- If there are more than left, fill the column back to 1.
- If there are left, that person will be the winner.
Now, the participants are initially arranged so that the th from the beginning becomes the person .
Solve the following problem for all integers that satisfy .
- From the initial state, the first person moves to the end of the column without changing the order.
- In other words, if you list the number of participants in the moved column from the beginning, $ P_ {k + 1}, P_ {k + 2}, ..., P_ {2 ^ N}, P_1, P_2, ..., P_k $.
- Find the winner's number when you start the tournament from the line after the move.
Constraint
- is an integer.
- is a string consisting of and .
- is a permutation of integers from to .
input
Input is given from standard input in the following format.
output
Output lines.
In the line , output the answer to the above problem when .
Input example 1
2 100 1 4 2 3
Output example 1
1 2 1 2
For example, if , the number of participants in the moved column will be from the beginning.
When person and person fight, person wins over .
When person and person fight, person wins over .
When person and person fight, person wins over .
Therefore, if , the winner would be person.
Input example 2
Four 101011100101000 8 15 2 9 12 5 1 7 14 10 11 3 4 6 16 13
Output example 2
16 1 16 2 16 12 Ten 14 16 1 16 2 16 12 Ten 14
Input example 3
1 0 1 2
Output example 3
1 1
Example
Input
2 100 1 4 2 3
Output
1 2 1 2
inputFormat
input
Input is given from standard input in the following format.
outputFormat
output
Output lines.
In the line , output the answer to the above problem when .
Input example 1
2 100 1 4 2 3
Output example 1
1 2 1 2
For example, if , the number of participants in the moved column will be from the beginning.
When person and person fight, person wins over .
When person and person fight, person wins over .
When person and person fight, person wins over .
Therefore, if , the winner would be person.
Input example 2
Four 101011100101000 8 15 2 9 12 5 1 7 14 10 11 3 4 6 16 13
Output example 2
16 1 16 2 16 12 Ten 14 16 1 16 2 16 12 Ten 14
Input example 3
1 0 1 2
Output example 3
1 1
Example
Input
2 100 1 4 2 3
Output
1 2 1 2
样例
2
100
1 4 2 3
1
2
1
2
</p>