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

using namespace std;


long long burnl[1009][19];
long long burnbig[1009][19];
long long burnbigless[1009][19];
long long burnlless[1009][19];
long long tab[1009][1009];

int n, k, p;

long long dwum(int nn, int kk){
    if(tab[nn][kk]!=0)return tab[nn][kk];
    if(nn<kk)return 0;
    if(nn==0 || kk==0 || nn==kk){
        tab[nn][kk]=1;
    }
    else tab[nn][kk]=tab[nn-1][kk]+tab[nn-1][kk-1];
    tab[nn][kk]%=p;
    return tab[nn][kk];
}


int main(){
    ios_base::sync_with_stdio(0);
    cin>>n>>k>>p;

    burnl[0][0]=1;
    burnbig[0][0]=1;
    for(int t=1;t<15;++t){
        burnlless[0][t]=burnlless[0][t-1]+burnl[0][t-1];
        burnbigless[0][t]=burnbigless[0][t-1]+burnbig[0][t-1];
    }

    for(int i=1;i<=n;++i){
        for(int j=0;j<i;++j){
            for(int t=1;t<15;++t){
                burnl[i][t]+=burnbig[j][t-1]*dwum(i-1, j)%p*burnlless[i-1-j][t]%p;
                burnl[i][t]+=burnl[i-1-j][t]*dwum(i-1, i-1-j)%p*burnbigless[j][t-1]%p;
                burnl[i][t]+=burnl[i-1-j][t]*dwum(i-1, i-1-j)%p*burnbig[j][t-1]%p;

                burnbig[i][t]+=burnbig[j][t]*dwum(i-1, j)%p*burnbigless[i-1-j][t]%p;
                burnbig[i][t]+=burnbig[i-1-j][t]*dwum(i-1, i-1-j)%p*burnbigless[j][t]%p;
                burnbig[i][t]+=burnbig[i-1-j][t-1]*dwum(i-1, i-1-j)%p*burnbig[j][t-1]%p;
                burnl[i][t]%=p;
                burnbig[i][t]%=p;
            }

            for(int t=1;t<15;++t){
                burnlless[i][t]=burnlless[i][t-1]+burnl[i][t-1];
                burnbigless[i][t]=burnbigless[i][t-1]+burnbig[i][t-1];
                burnbigless[i][t]%=p;
                burnlless[i][t]%=p;
            }
        }
    }

    long long wyn=0;
    for(int j=0;j<n;++j){
        wyn+=burnl[j][k]*dwum(n-1, j)%p*burnlless[n-1-j][k]%p;
        wyn+=burnlless[j][k]*dwum(n-1, j)%p*burnl[n-1-j][k]%p;
        wyn+=burnl[j][k]*dwum(n-1, j)%p*burnl[n-1-j][k]%p;
    }
    wyn%=p;

    /*
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            cout<<"bl "<<i<<" "<<j<<" "<<burnl[i][j]<<" ";
        }
        cout<<endl;
    }

    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            cout<<"bbig "<<i<<" "<<j<<" "<<burnbig[i][j]<<" ";
        }
        cout<<endl;
    } */

    cout<<wyn<<endl;


    return 0;
}