#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a),i##ss=(b);i<=i##ss;i++)
#define dwn(i,a,b) for(int i=(a),i##ss=(b);i>=i##ss;i--)
#define deb(x) cerr<<(#x)<<":"<<(x)<<'\n'
#define pb push_back
#define fi first
#define se second
#define hvie '\n'
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

const int maxn=3e5+5;
int n,mod,f[55][2555]={1},s[55][2555]={1},ans[55];
int main(){
	cin>>n>>mod;
	rep(i,1,n*(n-1)/2) s[0][i]=1;
	rep(i,1,n){
		rep(j,0,n*(n-1)/2){
			if(j-i>=0) f[i][j]=(s[i-1][j]-s[i-1][j-i]+mod)%mod;
			else f[i][j]=s[i-1][j];
			s[i][j]=((j?s[i][j-1]:0)+f[i][j])%mod;
		}
	}
	rep(i,1,n){
		rep(j,1,i){
			rep(k,j+1,i){
				rep(w,0,(i-1)*(i-2)/2){
					int t=w-(k-j)-1;
					if(t<0) continue;
					ans[i]=(ans[i]+1ll*f[i-1][w]*s[i-1][t]%mod)%mod;
				}
			}
		}
	}
	rep(i,2,n) ans[i]=(ans[i]+1ll*i*ans[i-1]%mod)%mod;
	cout<<ans[n]<<hvie;
	return 0;
}
