#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<ll> vii;
typedef vector<pii> vpii;
typedef unordered_map<int,int> umap;
typedef long double ld;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define popcount __builtin_popcount
#define case cout<<"Case "<<z-t<<": ";
static int M,C;
typedef complex<double> cd;
const double PI = acos(-1);
int N=505;
void fft(vector<cd> &a,bool invert){
    int n=a.size();

    for(int i=1,j=0;i<n;i++){
        int bit=n>>1;
        for(;j&bit;bit>>=1) j^=bit;
        j^=bit;
        if(i<j) swap(a[i],a[j]);
    }

    for(int len=2;len<=n;len<<=1){
        double ang=2*PI/len*(invert?-1:1);
        cd wlen(cos(ang),sin(ang));
        for(int i=0;i<n;i+=len){
            cd w(1);
            for(int j=0;j<len/2;j++){
                cd u= a[i+j], v=a[i+j+len/2]*w;
                a[i+j] = u+v;
                a[i+j+len/2] =u-v;
                w*=wlen;
            }
        }
    }
    if(invert) for(cd &x : a) x/=n;
}
vii multiply(vii const &a, vii const& b){
    vector<cd> fa(a.begin(),a.end()),fb(b.begin(),b.end());
    int n=1;
    while(n<a.size()+b.size()) n<<=1;
    fa.resize(n);
    fb.resize(n);
    fft(fa,false);
    fft(fb,false);
    for(int i=0;i<n;i++) fa[i]*=fb[i];
    fft(fa,true);
    vii result(n);
    for(int i=0;i<n;i++) result[i]=(ll)round(fa[i].real())%M ;
    return result;
}

vii __multiply(vii &a,vii &b){
    vii a1(a.size()),a2(a.size()),b1(b.size()),b2(b.size());
    for(int i=0;i<a.size();i++) a2[i]=a[i]/C,a1[i]=a[i]%C;
    for(int i=0;i<b.size();i++) b2[i]=b[i]/C,b1[i]=b[i]%C;
    vii f11=multiply(a1,b1),f12=multiply(a1,b2),
        f21=multiply(a2,b1),f22=multiply(a2,b2);
    for(int i=0;i<f11.size();i++){
        f11[i]=(f11[i]+((f12[i]+f21[i])*C %M) +f22[i]*C*C %M)%M;
    }
    return f11;
}
ll solve(vii dp,int n){
    int sz=dp.size();
    ll s=0,sum=0,count=0;
    ll ans=0;
    for(int i=2;i<sz;i++){
        s=0;
        int k=n-1;
        count =0;
        for(int j=i-2;j>=0;j--){
            s+=max(0,k--);
            count=(count+s*dp[j])%M;
        }
        ans=(ans+count*dp[i])%M;
    }
    return ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m,i,j,k;
    cin>>n>>M;
    if(n<4 || M==1){
        cout<<0<<endl;
        return 0;
    }
    C=sqrt(M);
    //cout<<C<<endl;
    vii dp={1};
    vector<vii> comb(N,vii(N));
    comb[0].assign(N,0);
    for(i=1;i<N;i++){
        comb[i][0]=comb[i][i]=1;
        for(j=1;j<i;j++) comb[i][j]=(comb[i-1][j]+comb[i-1][j-1])%M;
    }
    ll F[N];F[0]=1;for(i=1;i<N;i++) F[i]=F[i-1]*i %M;

    ll ans=0;
    for(i=2;i<=n;i++){
        vii temp(i,1ll);
        ll p=comb[n][i]*F[n-i] %M;
        ll q=solve(dp,i);
        ans=(ans+p*q)%M;
        //cout<<p<<" "<<q<<" "<<ans<<endl;
        dp=__multiply(dp,temp);
        dp.resize(i*(i-1) /2 +1);
        ll t=0;
        //for(auto i: dp) cout<<i<<" ";cout<<endl;
    }
    cout<<ans<<endl;
}

