#include <iostream>
#include <random>
#include <chrono>
#include <ctime>
#include <string>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define int long long
using ll = long long;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N = 101;
int n, mod;
int f[N][N * N];
int pp[N][N * N];
int add(int x, int y) {
    return (x + y) % mod;
}
int mult(int x, int y) {
    return 1ll * x * y % mod;
}
int A(int n, int m) {
    if (n < m) return 0;
    int ret = 1;
    for (int i = 0; i < m; i++)
        ret = mult(ret, n - i);
    return ret;
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int ans = 0;
    cin >> n >> mod;
    if (mod == 1) {
        cout << 0;
        return 0;
    }
    int R = n * (n - 1) / 2 + 10;
    f[0][0] = 1;
    for (int i = 0; i < n; i++)
        for (int inv = 0; inv <= i * (i - 1) / 2; inv++)
            for (int plus = 0; plus <= i; plus++)
                f[i + 1][inv + plus] = add(f[i + 1][inv + plus], f[i][inv]);
    for (int i = 0; i <= n; i++) {
        pp[i][0] = f[i][0];
        for (int j = 1; j < R; j++)
            pp[i][j] = add(pp[i][j - 1], f[i][j]);
    }
    for (int pref = 0; n - pref - 1 >= 0; pref++) {
        int koef = A(n, pref);
        int cur = 0;
        for (int x = 1; x <= n - pref; x++)
            for (int y = x + 1; y <= n - pref; y++) {
                for (int cnt1 = 0; cnt1 < R; cnt1++) {
                    int cnt2 = cnt1 + x - y;
                    if (cnt2 > 0)
                        cur = add(cur, mult(f[n - pref - 1][cnt1], pp[n - pref - 1][cnt2 - 1]));
                }
            }
        ans = add(ans, mult(cur, koef));
    }
    cout << ans;
    return 0;
}