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)

// https://atcoder.jp/contests/agc024/tasks/agc024_e
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        n: usize, k: usize, MOD: usize
    };

   let mut comb = vec![vec![0; n+2]; n+2];
    for i in 0..n+2 {
        comb[i][0] = 1;
        comb[i][i] = 1;
        for j in 1..i {
            comb[i][j] = (comb[i-1][j-1] + comb[i-1][j]) % MOD;
        }
    }

    let mut dp = vec![vec![0; k+1]; n+2];
    for i in 0..k+1 {
        dp[1][i] = 1;
    }


    let mut dp_sum = vec![vec![0; k+2]; n+2];
    for i in 2..n+2 {
        for j in 0..k+1 {
            let p = dp_sum[i-1][j];
            dp_sum[i-1][j+1] = (p + dp[i-1][j]) % MOD;
        }

        for j in 0..k+1 {
            let mut total = 0;
            for w in 1..i {
                total += (MOD + dp_sum[w][k+1] - dp_sum[w][j+1]) % MOD * dp[i-w][j] % MOD * comb[i-2][w-1] % MOD;
                total %= MOD;
            }
            dp[i][j] = total;
            // dp[i][j] = sum(k, c(>j)) { dp[i-k][c] * dp[k][j] )
        }
    }

    println!("{}", dp[n+1][0]);
}