{"raw_statement":[{"iden":"problem statement","content":"You are given integers $N$ and $M$. Find the number of arrays $A=[A_1, A_2, \\ldots, A_N]$ of length $N$ such that the following conditions hold:\n\n*   $2 \\le A_i \\le M$ ($1 \\leq i \\leq N$)\n*   There exists a permutation $P=[P_1,P_2,\\ldots,P_N]$ of integers from $1$ to $N$ with the following property:\n    *   For every $i$ from $1$ to $N$, $A_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]$.\n\nAs this number can be very large, output it modulo some prime $Q$."},{"iden":"constraints","content":"*   $3 \\le N \\le 5000$.\n*   $2 \\le M \\le N-1$.\n*   $10^8 \\le Q \\le 10^9$\n*   $Q$ is a prime."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$ $M$ $Q$"},{"iden":"sample input 1","content":"3 2 686926217"},{"iden":"sample output 1","content":"1\n\nThe only such array is $[2, 2, 2]$, for which exists a permutation $[1, 2, 3]$."},{"iden":"sample input 2","content":"4 3 354817471"},{"iden":"sample output 2","content":"9\n\nThere are $9$ such arrays: $[2, 2, 2, 2]$, $[2, 2, 2, 3]$, $[2, 2, 3, 2]$, $[2, 2, 3, 3]$, $[2, 3, 2, 2]$, $[2, 3, 3, 2]$, $[3, 2, 2, 2]$, $[3, 3, 2, 2]$, $[3, 3, 3, 3]$."},{"iden":"sample input 3","content":"5 2 829412599"},{"iden":"sample output 3","content":"1\n\nThe only such array is $[2, 2, 2, 2, 2]$."},{"iden":"sample input 4","content":"5 3 975576997"},{"iden":"sample output 4","content":"23"},{"iden":"sample input 5","content":"69 42 925171057"},{"iden":"sample output 5","content":"801835311"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}