eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків

GrayInc

Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB

Gray Inc. is a software fabricant specialized in management of Gray codes. An n-binary code, for n1, is a sequence of words w_0, w_1, ... that includes every possible binary word of n bits. An n-Gray code is an n-binary code such that between any two consecutive words there is only one bit that changes, i.e., they differ at exactly one position. As you might be aware by now, there are many n-Gray codes.

Gray Inc. produces its own particular kind of Gray code in the following way (name G_n the produced n-Gray code, n1):

The notation defining G_n should be understood as follows:

  • bA : appends bit b to every element of the sequence A;

  • AB : concatenates sequences A and B;

  • A^R : sequence with the elements of sequence A in reversed order.

For instance,

and

Observe that not only G_n is an n-Gray code, but also a circular Gray code as the first word in the sequence may be regarded as the successor of the last one in the sequence.

Gray Inc. wants your help to solve the following problem: given a binary word w in G_n and a natural number m, they want to produce the binary word in the sequence G_n that is m words ahead w in the listing (of course, considering the circular ordering described above). Can you help them?

Вхідні дані

The problem input consists of several cases, each one defined by a line with an integer m (0 < m1000), and a binary n-word w (1n100), separated by one blank.

The end of the input is given by a line with m = 0 and w = 0.

Вихідні дані

For each input case, your solution should output the n-binary word that is m words ahead of w in the listing of G_n.

Приклад

Вхідні дані #1
1 0
3 0
1 1
1 11
6 011
123 010101010
0 0
Вихідні дані #1
1
1
0
10
000
111100100