Ancient Machine 2

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

Bitaro and Bibako are archaeologists who excavated and investigated the ruin of JOI Kingdom. In the ruin, Bitaro found an old stone slate, and Bibako found an old machine.

From the results of the study, Bitaro found out that a string SS of length NN was written on the stone slate. Each character of the string is either ‘0’ or ‘1’. However, he does not yet know each character of the string SS.

On the other hand, from the results of the study, Bibako found out how to use the machine. To use it, we put the stone slate on the machine, input an integer mm and two sequences of integers aa, bb, and make a query. Here the integer mm and the sequences of integers aa, bb should satisfy the following conditions:

  • The integer mm is between 11 and 1,0021\\,002, inclusive.
  • Both of the lengths of the sequences aa, bb are equal to mm.
  • Every element of the sequences aa, bb is an integer between 00 and m1m - 1, inclusive.

If we put the stone slate on the machine, input an integer mm and two sequences of integers aa, bb, and make a query, the machine will operate as follows and will show an integer.

  1. The machine sets 00 in the memory area of the machine.

  2. The machine performs the following NN operations. The (i+1)(i + 1)-th (0iN10 ≤ i ≤ N - 1) operation proceeds as follows.

    • Let xx be the current integer set in the memory area of the machine. The machine reads the character S_iS\_i. Here, S_iS\_i is the ii-th character of the string SS, if we count the characters of the string SS so that the first character is the 00-th character.

      • If S_iS\_i is ‘0’, the machine sets a_xa\_x in the memory area of the machine. Here, a_xa\_x is the xx-th element of the sequence aa, if we count the elements of the sequence aa so that the first element is the 00-th element.
      • If S_iS\_i is ‘1’, the machine sets b_xb\_x in the memory area of the machine. Here, b_xb\_x is the xx-th element of the sequence bb, if we count the elements of the sequence bb so that the first element is the 00-th element.
  3. The machine shows the integer which is finally set in the memory area.

Using the machine, Bitaro wants to specify the string written on the stone slate. However, since the machine is very fragile, the number of queries cannot exceed 1,0001\\,000. Moreover, the maximum of the integer mm input to the machine for a query should be as small as possible.

Write a program which, using the machine, specifies the string written on the stone slate.

제한

  • N=1,000N = 1\\,000.
  • SS is a string of length NN.
  • Each character of the string SS is either ‘0’ or ‘1’.