logo AlgoBeat OnlineJudge
登录 注册

#206119. [NEERC 2017] Knapsack Cryptosystem

内存限制:512 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

The Merkle-Hellman Knapsack Cryptosystem was one of the earliest public key cryptosystems invented by Ralph Merkle and Martin Hellman in . 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 mod . 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 i-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 mod -- the encrypted message taken modulo mod

The given sequence is a valid public key in the described implementation, and the given value mod is a valid encrypted message.

输出格式

Output exactly bits ( or digits) -- the original message.

样例

样例输入 1

5
10
20
50
140
420
440

样例输出 1

01001

数据范围与提示

Time limit: 3 s, Memory limit: 512 MB.