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<cstdio>
#include<algorithm>
#include<queue>
#include<utility>

#define MAXN 7003
int n, m, mod, wynik;
int dp[MAXN][MAXN];
int new_dp[MAXN][MAXN];
int main () {
  scanf("%d %d %d", &n, &m, &mod);
  
  for (int i = 0; i < m; i++) {
	for (int j = i; j < m; j++) {
		dp[i][j] = 1;
	}
  }
  for (int s = 1; s < n; s++) {
	for (int b = 0; b < m; b++) {
		for (int g = b; g < m; g++) {
			for (int p = 0; p <= g; p++) {
				for (int k = std::max(b, p); k < m; k++) {
					new_dp[b][g] += dp[p][k];
					new_dp[b][g] %= mod;
				}
			}			
		}
	}
	for (int p = 0; p < m; p++) {
		for (int k = p; k < m; k++) {
			dp[p][k] = new_dp[p][k];
			new_dp[p][k] = 0;
		}
	}
  }
  for (int p = 0; p < m; p++) {
		for (int k = p; k < m; k++) {
			wynik += dp[p][k];
			wynik %= mod;
		}
	}
  
  printf("%d\n", wynik);

  return 0;
}