시간 제한메모리 제한제출정답맞힌 사람정답 비율
6 초 1024 MB172222.222%

문제

In JOI Kingdom, a national festival is held once a year. During the period of the festival, there are $N$ events in total. The schedule for each event is already fixed. The schedule of the $N$ events are described by sequences $a$, $b$ of length $N$ satisfying the following conditions.

  • Every integer between $1$ and $2N$, inclusive, appears as an element of $a$ or $b$.
  • $a_i < b_i$ ($1 ≤ i ≤ N$).
  • $a_i < a_{i+1}$ ($1 ≤ i ≤ N - 1$).

The $i$-th event will start at $a_i$ minutes after the beginning of the festival, and end at $b_i$ minutes after the beginning of the festival.

Participants of the festival may choose any events in which they will participate. However, it is not allowed to participate in two events whose schedules overlap. (Note that the starting times and the ending times of the events are different from each other.)

JOI-kun wants to participate in as many events as possible. Until last year, he chose the events in which he participated by the following procedures on a computer.

  • For $i = 1, 2, \dots , N$, the following are done in this order.
    • If the schedule of the $i$-th event does not overlap the schedules of the other events in which he already chose to participate, he will participate in the $i$-th event. Otherwise, he will not participate in the $i$-th event.

However, after studying computer science, JOI-kun noticed that the above algorithm does not necessarily maximize the number of events in which JOI-kun will participate. From this year, JOI-kun will use an improved algorithm. Using the improved algorithm, JOI-kun will be able to maximize the number of events in which JOIkun will participate.

JOI-kun wants to know the number of cases where the improved algorithm produces a larger number of events.

Write a program which, given the integer $N$ and a large prime number $P$, calculates the number of pairs of sequences $a$, $b$ describing the schedules of the $N$ events for which the improved algorithm produces a larger number of events. Since the answer can be very large, your program should output the remainder of the answer when divided by $P$.

입력

Read the following data from the standard input.

$N$ $P$

출력

Write one line to the standard output. The output should contain the remainder of the answer, the number of pairs of sequences $a$, $b$ describing the schedules of the $N$ events for which the improved algorithm produces a larger number of events, when divided by $P$.

제한

  • $1 ≤ N ≤ 20\,000$.
  • $10^8 < P < 10^9$.
  • $P$ is a prime number.
  • Given values are all integers.

서브태스크

번호배점제한
15

$N ≤ 5$.

25

$N ≤ 8$.

327

$N ≤ 30$.

414

$N ≤ 300$.

536

$N ≤ 3\,000$.

613

No additional constraints.

예제 입력 1

3 100000007

예제 출력 1

2

For example, consider the case where $a = (1, 2, 4)$ and $b = (6, 3, 5)$. If JOI-kun uses the algorithm used until last year, he will participate in the first event only. On the other hand, if he uses a correct algorithm to maximize the number of events, he will participate in the second event and the third event. Thus, he will participate in two events. In this case, the improved algorithm produces a larger number of events.

The following are the pair of sequences $a$, $b$ for which the improved algorithm produces a larger number of events.

  • $a = (1, 2, 4)$, $b = (6, 3, 5)$
  • $a = (1, 2, 4)$, $b = (5, 3, 6)$

Therefore, output $2$, which is the remainder of $2$ when divided by $100\,000\,007$.

This sample input satisfies the constraints of all the subtasks.

예제 입력 2

4 100000007

예제 출력 2

28

There are $28$ pairs of sequences $a$, $b$ satisfying the condition. Therefore, output $28$, which is the remainder of $28$ when divided by $100\,000\,007$.

This sample input satisfies the constraints of all the subtasks.

예제 입력 3

15 999999937

예제 출력 3

935834920

There are $5\,295\,044\,602\,247\,148$ pairs of sequences $a$, $b$ satisfying the condition. Therefore, output $935\,834\,920$, which is the remainder of $5\,295\,044\,602\,247\,148$ when divided by $999\,999\,937$.

This sample input satisfies the constraints of Subtasks 3, 4, 5, 6.

채점 및 기타 정보

  • 예제는 채점하지 않는다.