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
#include<bits/stdc++.h>

using namespace std;

map<pair<int,int>,long long>M[2];
vector<pair<int,int>>pod;

vector<pair<int,int>> podzbiory(int a, int b)
{
	vector<pair<int,int>>pod;
	for(int i=a;i<=b;++i)
	{
		for(int j=i;j<=b;++j)
		{
			pod.push_back({i,j});
		}
	}
	return pod;
}

void rekt(int x, int l, int &m, long long &p)
{
	//cout << "X = " << x << endl;
	if(x==m)
		return ;
	M[l].clear();
	for(auto e: pod)
	{
		//cout << "rozwazam " << e.first << " " << e.second << endl;
		for(auto f: pod)
		{
			if(f.second>=e.first && f.first<=e.second)
			{
				//cout << "\t" << f.first << " " << f.second << endl;
				M[l][e]+=M[l^1][f];
				M[l][e]%=p;
				//cout << M[l^1][f] << endl;
			}
		}
	}
	rekt(x+1, l^1, m, p);
}

int main()
{
	int n,m;
	long long p, ans=0;
	scanf("%d%d%lld", &n, &m, &p);
	pod=podzbiory(1,m);
	for(auto e: pod)
	{
		M[0][e]=1;
		//cout << e.first << " " << e.second << endl;
	}
	rekt(1,1, n, p);
	if(n&1)
	{
		for(auto e: pod)
		{
			ans+=M[0][e];
			ans%=p;
		}
	}
	else
	{
		for(auto e: pod)
		{
			ans+=M[1][e];
			ans%=p;
		}
	}
	printf("%lld", ans);
	return 0;
}