CF BUDDY
← Problems·

1515E · Phoenix and Computers

2200 · combinatorics, dp, math

Problem: There are nn computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer i1i-1 and computer i+1i+1 are both on, computer ii (2in1)(2 \le i \le n-1) will turn on automatically if it is not already on. Note that Phoenix cannot manually turn on a computer that already turned on automatically.

If we only consider the sequence of computers that Phoenix turns on manually, how many ways can he turn on all the computers? Two sequences are distinct if either the set of computers turned on manually is distinct, or the order of computers turned on manually is distinct. Since this number may be large, please print it modulo MM.

Input Format: The first line contains two integers nn and MM (3n4003 \le n \le 400; 108M10910^8 \le M \le 10^9) — the number of computers and the modulo. It is guaranteed that MM is prime.

Output Format: Print one integer — the number of ways to turn on the computers modulo MM.

Note: In the first example, these are the 66 orders in which Phoenix can turn on all computers:

  • [1,3][1,3]. Turn on computer 11, then 33. Note that computer 22 turns on automatically after computer 33 is turned on manually, but we only consider the sequence of computers that are turned on manually.
  • [3,1][3,1]. Turn on computer 33, then 11.
  • [1,2,3][1,2,3]. Turn on computer 11, 22, then 33.
  • [2,1,3][2,1,3]
  • [2,3,1][2,3,1]
  • [3,2,1][3,2,1]

Sample Cases

Case 1

Input

3 100000007

Output

6

Case 2

Input

4 100000007

Output

20

Case 3

Input

400 234567899

Output

20914007

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback