AtCoder Grand Contest 067
D
Unique Matching
AtCoder
⌀ 3345
原题
← CE →
翻译中…

Problem Statement

翻译中…

You are given an integer $N$ and prime $P$.

翻译中…

We call a sequence of $N$ intervals $([L_1,R_1] ,[L_2,R_2], \cdots, [L_N,R_N])$ good if and only if both of the followings are satisfied:

翻译中…
  • $1\le L_i\le R_i\le N$ holds for all $1\le i\le N$.
  • There exists a unique permutation $x=(x_1,x_2,\cdots,x_N)$ of $(1,2,\cdots,N)$ such that $L_i\le x_i\le R_i$ holds for all $1\le i\le N$.
翻译中…

Count the number, modulo $P$, of good sequences of intervals.

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 5000$
  • $10^9<P<1.01\times 10^9$
  • $P$ is prime.
  • All input values are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N P

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
2 1005488041
Output #1
6
The following $6$ sequences are good: - $([1,1],[2,2])$ - $([1,2],[2,2])$ - $([1,1],[1,2])$ - $([2,2],[1,1])$ - $([2,2],[1,2])$ - $([1,2],[1,1])$
Input #2
5 1005488041
Output #2
102960
Input #3
100 1005488041
Output #3
47599495
Input #4
1000 1005488041
Output #4
632708165
题目信息
题号
agc067_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。