#include"bits/stdc++.h" usingnamespace std; #define fi first #define se second #define vi vector<int> #define pb push_back #define eb emplace_back #define pii pair<int,int> #define mp make_pair #define rep( i , a , b ) for( int i = (a) , i##end = b ; i <= i##end ; ++ i ) #define per( i , a , b ) for( int i = (a) , i##end = b ; i >= i##end ; -- i ) #define mem( a ) memset( a , 0 , sizeof (a) ) #define all( x ) x.begin() , x.end() //#define int long long // #pragma GCC optimize(2) typedeflonglong ll; constint MAXN = 5e3 + 10; int P; int n , m , q;
intPow( int x , int a ){ int ret = 1; while( a ) { if( a & 1 ) ret = ret * 1ll * x % P; x = x * 1ll * x % P , a >>= 1; } return ret; }
int dp[MAXN][MAXN]; voidInc( int& x , int y ){ x = ( x + y < P ? x + y : x + y - P ); }
int d[MAXN] , C[MAXN][MAXN];
voidsolve(){ cin >> n >> m >> P; dp[0][0] = 1; for( int i = 1 ; i <= n ; ++ i ) for( int j = 1 ; j <= i ; ++ j ) { if( dp[i - 1][j - 1] ) Inc( dp[i][j] , dp[i - 1][j - 1] ); if( i >= 2 ) { Inc( dp[i][j] , dp[i - 2][j - 1] * 2 % P ); } } rep( j , 1 , n ) Inc( dp[n][j] , dp[n - 1][j] ); // cout << dp[n][2] << endl; rep( i , 0 , n ) { C[i][0] = 1; rep( j , 1 , i ) C[i][j] = ( C[i - 1][j] + C[i - 1][j - 1] ) % P; } rep( i , 0 , n ) { Inc( d[i] , C[n][i] ); Inc( d[i + 1] , P - dp[n][i] ); } rep( i , 1 , n ) d[i] = ( d[i] + d[i - 1] ) % P; // rep( i , 0 , m + 1 ) cout << d[i] << endl; int res = ( n != 3 ) + ( m == n - 1 ); rep( i , 3 , m ) Inc( res , d[i] ); cout << res << endl; }