#P2396. yyy loves Maths VII
yyy loves Maths VII
Description
A group of classmates are playing a game with yyy.
Each time, they give yyy cards with numbers on them. All the numbers are "lucky numbers". Let the number on the -th card be .
On each move, yyy may choose to move forward steps and discard the -th card. He wins when he has no cards left.
However, traps are set on positions that are "unlucky numbers". If yyy stops on such a cell, he loses. Note: even if he reaches the end, if that position is an unlucky number, he still loses.
Now, some classmates begin to ask: what is the probability that yyy will win?
They think this is a good question, and someone immediately asks yyy to write a program: "Computers are very fast! factorial is only , yyy, hurry up and write a program to compute it."
yyy is speechless. He says he does not want to compute the probability—at most he can compute the number of winning plans, and only modulo .
None of them can code, so they have to compromise.
But now yyy is troubled: is too large; it would take a long time to run.
He is seriously short on time and needs your help!
A number may belong to both the lucky numbers and the unlucky numbers.
Input Format
The first line contains an integer .
The second line contains integers; the -th integer is , the number on the -th card.
The third line contains an integer denoting the number of yyy's unlucky numbers (at most ).
If , the fourth line contains integers representing all the unlucky numbers.
Output Format
Output the number of winning plans modulo .
8
1 3 1 5 2 2 2 3
0
40320
24
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2
10 15
0
Hint
Constraints:
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号