eolymp
bolt
Try our new interface for solving problems
Problems

GrayInc

GrayInc

Gray Inc. is a software fabricant specialized in management of Gray codes. An \textbf{n}-binary code, for \textbf{n} ≥ \textbf{1}, is a sequence of words \textbf{w_0}, \textbf{w_1}, ... that includes every possible binary word of \textbf{n} bits. An \textbf{n}-Gray code is an \textbf{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 \textbf{n}-Gray codes. Gray Inc. produces its own particular kind of Gray code in the following way (name \textbf{G_n} the produced \textbf{n}-Gray code, \textbf{n} ≥ \textbf{1}): \includegraphics{https://static.e-olymp.com/content/b6/b61800c843b929bace0d7d8cbdbd7d234c12f558.jpg} The notation defining \textbf{G_n} should be understood as follows: \begin{itemize} \item \textbf{bA} : appends bit \textbf{b} to every element of the sequence \textbf{A}; \item \textbf{AB} : concatenates sequences \textbf{A} and \textbf{B}; \item \textbf{A^R} : sequence with the elements of sequence \textbf{A} in reversed order. \end{itemize} For instance, \includegraphics{https://static.e-olymp.com/content/3b/3bf83035f22accfeda5de0f10d4eab52cbfd5542.jpg} and \includegraphics{https://static.e-olymp.com/content/2a/2ada17fdbf15448369585359ee344de191a2ae94.jpg} Observe that not only \textbf{G_n} is an \textbf{n}-Gray code, but also a \textit{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 \textbf{w} in \textbf{G_n} and a natural number \textbf{m}, they want to produce the binary word in the sequence \textbf{G_n} that is \textbf{m} words ahead \textbf{w} in the listing (of course, considering the circular ordering described above). Can you help them? \InputFile The problem input consists of several cases, each one defined by a line with an integer \textbf{m }(\textbf{0} < \textbf{m} ≤ \textbf{1000}), and a binary \textbf{n}-word \textbf{w} (\textbf{1} ≤ \textbf{n} ≤ \textbf{100}), separated by one blank. The end of the input is given by a line with \textbf{m} = \textbf{0} and \textbf{w} = \textbf{0}. \OutputFile For each input case, your solution should output the \textbf{n}-binary word that is \textbf{m} words ahead of \textbf{w} in the listing of \textbf{G_n}.
Time limit 1 second
Memory limit 64 MiB
Input example #1
1 0
3 0
1 1
1 11
6 011
123 010101010
0 0
Output example #1
1
1
0
10
000
111100100