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

#define luk(n,m) for(int i=n; i<m; ++i)
#define maxn 1010
#define pb(n) push_back(n)
#define mp make_pair
#define inf 1000000000
#define mod 1000000007
#define mod1 1000696969
#define ff first.first
#define fs first.second
#define ll long long



using namespace std;


vector<int>v[2];
int tab[maxn];
int wynik,n,k;

bool spraw()
{
	v[0].clear();
	luk(0,n)
	v[0].pb(tab[i]);
	int x=1,y=0;
	while((int)v[x^1].size()!=1)	
	{
		v[x].clear();
		int s=(int)v[x^1].size();
		luk(0,s)
		{
			if(i==0)
			{
				if(v[x^1][i]>v[x^1][i+1])
				v[x].pb(v[x^1][i]);
			}
			else
			{
			if(i==s-1)
			{
				if(v[x^1][i]>v[x^1][i-1])
				v[x].pb(v[x^1][i]);
			}
			else
			{
				if(v[x^1][i]>v[x^1][i-1]&&v[x^1][i]>v[x^1][i+1])
				v[x].pb(v[x^1][i]);
			}
			}
		}
		++y;
		x=x^1;
	}
	return y==k;
}


int main()
{
	int p;
	scanf("%d%d%d", &n, &k, &p);
	luk(0,n)
	{
		tab[i]=i+1;
	}
	do
	{
		if(spraw())
		++wynik;
	}while(next_permutation(tab, tab+n));
	printf("%d", wynik%p);
}