11439: ABC378 - G - Everlasting LIDS
[Creator : ]
Description
You are given integers $A$, $B$, and $M$.
How many permutations $P = (P_1, \dots, P_{AB-1})$ of $(1, 2, \ldots, AB - 1)$ satisfy all of the following conditions? Find the count modulo $M$.
- The length of a longest increasing subsequence of $P$ is $A$.
- The length of a longest decreasing subsequence of $P$ is $B$.
- There exists an integer $n$ such that appending $n + 0.5$ to the end of $P$ does not change either of the lengths of a longest increasing subsequence and a longest decreasing subsequence.
How many permutations $P = (P_1, \dots, P_{AB-1})$ of $(1, 2, \ldots, AB - 1)$ satisfy all of the following conditions? Find the count modulo $M$.
- The length of a longest increasing subsequence of $P$ is $A$.
- The length of a longest decreasing subsequence of $P$ is $B$.
- There exists an integer $n$ such that appending $n + 0.5$ to the end of $P$ does not change either of the lengths of a longest increasing subsequence and a longest decreasing subsequence.
Input
The input is given from Standard Input in the following format:
```
$A$ $B$ $M$
```
```
$A$ $B$ $M$
```
Output
Print the number of permutations satisfying the conditions, modulo $M$.
Constraints
- All input values are integers.
- $2 \leq A, B$
- $AB \leq 120$
- $10^8 \leq M \leq 10^9$
- $M$ is a prime.
- $2 \leq A, B$
- $AB \leq 120$
- $10^8 \leq M \leq 10^9$
- $M$ is a prime.
Sample 1 Input
3 2 998244353
Sample 1 Output
10
For example, $P = (2, 4, 5, 1, 3)$ satisfies the conditions. This can be confirmed as follows:
- The length of a longest increasing subsequence of $P$ is $3$.
- The length of a longest decreasing subsequence of $P$ is $2$.
- For $n = 4$, the lengths of longest increasing and decreasing subsequences of $(2, 4, 5, 1, 3, 4.5)$ are $3$ and $2$, respectively.
There are $10$ permutations of $(1, 2, 3, 4, 5)$ that satisfy the conditions.
- The length of a longest increasing subsequence of $P$ is $3$.
- The length of a longest decreasing subsequence of $P$ is $2$.
- For $n = 4$, the lengths of longest increasing and decreasing subsequences of $(2, 4, 5, 1, 3, 4.5)$ are $3$ and $2$, respectively.
There are $10$ permutations of $(1, 2, 3, 4, 5)$ that satisfy the conditions.
Sample 2 Input
10 12 924844033
Sample 2 Output
623378361