#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define ff first
#define ss second
#define pi pair<int,int>
#define INF 1e18
#define db double 
#define vec vector<ll>
#define test cout<<" test_rounds\n"
#define ull unsigned long long int 
#define cntone(n)  __builtin_popcount(n)
#define fastio  ios_base::sync_with_stdio(false),cin.tie(NULL)
#define pai acos(-1.0)
#define dbl long double
#define mk make_pair(ll,ll)
#define mem(a,b) memset(a,b,sizeof(a))
#define sz(s) int(s.size())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
 
 const int mod=1000000007;

 
 ll dp1[52][2505];
 ll dp2[52][2505];
 ll pre[52][2505];
 int n;
 ll m;

ll go1(int i,ll sum)
{          
            if(sum==0ll)
            return 1ll;
           

           if(i<=0)return 0ll;

           if(dp1[i][sum]!=-1)return dp1[i][sum];
           ll x=0;
            
           for(int j=0;j<=i-1;j++){
                
               if(sum-j>=0)
               x+=go1(i-1,sum-j);
               x%=m;
           }
           return dp1[i][sum]=x;
}

ll go2(int i,ll sum)
{
            
            if(sum==0ll)return 1ll;
            if(i>n)return 0ll;

            if(dp2[i][sum]!=-1)return dp2[i][sum];
            ll x=0;
            
           for(int j=0;j<=i-1;j++)
           {
               if(sum-j>=0)
               x+=go2(i+1,sum-j);
               x%=m;
                
           }
           return dp2[i][sum]=x;
}



  int main(){
            
            // ignore my comments// i just talking to myself;
        
             cin>>n>>m;
             for(int i=1;i<=n;i++)
             {

                   for(int j=1;j<=n*(n+1)/2;j++)
                          dp1[i][j]=-1ll,dp2[i][j]=-1ll,pre[i][j]=0ll;

                    dp1[i][0]=dp2[i][0]=1;
             }

             for(int i=0ll;i<=n*(n+1)/2;i++)
             {

                  dp1[n][i]=go1(n,i);
                  dp2[1][i]=go2(1,i);
             }


            ll x=1ll;
            ll ans=0ll;
            ll N=n*(n-1)/2;

             
            //pre_cal_calculate how many ways there can be when i can make bigger the p than q;


            for(int i=1;i<=n;i++)
            {     
                  ll x=0ll;
                  for(int j=0;j<=N;j++)
                  {             
                               x+=dp1[i][j];
                               x%=m;
                               pre[i][j]=x;

                  }

            }
        
            for(int i=n;i>=2;i--)
            {
                 
                 ll y;
                for(int j=1;j<=i-1;j++)
                {     

                          for(int k=0;k<j;k++)
                          {
                                  int dif=j-k;
                                  int hi=(i-2)*(i-1)/2;
                                  for(int kk=0;kk<=hi;kk++)
                                  {

                                          int pp=dif+kk;
                                          ll yy=dp1[i-1][kk];

                                          y=(pre[i-1][N]-pre[i-1][pp]+m)%m;
                                          y*=yy;
                                          y%=m;
                                          ans=(ans+x*y%m)%m;
                                  } 
                          }
                          
                        
                   }

                  x=0ll;
                 
                  for(int j=0;j<=N;j++)
                  {
                     x+=dp2[i][j];
                     x%=m;
                  }

            }
            cout<<ans%m<<"\n";
  }

