QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#13459. With Reinforcement and Polynomials

Statistics

Note. We distinguish the order of the children of a node.

"Daiqiang" (a nickname), as the name suggests, likes to strengthen various counting problems, especially those involving polynomials. A "polynomial tree" is a combination of "polynomial" and "tree," which means using polynomials to count trees.

Daiqiang believes that the stability of a rooted tree depends on the number of children each node has. He defines a set of positive integers $D$ and calls a rooted tree "iron" if and only if for every non-leaf node in the tree, if it has $x$ children, then $x \in D$.

For each query $n$, you need to answer how many "iron" rooted trees with $n$ leaves exist, modulo $M$.

Input

The first line contains three positive integers $T, K, M$, representing the number of queries, the range of numbers in the set, and the modulus, respectively.

The next line contains a binary string of length $K-1$. The $x$-th character in the string (starting the count from 2) is '1' if $x \in D$, and '0' otherwise.

Each of the following lines contains a positive integer $n$, representing the number of leaves in the query.

Output

Output $T$ lines, providing the corresponding answers in the order of the queries.

Examples

Input 1

5 2 47
1
1
2
3
4
5

Output 1

1
1
2
5
14

Note 1

These are the Catalan numbers $C_{n-1}$.

Input 2

10 15 50
11101010101101
1
2
3
4
5
10
100
10000
998244353
1145141919810

Output 2

1
1
3
11
44
27
31
30
10
26

Subtasks

For $100\%$ of the data, it is guaranteed that $1\le n\le 10^{18}, 2\le K, M\le 50, 1\le T\le 100$.

Subtask Score $n\le $ $T =$ Special Constraint A Special Constraint B
$1$ $10$ $100$ $100$
$2$ $4$ $10^4$ $1$ $\checkmark$
$3$ $6$
$4$ $30$ $10^{18}$ $100$ $\checkmark$ $\checkmark$
$5$ $15$
$6$ $15$ $\checkmark$
$7$ $20$

Special Constraint A: $M$ is a prime number.

Special Constraint B: $\gcd(n, M) = 1$.

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.