#agc030f. [agc030_f]Permutation and Minimum
[agc030_f]Permutation and Minimum
Problem Statement
There is a sequence of length : . Each is either or an integer between and (inclusive). Any integer other than appears at most once in .
For each such that , Snuke replaces with an integer between and (inclusive), so that will be a permutation of . Then, he finds a sequence of length , , as .
Find the number of different sequences that can be, modulo .
Constraints
- or .
- If , then . ()
Input
Input is given from Standard Input in the following format:
Output
Print the number of different sequences that can be, modulo .
Sample Input 1
3
1 -1 -1 3 6 -1
Sample Output 1
5
There are six ways to make a permutation of ; for each of them, would be as follows:
- $(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 2, 4, 3, 6, 5)$:
- $(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 2, 5, 3, 6, 4)$:
- $(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 4, 2, 3, 6, 5)$:
- $(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 4, 5, 3, 6, 2)$:
- $(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 5, 2, 3, 6, 4)$:
- $(A_1, A_2, A_3, A_4, A_5, A_6) = (1, 5, 4, 3, 6, 2)$:
Thus, there are five different sequences that can be.
Sample Input 2
4
7 1 8 3 5 2 6 4
Sample Output 2
1
Sample Input 3
10
7 -1 -1 -1 -1 -1 -1 6 14 12 13 -1 15 -1 -1 -1 -1 20 -1 -1
Sample Output 3
9540576
Sample Input 4
20
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 -1 -1 -1 -1 -1 7 -1 -1 -1 -1 -1 -1 -1 -1 -1 34 -1 -1 -1 -1 31 -1 -1 -1 -1 -1 -1 -1 -1
Sample Output 4
374984201