#P9084. [PA 2018] Skwarki

[PA 2018] Skwarki

Problem Description

This problem is translated from PA 2018 Round 5 Skwarki.

Find how many sequences of length NN satisfy the following conditions:

  • Each of the NN numbers 11 to NN appears exactly once in the sequence.
  • Only after performing exactly KK operations, the sequence becomes a sequence with only one element.

The operation is defined as follows:

Let AiA_i be the ii-th element of the sequence (1<i<len1 < i < \mathrm{len}, where len\mathrm{len} is the sequence length). If Ai1>AiA_{i-1} > A_i or Ai+1>AiA_{i+1} > A_i, then mark AiA_i. If A2>A1A_2 > A_1, then mark A1A_1. If Alen1>AlenA_{\mathrm{len}-1} > A_{\mathrm{len}}, then mark AlenA_{\mathrm{len}}.

Then, delete all marked elements from the sequence.

There may be many valid sequences, so please output the answer modulo PP.

Input Format

The input contains only one line with three integers N,K,PN, K, P.

Output Format

Output one integer per line, representing the number of valid sequences modulo PP.

5 3 100000007
4

Hint

Sample 1 Explanation

All valid sequences are listed below:

  • (4,1,3,2,5)(4,1,3,2,5)
  • (4,2,3,1,5)(4,2,3,1,5)
  • (5,1,3,2,4)(5,1,3,2,4)
  • (5,2,3,1,4)(5,2,3,1,4)

Constraints

This problem uses bundled testdata.

For 100%100\% of the testdata, it is guaranteed that 1K,N10001 \le K, N \le 1000, N2N \ge 2, and 108P10910^8 \le P \le 10^9.

Translated by ChatGPT 5