Under construction

Still being built. Things may change

Beautiful Sequence Unraveling

Time limit7sMemory limit512 MB

Summary
Count arrays of length n with values from 1 to k where no split point has prefix maximum equal to suffix minimum, modulo the prime p.
Level

Hard8 of 10

Topics
Math, Combinatorics, Dynamic programming
Solved
No attempts yet

Problem

You are the happy owner of a powerful tool called Beautiful Sequence Unraveler (BSU). BSU handles beautiful sequences well.

A beautiful sequence is an array a1,a2,…,ana_1, a_2, \ldots, a_n of nn integers such that there is no integer ii with 1≤i<n1 \le i < n and max⁡{a1,…,ai}=min⁡{ai+1,…,an}\max\{a_1, \dots, a_i\} = \min\{a_{i + 1}, \dots, a_n\}.

You want to know how often such sequences occur. Count the beautiful sequences among all arrays of length nn whose integers are between 11 and kk, inclusive. The count may be large, so print it modulo the prime pp.

Input

The only line contains three integers nn, kk, pp (1≤n≤4001 \le n \le 400, 1≤k≤1081 \le k \le 10^8, 998 244 353≤p≤109+9998\,244\,353 \le p \le 10^9 + 9).

It is guaranteed that pp is prime.

Output

Print the answer modulo pp.

Examples3

  1. Example 1

    Input
    2 2 1000000007
    
    Expected output
    2
    
  2. Example 2

    Input
    3 4 1000000009
    
    Expected output
    36
    
  3. Example 3

    Input
    228 112263 998244353
    
    Expected output
    379700769