#include <iostream>
#include <cstdio>
#include <cstring>
#define int long long
using namespace std;
int n,mod,C[55][55],A[55][55],f[55][1255],g[55][1255],sum[1255],ans;
signed main(){
    cin>>n>>mod;
    C[0][0]=1;
    for (int i=1;i<=n;i++)
        for (int j=0;j<=i;j++){
            C[i][j]=C[i-1][j];
            if (j>0)C[i][j]=(C[i][j]+C[i-1][j-1])%mod;
        }
    A[0][0]=1;
    for (int i=1;i<=n;i++)
    	for (int j=0;j<=i;j++){
    		A[i][j]=C[i][j];
    		for (int k=1;k<=j;k++)A[i][j]=A[i][j]*k%mod; 
		}
    f[1][0]=1;
    for (int i=2;i<=n;i++){
    	for (int j=0;j<=i*(i-1)/2;j++){
    		for (int k=0;k<i;k++)
				if (j>=k)f[i][j]=(f[i][j]+f[i-1][j-k])%mod;
	//		cout<<i<<' '<<j<<' '<<f[i][j]<<endl;
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=0;j<=i*(i-1)/2;j++){
			sum[j]=f[i][j];
			if (j>0)sum[j]=(sum[j]+sum[j-1])%mod;
		}
		for (int j=0;j<=n;j++){
			for (int k=0;k<=i*(i-1)/2;k++)
				if (k>=j)g[i][j]=(g[i][j]+f[i][k]*sum[k-j])%mod;
		}
	}
	for (int i=0;i<n;i++){
		int num=0;
		for (int j=1;j<=n-i;j++)
			for (int k=j+1;k<=n-i;k++)
				ans=(ans+A[n][i]*g[n-i-1][k-j+1])%mod;
	}
	cout<<ans<<endl;
    return 0;
}