시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 0 0 0 0.000%

문제

Walaweh number is a numbering sequence that is so troublesome (that's exactly where it gets its name, "Walaweh!"). Walaweh number is similar to binary number (only consist of zeros and ones) except that the length of the number is important (thus leading zeros are preserved). Note that the "length" of Walaweh numbers means the number of digits in the Walaweh numbers.

To simplify the wording, Walaweh numbers of length L will be written as WL, which denotes all Walaweh numbers with exactly L digits. Walaweh numbers (of any length) is an ordered list of numbers. The most basic (smallest) Walaweh numbers is W1 which are "0" and "1" in that order. WL can be generated from WL-1 except for W1 which is fixed. This is done by creating two clones (C1 and C2) of WL-1 then apply some operations (see below) on C1 and C2 to produce C1' and C2'. The combined list of numbers in C1' followed by the list of numbers in C2' (in that order) produces WL.

These are the 8 possible operations on C1 and C2:

  1. Append a digit zero to the end of all numbers in C1 and append a digit one to the end of all numbers in C2.
  2. Append a digit zero to the beginning of all numbers in C1 and append a digit one to the beginning of all numbers in C2.
  3. Append a digit one to the end of all numbers in C1 and append a digit zero to the end of all numbers in C2.
  4. Append a digit one to the beginning of all numbers in C1 and append a digit zero to the beginning of all numbers in C2.
  5. Reverse the order of the list of numbers in C2 and do operation 1 above.
  6. Reverse the order of the list of numbers in C2 and do operation 2 above.
  7. Reverse the order of the list of numbers in C2 and do operation 3 above.
  8. Reverse the order of the list of numbers in C2 and do operation 4 above.

W1 is fixed. W2 is generated by applying the first operation on W1. W3 is generated by applying the second operation on W2 and so on... and it will go back to the first operation again after the eighth operation. So, W9 is generated by applying the eighth operation on W8. W10 is generated by applying the first operation on W9 and so on... Walaweh!

Below is the list of W1, W2, W3, and W4 :

Walaweh Length Sequence Number Walaweh Number   Walaweh Length Sequence Number Walaweh Number
1 1 0   4 1 0001
1 2 1   4 2 0101
        4 3 0011
2 1 00   4 4 0111
2 2 10   4 5 1001
2 3 01   4 6 1101
2 4 11   4 7 1011
        4 8 1111
3 1 000   4 9 0000
3 2 010   4 10 0100
3 3 001   4 11 0010
3 4 011   4 12 0110
3 5 100   4 13 1000
3 6 110   4 14 1100
3 7 101   4 15 1010
3 8 111   4 16 1110

To give you an idea of "reverse the order of the list of numbers in C2" for the fifth to eighth operations, we give the last 5 numbers of W6 :

Walaweh Length Sequence Number Walaweh Number
6 60 110011
6 61 101111
6 62 100111
6 63 101011
6 64 100011

Your job is to convert from Walaweh Length + Sequence Number into Walaweh Number and vice versa.

입력

There are multiple input, each on a line by itself. The line will either begin with the word "Walaweh" then followed by an integer number L < 64 and N < 2L or begin with the word "Sequence" then followed by a binary representation of the Walaweh number with length < 64.

출력

For input line that begins with "Walaweh" you have to output the N'th Walaweh number of length L. For those lines that begins with "Sequence" you have to output the Sequence number of the given Walaweh number (The length of the Walaweh number is already obvious from the input).

예제 입력

Walaweh 1 1
Walaweh 3 6
Walaweh 4 13
Sequence 1100
Walaweh 5 14
Sequence 1110
Sequence 01010
Walaweh 6 1
Walaweh 6 20
Walaweh 6 32

예제 출력

0
110
1000
14
11100
16
31
100010
001110
011100

힌트