atcoder#AGC055C. [AGC055C] Weird LIS

[AGC055C] Weird LIS

Score : 900900 points

Problem Statement

You are given integers NN and MM. Find the number of arrays A=[A1,A2,,AN]A=[A_1, A_2, \ldots, A_N] of length NN such that the following conditions hold:

  • 2AiM2 \le A_i \le M (1iN1 \leq i \leq N)
  • There exists a permutation P=[P1,P2,,PN]P=[P_1,P_2,\ldots,P_N] of integers from 11 to NN with the following property:- For every ii from 11 to NN, AiA_i equals the length of the longest increasing subsequence of the sequence $[P_1, P_2, \ldots, P_{i-1}, P_{i+1}, \ldots, P_{N-1}, P_N]$.
  • For every ii from 11 to NN, AiA_i equals the length of the longest increasing subsequence of the sequence $[P_1, P_2, \ldots, P_{i-1}, P_{i+1}, \ldots, P_{N-1}, P_N]$.

As this number can be very large, output it modulo some prime QQ.

Constraints

  • 3N50003 \le N \le 5000.
  • 2MN12 \le M \le N-1.
  • 108Q10910^8 \le Q \le 10^9
  • QQ is a prime.

Input

Input is given from Standard Input in the following format:

NN MM QQ

Output

Print the answer modulo QQ.

3 2 686926217
1

The only such array is [2,2,2][2, 2, 2], for which exists a permutation [1,2,3][1, 2, 3].

4 3 354817471
9

There are 99 such arrays: [2,2,2,2][2, 2, 2, 2], [2,2,2,3][2, 2, 2, 3], [2,2,3,2][2, 2, 3, 2], [2,2,3,3][2, 2, 3, 3], [2,3,2,2][2, 3, 2, 2], [2,3,3,2][2, 3, 3, 2], [3,2,2,2][3, 2, 2, 2], [3,3,2,2][3, 3, 2, 2], [3,3,3,3][3, 3, 3, 3].

5 2 829412599
1

The only such array is [2,2,2,2,2][2, 2, 2, 2, 2].

5 3 975576997
23
69 42 925171057
801835311