#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back

int mid = 125000, mid2 = 500;
int dp[2][250005];
int dp2[505][1005], sum2[505][1005];
int C[505];
int main(){
    int n, mod;
    scanf("%d%d", &n, &mod);

    C[0] = 1;
    for(int i=1;i<=n;i++) C[i] = C[i-1]*1ll*(n-i+1)%mod;

    for(int i=1;i<=n;i++){
        int d = i;
        for(int j=1;j<d;j++){
            for(int k=j+1;k<=d;k++){
                dp2[i][(j-1)-(k-1)+mid2] = (dp2[i][(j-1)-(k-1)+mid2] + 1)%mod;
            }
        }

        sum2[i][mid2+mid2] = dp2[i][mid2+mid2];
        for(int j=mid2+mid2-1;j>=0;j--){
            sum2[i][j] = (sum2[i][j+1] + dp2[i][j])%mod;
        }
    }

    ll ans = 0;
    int v = 0;
    dp[0][mid] = 1;
    for(int i=1;i<=n-1;i++){

        ll res = 0, sum = 0;
        for(int j=0;j<=mid+mid;j++){
            res = (res + dp[v][j]*1ll*i)%mod;
            sum = (sum + dp[v][j])%mod;

            dp[v^1][j] = res;

            res = (res - sum + mod)%mod;
            if(j >= i-1) sum = (sum - dp[v][j-(i-1)] + mod)%mod;
        }

        res = 0, sum = 0;
        for(int j=mid+mid;j>=0;j--){
            res = (res + dp[v][j]*1ll*i)%mod;
            sum = (sum + dp[v][j])%mod;

            dp[v^1][j] = (dp[v^1][j] + res)%mod;
            dp[v^1][j] = (dp[v^1][j] - dp[v][j]*1ll*i%mod + mod)%mod;

            res = (res - sum + mod)%mod;
            if(j+i-1 <= mid+mid) sum = (sum - dp[v][j+i-1] + mod)%mod;
        }

        for(int j=0;j<=mid+mid;j++){
            if(j < mid){
                int d = mid2 - (j-mid - 1);
                if(d > mid2+mid2) continue;
                ans = (ans + sum2[i+1][d]*1ll*dp[v^1][j]%mod*C[n-i-1])%mod;
            }
            else{
                int d = mid2 - (j-mid - 1);
                d = max(d, 0);
                ans = (ans + sum2[i+1][d]*1ll*dp[v^1][j]%mod*C[n-i-1])%mod;
            }
        }

        v ^= 1;
    }
    printf("%lld\n", ans);
}