#arc146e. [arc146_e]Simple Speed
[arc146_e]Simple Speed
Problem Statement
You are given a sequence of positive integers: .
How many integer sequences consisting of integers between and (inclusive) satisfy all of the following conditions? Print the count modulo .
- For each integer such that , there are exactly occurrences of in .
- For each integer such that , it holds that .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
2 3 1
Sample Output 1
6
can be the following six sequences.
Thus, the answer is .
Sample Input 2
1
200000
Sample Output 2
0
There may be no sequence that satisfies the conditions.
Sample Input 3
6
12100 31602 41387 41498 31863 12250
Sample Output 3
750337372