#arc162e. [arc162_e]Strange Constraints
[arc162_e]Strange Constraints
Problem Statement
You are given a sequence of length consisting of integers from to , .
Find the number, modulo , of sequences of length consisting of integers from to , , that satisfy the following conditions for all .
- The number of occurrences of in is at most .
- The number of occurrences of in is at most .
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
1 2 3
Sample Output 1
10
The following sequences satisfy the conditions:
Sample Input 2
4
4 4 4 4
Sample Output 2
256
All sequences of length consisting of integers from to satisfy the conditions, and there are such sequences.
Sample Input 3
5
1 1 1 1 1
Sample Output 3
120
All permutations of satisfy the conditions, and there are such sequences.
Sample Input 4
14
6 5 14 3 6 7 3 11 11 2 3 7 8 10
Sample Output 4
628377683
Be sure to print the number modulo .