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
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <queue>
#include <array>

using namespace std;

#ifdef USE_CERR_LOG
#define LOG if (true) cerr
const bool LogEnabled = true;
#else
#define LOG if (false) cerr
const bool LogEnabled = false;
#endif

bool LogBigEnabled = true;

#ifdef USE_FILE_CIN
ifstream fin("mal.in");
#define cin fin
#endif

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;


ll plankCount, plankLength, prime;


void readData() {
    ios_base::sync_with_stdio(false);
    cin >> plankCount >> plankLength >> prime;
}


void solve() {
    int i, j, k, l;
    vector<vector<ll>> prevCounts, counts;
    
    prevCounts.resize(plankLength);
    counts.resize(plankLength);
    
    for (i = 0; i < plankLength; i++) {
        prevCounts[i].resize(plankLength + 1);
        counts[i].resize(plankLength + 1);
        
        for (j = i + 1; j <= plankLength; j++) {
            prevCounts[i][j] = 1;
        }
    }
    
    for (int a = 1; a < plankCount; a++) {
        for (i = 0; i < plankLength; i++) {
            for (j = i + 1; j <= plankLength; j++) {
                ll count = 0;
                for (k = 0; k < j; k++) {
                    for (l = i+1; l <= plankLength; l++) {
                        count = (count + prevCounts[k][l]) % prime;
                    }
                }
                counts[i][j] = count;
            }
        }
        swap(counts, prevCounts);
    }
    
    ll result = 0;
    for (i = 0; i < plankLength; i++) {
        for (j = i + 1; j <= plankLength; j++) {
            result = (result + prevCounts[i][j]) % prime;
        }
    }
    
    cout << result;
}


int main() {
    readData();
    
    if (plankCount == 1) {
        cout << (plankLength * (plankLength + 1)) / 2 % prime;
        return 0;
    } else if (plankLength == 1) {
        cout << 1;
        return 0;
    } else {
        solve();
    }
    
    return 0;
}