This page is still under construction.

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

Knapsack Cryptosystem

Time limit3sMemory limit512 MB

Summary
Recover the plaintext bits from a Merkle-Hellman knapsack instance where q = 2^64, exploiting the known modulus to invert the hidden superincreasing sequence.
Level

Hard8 of 10

Topics
Number theory, Brute force, Bit manipulation, Math
Solved
No attempts yet

Problem

The Merkle-Hellman knapsack cryptosystem is one of the first public key cryptosystems. Ralph Merkle and Martin Hellman published it in 1978. It works like this.

Alice picks nn positive integers a1,…,ana_1, \dots, a_n such that ai>∑j=1i−1aja_i > \sum_{j=1}^{i-1} a_j holds for every ii, a positive integer qq greater than a1+⋯+ana_1 + \dots + a_n, and a positive integer rr coprime with qq. These n+2n + 2 integers are Alice's private key.

Alice then computes bi=(ai⋅r) mod qb_i = (a_i \cdot r) \bmod q. These nn integers are Alice's public key.

Knowing the public key, Bob can send Alice a message of nn bits. He computes ss, the sum of the bib_i over the indices ii where his message has bit 1. The value ss is the encrypted message.

An eavesdropper Eve, who knows the public key and the encrypted message, has to solve an instance of the knapsack problem, which is presumably hard. Alice, on the other hand, recovers the message in linear time once she receives ss.

This problem is about an implementation in which Alice chose q=264q = 2^{64} for obvious performance reasons and published that choice. Since everyone knows her qq, she asks Bob to send the value ss taken modulo 2642^{64}, which keeps the communication simple.

Break this implementation. Given the public key and an encrypted message, restore the original message.

Input

The first line contains one integer nn (1≤n≤641 \le n \le 64).

Each of the next nn lines contains one integer bib_i (1≤bi<2641 \le b_i < 2^{64}).

The last line contains s mod qs \bmod q, the encrypted message taken modulo qq (0≤s mod q<2640 \le s \bmod q < 2^{64}).

The given sequence b1,…,bnb_1, \dots, b_n is a valid public key of the implementation above, and the given value is a valid encrypted message.

Output

Print exactly nn characters on one line, each of them 0 or 1, the bits of the original message in order.

Exactly one message fits the input, because the subset sums of a1,…,ana_1, \dots, a_n are pairwise different.

Examples4

  1. Example 1

    Input
    5
    10
    20
    50
    140
    420
    440
    
    Expected output
    01001
    
  2. Example 2

    Input
    1
    912305779442463498
    0
    
    Expected output
    0
    
  3. Example 3

    Input
    1
    15896681328832863091
    15896681328832863091
    
    Expected output
    1
    
  4. Example 4

    Input
    2
    11359365954229918514
    16673425955450702548
    16673425955450702548
    
    Expected output
    01