#D685. Tournament

    ID: 571 Type: Default 2000ms 268MiB

Tournament

Tournament

Problem statement

A 2 2 human-player match-up game tournament is about to take place in front of Kyoto University Camphor Tree.

There are 2N 2 ^ N participants in this tournament, numbered from 1 1 to 2N 2 ^ N .

Winning or losing when 2 2 of participants fight is represented by the 2N1 2 ^ N-1 string S S consisting of 0 0 and 1 1 .

When people x x and people y y (1 lex<y le2N) (1 \ le x <y \ le 2 ^ N) fight

  • When Syx=0 S_ {y-x} = 0 , the person x x wins,
  • When Syx=1 S_ {y-x} = 1 , the person y y wins

I know that.

The tournament begins with a line of participants and proceeds as follows:

  1. Make a pair of 2 2 people from the beginning of the column. For every pair, 2 2 people in the pair fight.
  2. Those who win the match in 1 will remain in the line, and those who lose will leave the line.
  3. If there are more than 2 2 left, fill the column back to 1.
  4. If there are 1 1 left, that person will be the winner.

Now, the participants are initially arranged so that the i i th (1 lei le2N) (1 \ le i \ le 2 ^ N) from the beginning becomes the person Pi P_i .

Solve the following problem for all integers k k that satisfy 0 lek le2N1 0 \ le k \ le 2 ^ N-1 .

  • From the initial state, the first k k 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

  • 1 leqN leq18 1 \ leq N \ leq 18
  • N N is an integer.
  • S S is a 2N1 2 ^ N-1 string consisting of 0 0 and 1 1 .
  • P P is a permutation of integers from 1 1 to 2N 2 ^ N .

input

Input is given from standard input in the following format.

N N S1S2 ldotsS2N1 S_1S_2 \ ldots S_ {2 ^ N-1} P1 P_1 P2 P_2  ldots \ ldots P2N P_ {2 ^ N}

output

Output 2N 2 ^ N lines.

In the i i line (1 lei le2N) (1 \ le i \ le 2 ^ N) , output the answer to the above problem when k=i1 k = i-1 .


Input example 1

2 100 1 4 2 3

Output example 1

1 2 1 2

For example, if k=2 k = 2 , the number of participants in the moved column will be 2,3,1,4 2, 3, 1, 4 from the beginning.

When person 2 2 and person 3 3 fight, person 3 3 wins over S1=1 S_1 = 1 .

When person 1 1 and person 4 4 fight, person 1 1 wins over S3=0 S_3 = 0 .

When person 3 3 and person 1 1 fight, person 1 1 wins over S2=0 S_2 = 0 .

Therefore, if k=2 k = 2 , the winner would be 1 1 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.

N N S1S2 ldotsS2N1 S_1S_2 \ ldots S_ {2 ^ N-1} P1 P_1 P2 P_2  ldots \ ldots P2N P_ {2 ^ N}

outputFormat

output

Output 2N 2 ^ N lines.

In the i i line (1 lei le2N) (1 \ le i \ le 2 ^ N) , output the answer to the above problem when k=i1 k = i-1 .


Input example 1

2 100 1 4 2 3

Output example 1

1 2 1 2

For example, if k=2 k = 2 , the number of participants in the moved column will be 2,3,1,4 2, 3, 1, 4 from the beginning.

When person 2 2 and person 3 3 fight, person 3 3 wins over S1=1 S_1 = 1 .

When person 1 1 and person 4 4 fight, person 1 1 wins over S3=0 S_3 = 0 .

When person 3 3 and person 1 1 fight, person 1 1 wins over S2=0 S_2 = 0 .

Therefore, if k=2 k = 2 , the winner would be 1 1 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>