#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 998244353;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()

int main(){
    ll N,M;
    cin >> N >> M;
    mat A(N,vec(N*N+1,0));
    rep(i,N){
        if(i==0) A.at(i).at(0)=1;
        else{
            rep(j,i*i+1){
                rep(k,i+1){
                    A.at(i).at(j+k)+=A.at(i-1).at(j);
                    A.at(i).at(j+k)%=M;
                }

            }
        }
    }
    vec B(N,0);
    rep(i,N){
        if(i==0){
            B.at(i)=0;
        }else{
            rep(j,i+1){
                if(j==0){
                    B.at(i)+=(i+1)*B.at(i-1);
                    B.at(i)%=M;
                }else{
                    ll a=0,b=0,c=0;
                    rep(k,i*i+1){
                        if(k>j) a+=A.at(i-1).at(k);
                        a%=M;
                    }
                    rep(k,i*i-j){
                        c+=a*A.at(i-1).at(k);
                        c%=M;
                        a+=M-A.at(i-1).at(k+j+1);
                        a%=M;
                    }
                    B.at(i)+=(i+1-j)*c;
                    B.at(i)%=M;
                }
            }
        }
    }
    cout << B.at(N-1) << endl;
}