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]. 
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std::chrono;    

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long 
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(v) (v).begin(), (v).end()
// #define mod 1000000007  
#define mod2 998244353
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)

int fexp(int a, int b,int m){int ans = 1;while(b){if(b&1)ans=(ans*a)%m; b/=2;a=(a*a)%m;}return ans;}
int inverse(int a, int p){return fexp(a, p-2,p);} 

// int fac[2000001];

// int nCrModPFermat(int n, int r,int p) { 
//     // cout<<1<<endl;
//     if (r==0) return 1; 
//     return (((fac[n]*((((inverse(fac[r],p)%p)*inverse(fac[n-r],p))%p))))%p); 
// }
// vi prime(112345,1);
// vi allprime;
// vi spf(10000001,1);
// vi factors[512345];


void solve(){
    int n,mod;cin>>n>>mod;
    vector<int> inversion2(n*n+5,0);
    inversion2[0]=1;
    int ans = 0;
    for(int i=2;i<=n;i++){
        vector<int> sum = inversion2;
        vector<int> prev = inversion2;

        int temp = ans;
        for(int k=n*n-1;k>=0;k--)
            sum[k]=(sum[k]+sum[k+1])%mod;
        for(int j=2;j<=i;j++){
            vector<int> inversion(n*n+5,0);
            for(int k=0;k+j-1<=n*n;k++){
                inversion[k+j-1]=(prev[k]);
            }            
            for(int k=0;k<n*n-1;k++)
                ans=(ans+((inversion[k]*sum[k+1])%mod))%mod;
            
            for(int k=n*n;k>=0;k--){
                inversion2[k]=(inversion2[k]+inversion[k])%mod;
                //sum[k]=(sum[k]+inversion[k]);
            }
            sum = inversion2;
            for(int k=n*n-1;k>=0;k--)
                sum[k]=(sum[k]+sum[k+1])%mod;
            // cout<<ans<<" ";
        }
        ans=(ans+((temp*(i-1))%mod))%mod;
    }
    ans%=mod;
    if(ans<0)ans+=mod;
    cout<<ans;
    
}
         
signed main(){
        IOS;    
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r" , stdin);
        freopen("output.txt", "w", stdout);
        #endif
        auto start = high_resolution_clock::now();
        int t=1; 
        // cin>>t;
        // spf[1]=0;
        // for(int i=2; i<=100005; i++){
        // if(spf[i]==1)
        // {
        //     // allprime.pb(i);
        //     for(int j=i+i; j<=100005; j+=i){
        //         // factors[j].pb(i);
        //         if(spf[j]==1)spf[j]=0;
        //     }
        // }
        //     spf[i]+=spf[i-1];
        // }
        // fac[0] = 1; 
        // for (int i=1 ; i<=200001; i++) fac[i] = fac[i-1]*i%mod; 

        rep(i,0,t){
            // cout<<"Case #"<<i+1<<": ";
            solve();
            cout<<"\n";
        }
        auto stop = high_resolution_clock::now();
        auto duration = duration_cast<microseconds>(stop - start);
        cerr<<"Time taken:"<<duration.count()/1000000.0<<"seconds"<<"\n";
    //    return 0;
}