#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'
const int INF = 1000000001;

using namespace std;

int A(int k, int n, int C){
    int ans = 1;
    for (int q = n; q > n-k; q--){
        ans = ans*q % C;
    }
    return ans;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, C;
    cin >> n >> C;
    int k = n*(n-1)/2;
    int num[n+1][k+1], pref[n+1][k+2];
    num[1][0] = 1, pref[1][0] = 0;
    fill(num[1]+1, num[1]+k+1, 0);
    fill(pref[1]+1, pref[1]+k+2, 1);
    for (int q = 2; q <= n; q++){
        for (int q1 = 0; q1 <= k; q1++){
            num[q][q1] = ((pref[q-1][q1+1]-pref[q-1][max(0LL, q1-q+1)]) % C+C) % C;
        }
        pref[q][0] = 0;
        for (int q1 = 1; q1 <= k+1; q1++){
            pref[q][q1] = (pref[q][q1-1]+num[q][q1-1]) % C;
        }
    }
    int d[n+1];
    fill(d, d+n+1, 0);
    for (int q = 2; q <= n; q++){
        for (int q1 = 1; q1 < q; q1++){
            for (int q3 = 0; q3 <= k; q3++){
                d[q] += num[q-1][q3]*(pref[q-1][k+1]-pref[q-1][min(k+1, q3+q1+1)]) % C*(q-q1) % C;
            }
        }
        d[q] = (d[q] % C+C) % C;
    }
    int ans = 0;
    for (int q = 0; q < n; q++){
        ans += d[n-q]*A(q, n, C) % C;
    }
    cout << ans % C << endl;
    return 0;
}
