Problem:
Score : 1200 points

Problem Statement

Find the number of the possible tuples of sequences (A_0,A_1,...,A_N) that satisfy all of the following conditions, modulo M:

For every i (0\leq i\leq N), A_i is a sequence of length i consisting of integers between 1 and K (inclusive);

For every i (1\leq i\leq N), A_{i-1} is a subsequence of A_i, that is, there exists 1\leq x_i\leq i such that the removal of the x_i-th element of A_i would result in a sequence equal to A_{i-1};

For every i (1\leq i\leq N), A_i is lexicographically larger than A_{i-1}.

Constraints

1 \leq N,K \leq 300

2 \leq M \leq 10^9

N, K and M are integers.

Input

Input is given from Standard Input in the following format:

N K M

Output

Print the number of the possible tuples of sequences (A_0,A_1,...,A_N), modulo M.

Sample Input 1

2 2 100

Sample Output 1

5

Five tuples below satisfy the conditions:

(),(1),(1,1)

(),(1),(1,2)

(),(1),(2,1)

(),(2),(2,1)

(),(2),(2,2)

Sample Input 2

4 3 999999999

Sample Output 2

358

Sample Input 3

150 150 998244353

Sample Output 3

186248260

Solution in Rust (1.15.1) (judge verdict: Accepted)

// use std::cmp;
// use std::collections::HashMap;
// use std::collections::HashSet;


// const INF: i64 = 1_000_000_000;


fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let N: usize = sc.read();
    let K: usize = sc.read();
    let md: usize = sc.read();
    let mut ans = vec![vec![0; K+1]; N+1];
    let mut anssum = vec![vec![0; K+1]; N+1];

    let mut c = vec![vec![0; N+1]; N+1];
    for n in 0..N+1 {
        for k in 0..n+1 {
            if k == 0 || k == n {
                c[n][k] = 1;
            } else {
                c[n][k] = (c[n-1][k-1] + c[n-1][k]) % md;
            }
        }
    }
    
    for k in 0..K+1 {
        for n in 0..N+1 {
            if k > 0 {
                anssum[n][k] = (anssum[n][k-1] + ans[n][k-1]) % md;
            }
            let mut ansnk: usize = 0;
            for t in 0..n {
                let tmp = ans[t][k] * anssum[n-1-t][k] % md;
                let tmp = tmp * c[n-1][t] % md;
                ansnk += tmp;
                ansnk %= md;
            }
            if n == 0 {
                ansnk = 1;
            }
            ans[n][k] = ansnk;
        }
    }

    println!("{}", ans[N][K]);
}

// thanks, ir5
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}