#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    long long solve(int n, long long MOD) {
        if (n == 1) {
            return 0;
        }

        vector<vector<long long>> C(n + 1, vector<long long>(n + 1, 0));
        for (int i = 0; i <= n; ++i) {
            C[i][0] = 1;
            for (int j = 1; j <= i; ++j) {
                C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
                C[i][j] %= MOD;
            }
        }
        vector<long long> FS(n + 1, 1);
        for (int i = 2; i <= n; ++i) {
            FS[i] = FS[i - 1] * i;
            FS[i] %= MOD;
        }

        auto calc = [&](int n) {
            int m = n * (n - 1) / 2;
            vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 0));
            dp[0][0] = 1;
            int mx = 0;
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j <= mx; ++j) {
                    for (int k = 0; k <= i; ++k) {
                        int nj = j + k;
                        dp[i + 1][nj] += dp[i][j];
                        if (dp[i + 1][nj] >= MOD) {
                            dp[i + 1][nj] -= MOD;
                        }
                    }
                }
                mx = (i + 1) * i / 2;
            }
            return dp;
        };

        auto dp = calc(n - 1);
        // for (int i = 0; i < dp.size(); ++i) {
        //     int mx = i * (i - 1) / 2;
        //     for (int j = 0; j <= mx; ++j) {
        //         cout << "(" << i << "," << j << ")=" << dp[i][j] << ' ';
        //     }
        //     cout << endl;
        // } 
        long long res = 0;
        for (int lcp = 0; lcp < n; ++lcp) {
            int m = n - lcp;
            auto& A = dp[m - 1];
            int mx = (n - lcp - 1) * (n - lcp - 1 - 1) / 2;
            long long ans = 0;
            for (int i = 0; i < m; ++i) {
                for (int j = i + 1; j < m; ++j) {
                    int P = i;
                    int Q = j;
                    
                    long long cnt = 0;
                    for (int p = 0, q = 0; p <= mx; ++p) {
                        while (q <= mx && p + P > q + Q) {
                            cnt += A[q];
                            if (cnt >= MOD) {
                                cnt -= MOD;
                            }
                            ++q;
                        }
                        ans += (cnt * A[p]) % MOD;
                        if (ans >= MOD) {
                            ans -= MOD;
                        }
                    }
                    // cout << P << " - " << Q << " " << ans << endl;
                }
            }
            (ans *= C[n][lcp]) %= MOD;
            (ans *= FS[lcp]) %= MOD;
            (res += ans) %= MOD;
            // cout << lcp << " :: " << res << " " << ans << " " << mx << endl;
        }
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    Solution sol;

    int n;
    long long MOD;
    cin >> n >> MOD;

    cout << sol.solve(n, MOD) << '\n';


    return 0;
}