문제
The Merkle–Hellman Knapsack Cryptosystem was one of the earliest public key cryptosystems invented by Ralph Merkle and Martin Hellman in 1978. Here is its description.
Alice chooses positive integers such that each , a positive integer which is greater than the sum of all , and a positive integer which is coprime with . These integers are Alice's private key.
Then Alice calculates . These integers are Alice's public key.
Knowing her public key, Bob can transmit a message of bits to Alice. To do that he calculates , the sum of with indices such that his message has bit in -th position. This value is the encrypted message.
Note that an eavesdropper Eve, who knows the encrypted message and the public key, has to solve a (presumably hard) instance of the knapsack problem to find the original message. Meanwhile, after receiving , Alice can calculate the original message in linear time; we leave it to you as an exercise.
In this problem you deal with the implementation of the Merkle–Hellman Knapsack Cryptosystem in which Alice chose , for obvious performance reasons, and published this information. Since everyone knows her , she asks Bob to send her the calculated value taken modulo for simplicity of communication.
You are to break this implementation. Given the public key and an encrypted message, restore the original message.
입력
The first line contains one integer ().
Each of the next lines contains one integer ().
The last line contains one integer — the encrypted message taken modulo ().
The given sequence is a valid public key in the described implementation, and the given value is a valid encrypted message.
출력
Output exactly bits (0 or 1 digits) — the original message.
예제 입력 1
5
10
20
50
140
420
440
예제 출력 1
01001
코드를 제출하려면 로그인이 필요합니다.
로그인