#pragma GCC optimize("2,Ofast,inline")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define LL long long
#define pii pair<int, int>
using namespace std;
const int N = 1e5 + 10;
int mod;

template <typename T> T read(T &x) {
	int f = 0;
	register char c = getchar();
	while (c > '9' || c < '0') f |= (c == '-'), c = getchar();
	for (x = 0; c >= '0' && c <= '9'; c = getchar())
		x = (x << 3) + (x << 1) + (c ^ 48);
	if (f) x = -x;
	return x;
}


namespace Comb {
	const int Maxn = 1000;
	
	int fac[Maxn], fav[Maxn], inv[Maxn];
	
	void comb_init() {
		fac[0] = fav[0] = 1;
		inv[1] = fac[1] = fav[1] = 1;
		for (int i = 2; i < Maxn; ++i) {
			fac[i] = 1LL * fac[i - 1] * i % mod;
			inv[i] = 1LL * -mod / i * inv[mod % i] % mod + mod;
			fav[i] = 1LL * fav[i - 1] * inv[i] % mod;
		}
	}
 
	inline int C(int x, int y) {
		if (x < y || y < 0) return 0;
		return 1LL * fac[x] * fav[y] % mod * fav[x - y] % mod;
	}

	inline int Qpow(int x, int p) {
		int ans = 1;
		for (; p; p >>= 1) {
			if (p & 1) ans = 1LL * ans * x % mod;
			x = 1LL * x * x % mod;
		}
		return ans;
	}

	inline int Inv(int x) {
		return Qpow(x, mod - 2);
	}
 
	inline void upd(int &x, int y) {
		(x += y) >= mod ? x -= mod : 0;
	}

	inline int add(int x, int y) {
		return (x += y) >= mod ? x - mod : x;
	}

	inline int dec(int x, int y) {
		return (x -= y) < 0 ? x + mod : x;
	}

}
using namespace Comb;

int n;
int f[55][1300], g[55], sum[55][1300];

int main() {
	read(n); read(mod);
	f[1][0] = 1;
	int Max = n * (n - 1) / 2;
	for (int i = 2; i <= n; ++i) {
		for (int j = 0; j <= Max; ++j) {
			for (int k = j; k >= 0 && k >= j - (i - 1); --k) {
				upd(f[i][j], f[i - 1][k]);
			}
		}
	}
	// for (int i = 1; i <= 5; ++i) {
	// 	for (int j = 0; j <= 10; ++j) {
	// 		cout << f[i][j] << ' ';
	// 	}
	// 	puts("");
	// }
	for (int i = 1; i <= n; ++i) {
		sum[i][0] = f[i][0];
		for (int j = 1; j <= Max; ++j) {
			sum[i][j] = add(sum[i][j - 1], f[i][j]);
		}
	}
//	cout << sum[5][10];
	for (int i = 2; i <= n; ++i) {
		upd(g[i], 1LL * g[i - 1] * i % mod);
		for (int j = 1; j <= i; ++j) {
			for (int k = j + 1; k <= i; ++k) {
				int tmax = (i - 1) * (i - 2) / 2;
				for (int w = 0; w <= tmax; ++w) {
					if (w - (k - j) > 0) {
						upd(g[i], 1LL * f[i - 1][w]
							 * sum[i - 1][w - (k - j) - 1] % mod);
					}
				}
			}
		}
	}
	// for (int i = 1; i <= n; ++i) cout << g[i] << ' ';
	// puts("");
	cout << g[n] << endl;
	return 0;
}
