#Q239. 「一本通 6.6 练习 8」礼物

    ID: 2321 Type: Default 1000ms 512MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>组合计数Lucas 定理中国剩余定理一本通提高

「一本通 6.6 练习 8」礼物

Description

Original source: BZOJ 2142

The annual Christmas season is approaching. Every year, Little E receives many gifts and, of course, gives many gifts in return. Different people hold varying levels of importance in Little E's heart, and those who carry more weight receive more gifts.

Little E has purchased nn gifts from the store, intending to distribute them among mm people, with wiw_i gifts designated for the ii-th person. Please help calculate the number of possible gifting schemes (two schemes are considered different if and only if there exists at least one person who receives different gifts in the two schemes). Since the number of schemes can be very large, you only need to output the result modulo PP.

Input Format

The first line of input contains a positive integer PP, representing the modulus;

The second line contains two positive integers nn and mm, representing the number of gifts Little E has bought and the number of gift recipients, respectively;

The following mm lines each contain a single positive integer wiw_i, representing the number of gifts Little E intends to give to the ii-th person.

Output Format

If no feasible scheme exists, output Impossible. Otherwise, output an integer representing the number of schemes modulo PP.

Sample 1

Details of the 1212 schemes are as follows: $\{1\}\{2,3\},\{1\}\{2,4\},\{1\}\{3,4\},\{2\}\{1,3\},\{2\}\{1,4\},\{2\}\{3,4\},\{3\}\{1,2\},\{3\}\{1,4\},\{3\}\{2,4\},\{4\}\{1,2\},\{4\}\{1,3\},\{4\}\{2,3\}$.

100
4 2
1
2

12

Constraints & Hints

Let $P=p_1^{c_1} \times p_2^{c_2} \times p_3^{c_3} \times \cdots \times p_t ^{ c_t}$, where pip_i are prime numbers.

For 100%100\% of the data, 1n109,1m5,1pici1051\le n\le 10^9,1\le m\le 5,1\le p_i^{c_i}\le 10^5.