atcoder#AGC030F. [AGC030F] Permutation and Minimum
[AGC030F] Permutation and Minimum
Score : points
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 .
3
1 -1 -1 3 6 -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.
4
7 1 8 3 5 2 6 4
1
10
7 -1 -1 -1 -1 -1 -1 6 14 12 13 -1 15 -1 -1 -1 -1 20 -1 -1
9540576
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
374984201