func_code_string: #include<bits/stdc++.h>      using namespace std;      #define task  sol    #define lb lower_bound   #define ub upper_bound   #define fi first   #define se second   #define pb push_back   #define mp make_pair   #define zs(v) ((int)(v).size())   #define BIT(x, i) (((x) >> (i)) & 1)   #define CNTBIT __builtin_popcountll   #define ALL(v) (v).begin(),(v).end()   #define endl   n       typedef long double ld;   typedef long long ll;   typedef pair<int, int> pii;      const ll base=331;   const int dx[8]={0,-1,0,1,1,-1,-1,1};   const int dy[8]={-1,0,1,0,-1,-1,1,1};      int c[55][55];   int mod;   ll dp[55][55*55];   ll fact[55];   int f[4005];   int n;         void gogo()   {       cin>>n>>mod;          dp[0][0]=1;       for (int i=1;i<=n;++i)       {           for (int num=0;num<=n*n;++num)           {               for (int k=1;k<=i;++k)                   if (num+i-k<=n*n) (dp[i][num+i-k]+=dp[i-1][num])%=mod;           }       }          for (int i=0;i<=n;++i)       {           c[i][0]=1;           for (int j=1;j<=i;++j)               c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;       }       fact[0]=1;       for (int i=1;i<=n;++i) fact[i]=fact[i-1]*i%mod;             int ans=0;       for (int i=0;i<n;++i)       {           ll val=c[n][i]*fact[i]%mod;           int len=n-i-1;           int m=len*(len-1)/2;              for (int i=0;i<=m;++i) f[i]=0;           for (int inv1=0;inv1<=m;++inv1)           {               for (int inv2=0;inv2<=inv1;++inv2)               {                   (f[inv1-inv2]+=dp[len][inv1]*dp[len][inv2]%mod)%=mod;               }           }           for (int i=1;i<=m;++i) (f[i]+=f[i-1])%=mod;           int value=0;           for (int x=1;x<=len+1;++x)           {               for (int y=x+1;y<=len+1;++y)               {                   assert(y-x>=0);                   if (m>y-x)                       (value+=(f[m]-f[y-x]+mod)%mod)%=mod;               }           }   //        cout<<value<<endl;           ans=(ans+val*value%mod)%mod;       }       cout<<ans;   }   int main()   {       ios_base::sync_with_stdio(0); cin.tie(0);       if (fopen(task .inp ,  r ))       {           freopen(task .inp ,  r , stdin);           freopen(task .out ,  w , stdout);       }       gogo();   }                     