QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 256 MB Total points: 10

#233. Cracklings [B]

Statistics

Recent reports from the Large Hadron Collider indicate the discovery of a completely new type of elementary particle – "skwarki" (quarks) – with previously unknown, astonishing physical properties. Unlike other elementary particles (which generally form in pairs), a collision creates a group of $N$ skwarki with different quantum states, which physicists have decided to label with the numbers $1, 2, \dots, N$. A group of skwarki always has a fixed order, meaning they are arranged in a sequence. The order of arrangement can be different in different groups – in other words, the skwarki form a permutation of the set $\{1, 2, \dots, N\}$. Each element of the sequence of skwarki is adjacent to two others, except for the first and last elements, which have only one neighbor.

Skwarki, like many other particles, generally live for a very short time. In each millisecond, if at least one of a skwark's neighbors has a higher quantum state (i.e., a larger number), that skwark immediately decays. For example, in the permutation $(3, 2, 5, 1, 4, 6)$, in the first millisecond, the skwarki $2, 1,$ and $4$ decay, and the sequence $(3, 5, 6)$ remains. After the second millisecond, only the skwark $6$ remains. The last remaining skwark always has the largest number $N$ and is stable.

Detectors have shown that in the last collision, the resulting group decayed for exactly $K$ milliseconds until only one skwark remained. How many possible groups (permutations) of skwarki could have produced such an effect? Since we only want to verify a certain research hypothesis, it is sufficient to provide the remainder of the result when divided by a certain prime number $P$.

Input

The single line of input contains the integers $N, K,$ and $P$ ($1 \le K \le N \le 1000, N \ge 2, 10^8 \le P \le 10^9$, $P$ is a prime number), separated by single spaces.

Output

Output a single integer – the number of possible groups of skwarki modulo $P$.

Examples

Input 1

5 3 100000007

Output 1

4

Note

Explanation for the example: We are looking for groups of five skwarki that decay in three milliseconds. There are four such groups: $(4, 1, 3, 2, 5)$ $(4, 2, 3, 1, 5)$ $(5, 1, 3, 2, 4)$ $(5, 2, 3, 1, 4)$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.