This page is still under construction.

Parts of this page are still being built. What you see may change.

Broken Device 2

Time limit2sMemory limit512 MB

Summary
Anna must encode an integer up to 10^18 into 0/1 arrays sent through a riffle-shuffle device so Bruno can recover it exactly.
Level

Hard8 of 10

Topics
Math, Bit manipulation, Implementation
Solved
No attempts yet

Problem

Anna and Bruno are gamble masters. They play a game with D-taro, the dealer of the game.

In this game, Anna and Bruno stay in different rooms. They can communicate only through a broken device. D-taro gives an integer to Anna. Their goal is to send the given integer from Anna to Bruno through the device.

When the game starts, Anna declares an integer mm between 1 and 2000, inclusive. Then they play QQ rounds. Round ii (1≤i≤Q1 \le i \le Q) goes as follows.

  1. D-taro gives an integer AiA_i to Anna.
  2. Anna inputs arrays sis_i and tit_i into the device. Every element of sis_i and tit_i is either 0 or 1. The two arrays have the same length, which is between 1 and mm, inclusive.
  3. Let uiu_i be the array obtained from sis_i and tit_i by a riffle shuffle (see below). The device sends uiu_i to Bruno.
  4. Bruno sends an integer to D-taro. If this integer equals AiA_i, Anna and Bruno win the round.

Write programs that implement the strategies of Anna and Bruno so that they win all QQ rounds.

Constraints

1≤Q≤1 0001 \le Q \le 1\,000.

1≤Ai≤10181 \le A_i \le 10^{18} (1≤i≤Q1 \le i \le Q).

Examples1

  1. Example 1

    Input
    1
    1
    
    Expected output
    1