#P7444. 「EZEC-7」猜排列
「EZEC-7」猜排列
Background
Update: The testdata has been strengthened.
Problem Description
Alice has a permutation of length , and the numbers in the permutation are .
Bob has nothing to do and wants to guess it, but Alice does not want him to guess it too easily.
So she gives Bob some conditions and asks him to guess the permutation.
We define , where the function means the smallest non-negative integer that does not appear in a multiset.
The conditions Alice gives contain numbers. The -th number represents the number of pairs satisfying and .
Bob immediately knows that this still cannot determine the whole permutation, so he wants to know how many permutations satisfy the given conditions.
Input Format
The first line contains a positive integer , representing the length of Alice's permutation.
The second line contains non-negative integers. The -th number represents the number of pairs satisfying and .
Output Format
Output the number of permutations satisfying the given conditions modulo .
4
4 3 1 1
2
4
4 0 3 2
0
Hint
Sample Explanation
In the first sample, there are two permutations that satisfy the conditions:
and .
In the second sample, you can find by enumeration that there is no solution that satisfies the requirements.
Constraints
This problem uses bundled testdata.
- Subtask 1 (4 points): .
- Subtask 2 (8 points): .
- Subtask 3 (16 points): .
- Subtask 4 (32 points): .
- Subtask 5 (20 points): .
- Subtask 6 (20 points): no special constraints.
For of the testdata, , , and it is guaranteed that .
Translated by ChatGPT 5