QOJ.ac

QOJ

実行時間制限: 5 s メモリ制限: 128 MB 満点: 100

#4114. Sequence Statistics

統計

Xiao C has a set $S$ consisting of non-negative integers less than $M$. He has written a program that generates a sequence of length $N$, where every element in the sequence belongs to the set $S$.

Xiao C has generated many such sequences using this generator. However, he needs your help with a problem: given an integer $x$, find the number of distinct sequences that can be generated such that the product of all numbers in the sequence modulo $M$ is equal to $x$. Xiao C considers two sequences $\{A_i\}$ and $\{B_i\}$ to be different if and only if there exists at least one integer $i$ such that $A_i \neq B_i$. Additionally, since the answer to this problem may be very large, he only needs you to find the answer modulo $1004535809$.

Input

The first line contains four integers $N$, $M$, $x$, and $|S|$, where $|S|$ is the number of elements in set $S$.

The second line contains $|S|$ integers, representing all elements in set $S$.

Output

A single integer representing the calculated count modulo $1004535809$.

Examples

Input 1

4 3 1 2
1 2

Output 1

8

Note

The distinct sequences that satisfy the requirements are $(1,1,1,1)$, $(1,1,2,2)$, $(1,2,1,2)$, $(1,2,2,1)$, $(2,1,1,2)$, $(2,1,2,1)$, $(2,2,1,1)$, and $(2,2,2,2)$.

Constraints

For $10\%$ of the data, $1 \le N \le 1000$;

For $30\%$ of the data, $3 \le M \le 100$;

For $60\%$ of the data, $3 \le M \le 800$;

For all data, $1 \le N \le 10^9$, $3 \le M \le 8000$, $M$ is a prime number, $1 \le x \le M-1$. The input guarantees that the elements in set $S$ are distinct.

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.