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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<bits/stdc++.h>
#define inf 1000000009
#define linf (1ll<<60)
#define lim 10000009
#define mk make_pair
#define sc second
#define ff first

using namespace std;

int n,m,md,pocz[2][lim],zaw[2][lim];
//long long tst[2][lim];

int main()
{
	scanf("%d%d%d", &n, &m, &md);
	//scanf("%d%d", &n, &m);md = 1000000000;
	if(m == 1)
	{
		printf("1\n");
		return 0;
	}
	for(int i = 0;i<m;++i)
	{
		pocz[0][i] = (m-i)%md;
		zaw[0][i] = (long long)(m-i)*(i+1)%md;
	}
	for(int i = 1;i<n;++i)
	{
		/*
		for(int j = 0;j<m;++j)
		{
			tst[i&1][j] = 0;
		}
		for(int h = 0;h<m;++h)
		{
			for(int g = h;g<m;++g)
			{
				long long s = zaw[(i&1)^1][h];
				for(int j = h+1;j<=g;++j)
				{
					s = (s+pocz[(i&1)^1][j])%md;
				}
				
				for(int j = h;j<=g;++j)
				{
					tst[i&1][j] = (tst[i&1][j]+s)%md;
				}
			}
		}
		for(int j = 0;j<m;++j){printf("%lld ", tst[i&1][j]);}
		//*/
		
		
		
		//printf("#%d:  ", i);
		for(int j = m-2;j>=0;--j)
		{
			pocz[(i&1)^1][j] = ((long long)pocz[(i&1)^1][j]*(m-j)+pocz[(i&1)^1][j+1])%md;
			//printf("%d ", pocz[(i&1)^1][j]);
		}
		//printf(" |  ");
		for(int j = 0;j<m;++j)
		{
			pocz[i&1][j] = ((long long)pocz[(i&1)^1][j+1]+(long long)zaw[(i&1)^1][j]*(m-j))%md;
			//printf("%d ", pocz[(i&1)][j]);
		}
		//printf("| ");
		for(int j = 0;j<m;++j)
		{
			zaw[i&1][j] = ((long long)pocz[(i&1)^1][j+1]*(j+1)+(long long)pocz[(i&1)^1][m-j]*(m-j) + (long long) zaw[(i&1)^1][j]*(m-j)%md*(j+1))%md;
			//printf("%d ", zaw[(i&1)][j]);
		}
		//printf("\n");
		
		
		
	}
	int i = (n-1)&1;
	long long wyn = 0;
	for(int j = 0;j<m;++j)
	{
		wyn = (wyn+pocz[i][j])%md;
	}
	printf("%lld\n", wyn);
}