#P7511. 三到六
三到六
Description
Given integers and an -th permutation , ask how many permutations satisfy that there are exactly positions such that and . Output the answer modulo .
Input Format
The first line contains two integers .
The second line contains positive integers, representing .
Output Format
Output one line containing one non-negative integer, representing the number of permutations that satisfy the condition.
5 0
1 2 3 4 5
120
5 1
2 3 4 5 1
5
5 2
2 4 5 1 3
60
Hint
Sample Explanation
For the first sample, cannot be less than , so the condition must always be satisfied. Therefore, the answer is .
For the second sample, there are the following permutations that satisfy the condition:
- ;
- ;
- ;
- ;
- 。
For the third sample, no explanation is provided.
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, .
For the other of the testdata, it is guaranteed that ().
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号