QOJ.ac

QOJ

时间限制: 2 s 内存限制: 512 MB 总分: 100

#2984. Strange Knapsack

统计

Xiao C is very good at knapsack problems. He has a strange backpack with a parameter $P$. When he puts several items into this backpack, the weight of the backpack is the sum of the volumes of the items modulo $P$.

Now, Xiao C has $n$ items with different volumes, where the $i$-th item has a volume of $V_i$. There are an infinite number of each item. He will perform $q$ queries. For each query, he gives a weight $w_i$, and you need to answer how many ways there are to put items into an initially empty backpack such that the resulting weight is $w_i$. Note that two ways are considered different if and only if the set of types of items included is different, regardless of the number of each item included. It is not difficult to see that the total number of ways is $2^n$.

Since the answer can be very large, you only need to output the answer modulo $10^9 + 7$.

Input

The first line contains three integers $n, q, P$. The next line contains $n$ integers representing $V_i$. The next line contains $q$ integers representing $w_i$.

Output

Output $q$ lines, each containing one integer representing the answer.

Examples

Input 1

3 3 6
1 3 4
5 2 3

Output 1

5 6 6

Note 1

For the first query $5$, the choices $\{1\}, \{1, 3\}, \{1, 4\}, \{3, 4\}, \{1, 3, 4\}$ are all valid schemes.

Input 2

See knapsack/knapsack2.in in the contestant directory.

Output 2

See knapsack/knapsack2.ans in the contestant directory.

Constraints

For all data, $1 \le n, q \le 10^6$, $3 \le P \le 10^9$, $0 < V_i, w_i < P$. It is guaranteed that all $V_i$ are distinct.

Test Case ID $n$ $q$ $P$
1 $= 1$ :---: $\le 10^9$
2 :---: :---: $\le 10$
3 $\le 10$ :---: :---:
4 :---: $\le 10^3$ $\le 250$
5 :---: :---: :---:
6 :---: :---: $\le 10^4$
7 $\le 10^3$ :---: $= 998244353$
8 :---: :---: :---:
9 :---: :---: $\le 10^9$
10 $\le 10^6$ $\le 10^6$ :---:

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.