#P7489. 「Stoi2031」手写的从前

「Stoi2031」手写的从前

Description

Yuan defines the weight of a set SS as σ(S)π(S)\dfrac{\sigma(S)}{\pi(S)}, where σ(S)=xSx\sigma(S)=\sum\limits_{x \in S}x is the sum of all elements in SS, and π(S)=xSx\pi(S)=\prod\limits_{x \in S}x is the product of all elements in SS. Tian asks him: what is the sum of the weights of all subsets of a set SS? Yuan quickly computes the answer. Tian then asks: what is the sum of the sums of the weights of all subsets of all subsets? Yuan also computes it quickly. So Tian asks one more question: in the question there are a total of kk layers of all subsets. Now Yuan cannot finish it, so he asks you for help. Yuan does not need an excessively large number, so you only need to output the answer modulo pp.

Input Format

The first line contains three positive integers n,k,pn,k,p, where nn is the number of elements in SS.

The second line contains nn positive integers, representing the elements of SS.

Output Format

Output one positive integer as the answer. It is guaranteed that the answer is meaningful modulo pp.

3 1 7
1 2 3

3

3 10 7
1 2 3

4

Hint

Brief statement of the problem:

Let f0(S)=σ(S)π(S)f_0(S)=\dfrac{\sigma(S)}{\pi(S)}, and fk(S)=TSfk1(T)f_k(S)=\sum\limits_{T \subseteq S}f_{k-1}(T). Here σ(S)=xSx\sigma(S)=\sum\limits_{x \in S}x is the sum of all elements in SS, and π(S)=xSx\pi(S)=\prod\limits_{x \in S}x is the product of all elements in SS. Given n,k,pn,k,p and the set SS, find fk(S)modpf_k(S) \bmod{p}.

Sample explanation:

Due to space limits, only sample 11 is explained.

Enumerate subsets:

\emptyset, with f0f_0 value 00;

{1}\{1\}, with f0f_0 value 11;

{2}\{2\}, with f0f_0 value 11;

{3}\{3\}, with f0f_0 value 11;

{1,2}\{1,2\}, with f0f_0 value 32\dfrac{3}{2};

{1,3}\{1,3\}, with f0f_0 value 43\dfrac{4}{3};

{2,3}\{2,3\}, with f0f_0 value 56\dfrac{5}{6};

{1,2,3}\{1,2,3\}, with f0f_0 value 11;

The total sum is 233\dfrac{23}{3}, which is 33 modulo 77.

Constraints:

For 30%30\% of the testdata, n13,k=1n \le 13,k=1.

For 70%70\% of the testdata, n103n \le 10^3.

For 100%100\% of the testdata, $1 \le n \le 7 \times 10^6,1 \le k \le 10^{18},1 \le x_i<p,1<p<2^{31},p$ is prime, and all xix_i are distinct.

The input size of this problem is large. You may use the fast input template from the contest statement to speed up reading.

Translated by ChatGPT 5