#arc151b. [arc151_b]A < AP
[arc151_b]A < AP
Problem Statement
You are given a permutation of .
Print the number of integer sequences of length that satisfy both of the conditions below, modulo .
- for every .
- The integer sequence is lexicographically smaller than the integer sequence .
What is lexicographical order?
An integer sequence is lexicographically smaller than an integer sequence when there is an integer that satisfies both of the conditions below.
- For all integers (), .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the number of integer sequences of length that satisfy both of the conditions in the Problem Statement, modulo .
Sample Input 1
4 2
4 1 3 2
Sample Output 1
6
Six integer sequences satisfy both of the conditions: , , , , , and .
For instance, when , we have $(A_{P_1}, A_{P_2}, A_{P_3}, A_{P_4}) = (2, 1, 1, 1)$, which is lexicographically larger than .
Sample Input 2
1 1
1
Sample Output 2
0
Sample Input 3
20 100000
11 15 3 20 17 6 1 9 5 19 10 16 7 8 12 2 18 14 4 13
Sample Output 3
55365742