#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define sz(x) ((int)(x).size())

// #define MULTIPLE_CASES

ll n, MOD;

vector<vector<ll>> dp;

void solve()
{
    cin >> n >> MOD;
    dp.assign(n+1, vector<ll>(n*n));
    vector<vector<ll>> pref(n+1, vector<ll>(n*n));
    dp[0][0] = 1;
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 0; j <= i*(i-1)/2; ++j)
        {
            for(int k = 0; k < i && k <= j; ++k)
            {
                dp[i][j] = (dp[i][j] + dp[i-1][j-k]) % MOD;
            }
            // cout << i << " " << j << " " << dp[i][j] << "\n";
            pref[i][j+1] = (pref[i][j] + dp[i][j]) % MOD;
        }
    }

    vector<vector<ll>> fac(n+1, vector<ll>(n+1));
    for(ll i = 0; i <= n; ++i)
    {
        fac[i][i] = i;
        for(ll j = i-1; j > 0; --j)
        {
            fac[i][j] = (fac[i][j+1] * j) % MOD;
        }
    }
    ll ans = 0;
    for(int i = 1; i < n; ++i)
    {
        for(int j = 1; j <= n-i; ++j)
        {
            int k = n-i;
            for(int x = j+1; x <= k*(k-1)/2; ++x)
            {
                // ll p = (pref[k][k*(k-1)/2+1] - pref[k][x] + MOD) % MOD;
                ll p = dp[k][x];
                ll q = pref[k][x-j];
                ll add = k+1 - j;
                if(i > 1) add = (add * fac[n][k+2]) % MOD;
                add = (((add * p) % MOD) * q) % MOD;
                // cout << i << " " << j << " " << x << " " << add << "\n";
                ans = (ans + add) % MOD;
            }
        }
    }

    cout << ans << "\n";
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    #ifdef MULTIPLE_CASES
    int t;
    cin >> t;
    for(int i = 0; i < t; ++i)
    {
        solve();
    }
    #else
    solve();
    #endif
}