#include<bits/stdc++.h>

#define ll long long
#define inf 0x3f3f3f3f
#define Inf 0x3f3f3f3f3f3f3f3f

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = a; i >= (b); --i)

using namespace std;

int mod;

const int maxn = 55;

int n;
ll val[maxn], dp[maxn][maxn * maxn / 2], sum[maxn][maxn * maxn / 2], res;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> mod;
	val[n] = 1;
	per(i, n-1, 2) val[i] = val[i+1] * (i+1) % mod;
	//per(i, n, 2) cout << val[i] << "\n";
	dp[1][0] = 1;
	sum[1][0] = sum[1][1] = 1;
	rep(i, 2, n){
		rep(j, 0, i * (i - 1) / 2 + 1){
			if(j - i >= 0) dp[i][j] = sum[i-1][j] - sum[i-1][j-i];
			else dp[i][j] = sum[i-1][j];
			if(dp[i][j] < 0) dp[i][j] += mod;
			//cout << i << ' ' << j << ' ' << dp[i][j] << "\n";
		}
		sum[i][0] = dp[i][0];
		rep(j, 1, i * (i + 1) / 2 + 1){
			sum[i][j] = sum[i][j-1] + dp[i][j];
			if(sum[i][j] >= mod) sum[i][j] -= mod;
		}
		rep(j, 0, i * (i - 1) / 2 + 1){
			rep(k, j + 2, i * (i - 1) / 2 + 1){
				ll tmp = 0;
				tmp += val[i+1] * (i * (i + 1) / 2);
				if(k - j <= i) tmp -= val[i+1] * ((i+1-k+j) * (i+1-k+j + 1) / 2);
				tmp %= mod;
				if(tmp < 0) tmp += mod;
				tmp = tmp * dp[i][j] % mod * dp[i][k] % mod;
				res += tmp;
				if(res >= mod) res -= mod;
				//cout << j << ' ' << k << ' ' << res << "\n";
			}
		}
		//cout << res << "\n";
	}
	cout << res << "\n";
}