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;
 
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")

#define mp make_pair
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define eb emplace_back
 
// https://codeforces.com/blog/entry/67830
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef BLAT
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef vector< pii > vpii;
typedef vector< vpii > vvpii;
typedef vector< pll > vpll;
typedef long double ld;
typedef vector< ld > vld;
typedef unsigned int uint;

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    const bool operator<(const M& o) const {return v < o.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
 
int main() { 
    #ifdef BLAT
        freopen("stdin", "r", stdin);
        freopen("stderr", "w", stderr);
    #endif
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, mod;
    cin >> n >> mod;

    if(mod == 1) {
      cout << 0 << '\n';
      return 0;
    }

    vector< vector< int > > permWithInversion(n + 1, vector< int > (n*n  + 1));

    permWithInversion[0][0] = 1;

    for(int i = 1; i <= n; ++i) {
      for(int j = 0; j <= i*i; ++j) {
        // elem curent imi poate adauga intre 0 si i-1 inv
        for(int k = 0; k <= j && k < i; ++k) {
          permWithInversion[i][j] += permWithInversion[i-1][j-k];
          if(permWithInversion[i][j] >= mod) permWithInversion[i][j] -= mod;
        }
      }
    }

    // for(int i = 0; i <= 4; ++i) {
    //   cout << permWithInversion[3][i] << ' ';
    // }

    // cout << '\n';

    // cout << permWithInversion[4][2] << '\n';
    // return 0;
    vector< vector< int > > choose(n + 1, vector< int > (n + 1));

    for(int i = 0; i <= n; ++i) {
      choose[i][0] = 1;
      for(int j = 1; j <= i; ++j) {
        choose[i][j] = choose[i-1][j] + choose[i-1][j-1];
        if(choose[i][j] >= mod) choose[i][j] -= mod;
      }
    }

    vector< int > fact(n + 1);
    fact[0] = 1;
    for(int i = 1; i <= n; ++i) {
      fact[i] = 1ll*fact[i-1]*i%mod;
    }
    int ans = 0;
    for(int prefix = 0; prefix <= n - 4; ++prefix) {
      int suffix = n - prefix - 1;
      int options = suffix + 1;

      vector< int > cnt(suffix*suffix + 2, 0); // in cate permutari prima are cu i mai multe ca a doua      
      for(int p = 0; p <= suffix*suffix; ++p) {
        for(int q = 0; q <= p; ++q) {
          cnt[p-q] += 1ll*permWithInversion[suffix][p] * permWithInversion[suffix][q] % mod;
          if(cnt[p-q] >= mod) cnt[p-q] -= mod; 

          // cout << p << ' ' << q << ' ' << cnt[p-q] << '\n';
        }
      }

      for(int i = suffix*suffix; ~i; --i) {
        cnt[i] += cnt[i+1];
        if(cnt[i] >= mod) cnt[i] -= mod;
      }

      int total = 0;

      for(int i = 1; i <= options; ++i) {
        for(int j = i + 1; j <= options; ++j) {
          // cout << i << ' ' << j << ' ' << cnt[j-i+1] << '\n';
          total += cnt[j-i+1];
          if(total >= mod) total -= mod;
        }
      }

      ans += 1ll*total*choose[n][prefix]%mod*fact[prefix]%mod;
      if(ans >= mod) ans -= mod;
    }

    cout << ans << '\n';

    #ifdef BLAT
        cerr << "\n\nConsumed " << clock() / (double)CLOCKS_PER_SEC << '\n';
    #endif
    return 0; 
}