1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>
using namespace std;

vector<vector<long long> > t[0];
int f;
long long P;

long long suma(int w, int h,int f,int m) {
	return (((t[f][m][m]-t[f][m][h-1]+P)%P-t[f][w-1][m]+P)%P+t[f][w-1][h-1])%P;
}

void go(int m) {
	for (int w=1;w<=m;w++)
		for (int h=m+1-w;h<=m;h++) {
			int y=m+1-h,x=m+1-w;
			t[1-f][w][h]=(((suma(y,x,f,m)+t[1-f][w-1][h])%P+t[1-f][w][h-1])%P-t[1-f][w-1][h-1]+P)%P;
		}
	f=1-f;
}

int main() {
	ios_base::sync_with_stdio(0);
	int n,m;
	cin >> n >> m >> P;
	for (int f=0;f<2;f++) {
		t[f].resize(m+2);
		for (int w=0;w<=m;w++) {
			t[f][w].resize(m+2);
		}
	}
	for (int w=1;w<=m;w++) {
		t[0][w][m+1-w]=1;
		for(int h=m+2-w;h<=m;h++)
			t[0][w][h]=((t[0][w-1][h]+t[0][w][h-1])%P-t[0][w-1][h-1]+1+P)%P;
	}
	for (int i=1;i<n;i++)
		go(m);
	/*
	for (int i=m;i>=0;i--) {
		for (int j=0;j<=m;j++)
			cout << t[f][i][j]<< " ";
		cout << endl;
	}*/
	cout << t[f][m][m];
	return 0;
}