#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 125005;
int n, mod; ll t[N], ans[N], f[2][N], s[2][N];
int main() {
	scanf("%d%d", &n, &mod), f[0][0] = 1;
	for (int i = 1; i <= n; ++ i) {
		int p = i & 1, q = p ^ 1; f[p][0] = s[p][0] = 1;
		for (int j = 1; j <= i * (i - 1) / 2; ++ j) {
			f[p][j] = 0;
			for (int k = j - i + 1; k <= j; ++ k)
				(f[p][j] += f[q][k]) %= mod;
			s[p][j] = (s[p][j - 1] + f[p][j]) % mod;
		}
		for (int x = 1; x <= i; ++ x)
			for (int y = x + 1; y <= i; ++ y)
				for (int w = max(0, y - x + 1); w <= i * (i - 1) / 2; ++ w)
					(t[i] += f[q][w] * s[q][w - y + x - 1]) %= mod;
	}
	for (int i = 2; i <= n; ++ i) ans[i] = (t[i] + i * ans[i - 1] % mod) % mod;
	return printf("%lld\n", ans[n]), 0;
}