#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<queue>
#include<cmath>
#include<deque>
#include<stack>
#include<iomanip>
#include<random>
#include<cstdio>
#include<string>
#include<cstring>
#include<fstream>
#include<numeric>
#include<bitset>
#include<cassert>

using namespace std;

const long long N = 51, M = 25 * 49 + 1;

long long n, m;
long long dp[N][N][M];
long long d[N][M];
long long p[N][N][M];

long long add(long long a, long long b) {
    return (a + b) % m;
}

long long mul(long long a, long long b) {
    return a * b % m;
}

void build() {
    dp[1][1][0] = 1;
    d[1][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= i * (i - 1) / 2; j++) {
            for (int k = 1; k <= min(i, j + 1); k++) {
                dp[i][k][j] = d[i - 1][j - k + 1];
                p[i][k][j] = dp[i][k][j];
                if (j > 0) {
                    p[i][k][j] = add(p[i][k][j - 1], p[i][k][j]);
                }
                d[i][j] = add(d[i][j], dp[i][k][j]);
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(30);
    int _ = 1;
    //cin >> _;
    while (_--) {
        long long ans = 0;
        cin >> n >> m;
        build();
        long long cur = 1;
        for (int i = n; i >= 1; i--) {
            for (int k = 1; k < i; k++) {
                for (int l = k + 1; l <= i; l++) {
                    for (int j = 1; j <= (i - 1) * (i - 2) / 2 + k - 1; j++) {
                        ans = add(ans, mul(cur, mul(dp[i][k][j], p[i][l][j - 1])));
                    }
                }
            }
            cur = mul(cur, i);
        }
        cout << ans << endl;
    }
}