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


int MOD;


vector<long long> sum(const vector<int> & V) {
    vector<long long> res(V.size()+1);
    for (int i=0; i< (int)V.size();i++) {
        res[i+1]= (res[i] + V[i]);
    }
    return res;
}

vector<long long> sum2(const vector<int> & V) {
    vector<long long> res(V.size()+1);
    for (int i=0; i< (int)V.size();i++) {
        res[i+1]= (res[i] + 1LL*i*V[i]);
    }
    return res;
}


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m >> MOD;
    vector<int> A(m+1);
    iota(A.begin(), A.end(), 0);
    while(--n) {
        auto sumA=sum(A);
        auto sum2A=sum2(A);
        
        for (int k=0; k<m+1; k++) {
            long long b = (1LL*sumA.back()*k);
            b -= 1LL*k*(sumA[m+1-k]+sumA[k]);
            b += sum2A[k];
            A[k]=(b%MOD+MOD)%MOD;
        }

    }
    cout << sum(A).back()%MOD << endl;
    
    return 0;
}