This is the easy version of the problem. The only difference between the easy version and the hard version is the constraints on n. You can only make hacks if both versions are solved.

A permutation of 1, 2, …, n is a sequence of n integers, where each integer from 1 to n appears exactly once. For example, [2,3,1,4] is a permutation of 1, 2, 3, 4, but [1,4,2,2] isn't because 2 appears twice in it.

Recall that the number of inversions in a permutation a_1, a_2, …, a_n is the number of pairs of indices (i, j) such that i < j and a_i > a_j.

Let p and q be two permutations of 1, 2, …, n. Find the number of permutation pairs (p,q) that satisfy the following conditions:

  * p is lexicographically smaller than q. 
  * the number of inversions in p is greater than the number of inversions in q. 



Print the number of such pairs modulo mod. Note that mod may not be a prime.

Input

The only line contains two integers n and mod (1≤ n≤ 50, 1≤ mod≤ 10^9).

Output

Print one integer, which is the answer modulo mod.

Example

Input


4 403458273


Output


17

Note

The following are all valid pairs (p,q) when n=4.

  * p=[1,3,4,2], q=[2,1,3,4], 
  * p=[1,4,2,3], q=[2,1,3,4], 
  * p=[1,4,3,2], q=[2,1,3,4], 
  * p=[1,4,3,2], q=[2,1,4,3], 
  * p=[1,4,3,2], q=[2,3,1,4], 
  * p=[1,4,3,2], q=[3,1,2,4], 
  * p=[2,3,4,1], q=[3,1,2,4], 
  * p=[2,4,1,3], q=[3,1,2,4], 
  * p=[2,4,3,1], q=[3,1,2,4], 
  * p=[2,4,3,1], q=[3,1,4,2], 
  * p=[2,4,3,1], q=[3,2,1,4], 
  * p=[2,4,3,1], q=[4,1,2,3], 
  * p=[3,2,4,1], q=[4,1,2,3], 
  * p=[3,4,1,2], q=[4,1,2,3], 
  * p=[3,4,2,1], q=[4,1,2,3], 
  * p=[3,4,2,1], q=[4,1,3,2], 
  * p=[3,4,2,1], q=[4,2,1,3]. 
#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+=dp[i-2];
        sum+=s;
        if(i>n){
            sum-=n*dp[i-n-1];
            s-=dp[i-n-1];
            //cout<<dp[i-n-1]<<" ";
        }
        sum=(sum+M)%M;
        count=(count+(n*s %M) -sum+M)%M;
        //cout<<count<<" "<<sum<<endl;
        ans=(ans+(count*dp[i] %M) ) %M;
    }
    //cout<<"\n\n";
    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;
}

