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
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <bits/stdc++.h>                                                        
using namespace std;                                                            
const int maxn = 1100;                                                          
typedef long long ll;                                                           
typedef pair<int, int> Pii;                                                     
typedef vector<Pii> vpii;                                                       
typedef vector<int> vi;
typedef vector<vi> vvi;                                                         
typedef vector<ll> vll;                                                         
#define pb push_back                                                            
#define fst first                                                               
#define snd second
ll N, K, p;
ll dp[maxn][16][3];
ll binom[maxn][maxn];
bool ok[maxn][16][3];
ll dp2[maxn][16][3];
bool ok2[maxn][16][3];
ll jebaj(int n, int k, int type);
ll sumka(int n, int k, int type)
{
	if(k == 0)
		return jebaj(n,k,type);
	if(!ok2[n][k][type])
	{
		if(k > 0)
			dp2[n][k][type] = (jebaj(n,k,type) + sumka(n,k-1,type)) % p;
		else
			dp2[n][k][type] = jebaj(n,k,type);
		ok2[n][k][type] = true;
	}
	return dp2[n][k][type];
}
ll jebaj(int n, int k, int type)
{
	if(!ok[n][k][type])
	{
		ll res = 0;
		if(type == 0)
		{
			if(k == 0) return n == 1;
			//if(n == 1) return k == 0;
			for(int i = 0; i < n; ++i)
			{
				ll res2 = jebaj(i, k, 1) * jebaj(n-i-1, k, 1);
				//res += binom[n-1][i] * jebaj(i, k, 1) % p * jebaj(n-i-1, k, 1) % p;
				//for(int j = 0; j < k; ++j)
				{
					///res += binom[n-1][i] * jebaj(i, k, 1) % p * jebaj(n-i-1, j, 1) % p;
					res2 += jebaj(i, k, 1) * sumka(n-i-1, k-1, 1);
					///res += binom[n-1][i] * jebaj(i, j, 1) % p * jebaj(n-i-1, k, 1) % p;
					res2 += sumka(i, k-1, 1) * jebaj(n-i-1, k, 1);
				}
				res += res2 % p * binom[n-1][i] % p;
			}
		}
		if(type == 1)
		{
			if(k == 0) return n == 0;
			if(n == 1) return k == 1;
			for(int i = 0; i < n; ++i)
			{
				//res += binom[n-1][i] * jebaj(i, k - 1, 2) % p * jebaj(n-i-1, k-1, 1) % p;
				//for(int j = 0; j < k; ++j)
				{
					//res += binom[n-1][i] * jebaj(i, k - 1 , 2) % p * jebaj(n-i-1, j, 1) % p;
					ll res2 = jebaj(i, k - 1 , 2) * sumka(n-i-1, k-1, 1);
					//res += binom[n-1][i] * jebaj(i, k - 1 , 2) % p * sumka(n-i-1, k-1, 1) % p;
					
					//res += binom[n-1][i] * jebaj(i, j, 2) % p * jebaj(n-i-1, k, 1) % p;
					res2 += sumka(i, k-1, 2) * jebaj(n-i-1, k, 1);
					res += res2 % p * binom[n-1][i] % p;
				}
			}
		}
		if(type == 2) // obie strony
		{
			if(k == 0) return n == 0;
			if(n == 1) return k == 1;
			for(int i = 0; i < n; ++i)
			{
				ll res2 = jebaj(i, k-1, 2) * jebaj(n-i-1, k-1, 2);
				//for(int j = 0; j < k; ++j)
				{

					//res += binom[n-1][i] * jebaj(i, k, 2) % p * jebaj(n-i-1, j, 2) % p;
					res2 += jebaj(i, k, 2) * sumka(n-i-1, k-1, 2);
					
					
					//res += binom[n-1][i] * jebaj(i, j, 2) % p * jebaj(n-i-1, k, 2) % p;
					res2 += sumka(i, k-1, 2) * jebaj(n-i-1, k, 2);
					res += res2 % p * binom[n-1][i] % p;
				}
			}
		}
		dp[n][k][type] = res % p;
		ok[n][k][type] = true;
	}

	return dp[n][k][type];
}
void init()
{
	for(int i = 0; i < maxn; ++i)
		binom[i][0] = 1;
		
	for(int i = 1; i < maxn; ++i)
		for(int j = 1; j <= i; ++j)
		{
			binom[i][j] = (binom[i-1][j] + binom[i-1][j-1]);
			if(binom[i][j] > p)
				binom[i][j] -= p;
		}
}
int main()
{
	scanf("%lld%lld%lld", &N, &K, &p);
	//N = 1000; K = 15; p = 100000007;
	init();
	
	//~ ll sum = 0;
	//~ for(int i = 1; i <= 1000; ++i)
		//~ for(int j = 1; j < 11; ++j)
			//~ sum += i * j * jebaj(i,j,0) % p;
	//~ printf("suma = %lld\n", sum % p);
	
	if(K >= 11)
		puts("0");
	else
		printf("%lld\n", jebaj(N, K, 0));
	return 0;
	//~ for(int i = 1; i < 1001; ++i)
	//~ {
		//~ for(int j = 1; j < 11; ++j)
			//~ printf("%lld ", jebaj(i, j, 0));
		//~ puts("");
	//~ }
	
}