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
140
141
142
143
144
145
146
147
148
149
150
#include<iostream>
//#include<windows.h>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector< ii > vii;
typedef vector< pair < ii, int > > viii;
typedef vector< vector < ii > > vvii;
typedef pair < pair < int, int >, int >  iii;
typedef pair < pair < int, int >, pair < int, int > > iiii;
typedef unsigned long long ull;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< ll > vll;
typedef long double ld;
typedef map < int, int > MAPA;

#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define st first
#define nd second
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rall(c) (c).rbegin(), (c).rend()
#define FOR(i, a, b)    for (int (i)=(a); (i)<(b); (i)++)
#define FOR2(i, a, b)    for (int (i)=(a); (i)>=(b); (i)--)

template<typename T> inline void setmin(T &x, T y) { if (y < x) x = y; }
template<typename T> inline void setmax(T &x, T y) { if (y > x) x = y; }
template<typename T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }

const int MAX = 2e6 + 7;
const int T = 1 << 20;
const int INF = 1e9 + 7;
const ll BIG_INF = 1e18 + 5;

ld e = 2.7182818284590452353602874713526624;
ld PI = acos(-1);
ld eps = 1e-19;

ll n, m, k;
bitset<100> odw;
int dp[100][100];
vi per;

void wypisz( int i , int dl)
{
	dl--;
	int roz = 0;
	int pom = i;
	if( !i ){
		roz++;
	}
	while( i )
	{
		roz++;
		i /= 10;
	}
	for( int i = 0 ; i < dl - roz ;i++ )
	{
		cout << ' ';
	}
	cout << pom << ' ';
}

void compute( int roz ){
	vi pom = per;

	int turns = 0;
	while( sz(pom) > 1){
		turns++;
		vi nowy;
		for( int i = 0 ; i < sz(pom) ; i++ ){
			bool good = 1;
			if( i > 0 && pom[ i - 1 ] > pom[i]){
				good = 0;
			}	
			if( i < sz(pom) - 1 && pom[i+1] > pom[i]){
				good = 0;
			}
			if(good){
				nowy.pb(pom[i]);
			}
		}
		pom = nowy;
	}
	dp[roz][turns]++;
}

void dfs( int ile , int roz ){
	if( ile == 0){
		compute( roz );
	}
	else{
		for( int i = 1 ; i <= roz ; i++ ){
			if( !odw[i] ){
				odw[i] = 1;
				per.pb( i );
				dfs( ile - 1 , roz );
				per.pop_back();
				odw[i] = 0;
			}
		}
	}
}

int main() {
	boost;

	//cin >> n >> m;
	n = 10 , m = 10;

	for( int i = 1 ; i <= n ; i ++ ){
		dfs( i , i);
	}
	/*cout << "************";
	for( int i = 0 ; i < 6 ; i++ ){
		cout << "  col" << i <<  "   ";  
	}
	cout << '\n';
	for( int i = 0 ; i < 13 ; i++ ){
		cout << "row : " ;
		wypisz( i , 3 );
		for( int j = 0 ; j < 6 ; j++){
			wypisz(dp[i][j] , 9);
		}
		cout << '\n';
	}*/
	int p;
	cin >> n >> m >> p;
	cout << dp[n][m] % p;
}