#include <vector>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <utility>

using namespace std;

int prom(int n, const vector<vector<int>> & inv, int mod) {
    int res = 0;
    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j <= n; j++) {
            int sum = 0;
            for (int k = j - i + 1; k <= (n * (n - 1)) / 2; k++) {
                sum = (sum + inv[n - 1][k - j + i - 1]) % mod;
                res = (res + (int)( ((long long)sum * inv[n - 1][k]) % mod)) % mod;
            }
            //cout << res << endl;
        }
    }
    return res;
}

int main() {
    int n, mod;
    cin >> n >> mod;

    vector<vector<int>> inv(52, vector<int>(52 * 26, 0));

    inv[1][0] = 1;
    for (int i = 2; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            for (int k = j - 1; k <= (i * (i - 1)) / 2; k++) {
                inv[i][k] = (inv[i][k] + inv[i - 1][k - j + 1]) % mod;
            }
        }
    }

    /*for (int i = 1; i <= 4; i++) {
        for (int j = 0; j <= 6; j++) {
            cout << i << ' ' << j  << " " << inv[i][j] << endl;
        }
    }*/

    long long fac = 1;
    long long ans = 0;
    for (int k = 0; k <= n - 2; k++) {
        ans = (ans + ((fac * prom(n - k, inv, mod)) % mod)) % mod;
        fac = (fac * (n - k)) % mod;
    }

    printf("%lld\n", ans);
}