func_code_string: #include <bits/stdc++.h>      #define int long long   using namespace std;      const int MAX = 505;   int n, MOD, fact[MAX], C[MAX][MAX], f[2][MAX * MAX];      int getMaxInv(int x) {       return (x - 1) * x / 2;   }      int32_t main() {   #ifdef ACM       freopen( input ,  r , stdin);   #endif       cin >> n >> MOD;       fact[0] = 1;       for (int i = 1; i <= n; i++)           fact[i] = fact[i - 1] * i % MOD;       C[0][0] = 1;       for (int i = 1; i <= n; i++) {           C[i][0] = C[i][i] = 1;           for (int j = 1; j < n; j++)               C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;       }       int rs = 0;       for (int i = 0; i < n; i++) {           for (int j = 1; j <= getMaxInv(n - 1); j++)               f[i % 2][j] = 0;           f[i % 2][0] = 1;           for (int inv = 1; inv <= getMaxInv(i); inv++) {               int l = inv - min(i, inv + 1) + 1, r = inv;               f[i % 2][inv] = (f[1 - i % 2][r] - (l == 0 ? 0 : f[1 - i % 2][l - 1]) + MOD) % MOD;           }           for (int j = 1; j <= getMaxInv(n - 1); j++)               f[i % 2][j] = (f[i % 2][j] + f[i % 2][j - 1]) % MOD;           for (int inv = 2; inv <= getMaxInv(i); inv++) {               int t1 = (f[i % 2][inv] - f[i % 2][inv - 1] + MOD) % MOD;               for (int t = 1; t <= min(i, inv - 1); t++) {                   int t2 = f[i % 2][inv - t - 1];                   int pickCnt = i - t + 1;                   rs = (rs + t1 * t2 % MOD * pickCnt % MOD * fact[n - i - 1] % MOD * C[n][i + 1]) % MOD;               }           }       }       cout << rs;   }