#P3200. [HNOI2009] 有趣的数列

    ID: 2249 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2009湖南素数判断,质数,筛法卡特兰,Catalan

[HNOI2009] 有趣的数列

Description

We call a sequence of length 2n2n interesting if and only if it satisfies the following three conditions:

  • It is a permutation of the 2n2n integers from 11 to 2n2n, written as a1,a2,,a2na_1, a_2, \dots, a_{2n}.
  • All odd-indexed terms satisfy a1<a3<<a2n1a_1 < a_3 < \dots < a_{2n-1}, and all even-indexed terms satisfy a2<a4<<a2na_2 < a_4 < \dots < a_{2n}.
  • For every adjacent pair a2i1a_{2i-1} and a2ia_{2i}, it holds that a2i1<a2ia_{2i-1} < a_{2i}.

For a given nn, find the number of different interesting sequences of length 2n2n. Since the answer can be large, output the answer modulo pp.

Input Format

One line with two positive integers n,pn, p.

Output Format

Output a single integer on one line, the answer.

3 10
5

Hint

Constraints
For 50%50\% of the testdata, 1n10001 \le n \le 1000.
For 100%100\% of the testdata, 1n1061 \le n \le 10^6, 1p1091 \le p \le 10^9.

Sample explanation
The 55 interesting sequences are (1, 2, 3, 4, 5, 6), (1, 2, 3, 5, 4, 6), (1, 3, 2, 4, 5, 6), (1, 3, 2, 5, 4, 6), (1, 4, 2, 5, 3, 6).

Translated by ChatGPT 5