#include <cstdio>

using namespace std;
int n,mod,i,j,k,h,pos[54][54];
long long nr[54][2504],sol[54],s[2504];
int main()
{
    scanf ("%d %d", &n, &mod);
    for (j=1;j<=n;j++)
        for (i=0;i<=(n*(n+1)/2);i++)
            nr[j][i]=0LL;
    nr[1][0]=1;
    for (i=1;i<=n;i++)
    {
        for (j=1;j<i;j++)
            pos[i][j]=0;
        for (j=1;j<i;j++)
            for (k=(j+1);k<=i;k++)
            {
                for (h=(k-j+1);h<i;h++)
                    pos[i][h]++;
            }
    }
    sol[1]=0LL;
    for (i=2;i<=n;i++)
    {
        sol[i]=(1LL)*sol[i-1]*i%mod;
        s[0]=nr[i-1][0];
        for (j=1;j<=(i*(i+1)/2);j++)
            s[j]=(1LL)*(s[j-1]+nr[i-1][j])%mod;
        for (j=0;j<=(i*(i-1)/2);j++)
        {
            for (k=2;(k<i) && ((j-k)>=0);k++)
            {
                sol[i]=(0LL)+sol[i]+(1LL)*nr[i-1][j]*nr[i-1][j-k]%mod*pos[i][k]%mod;
                sol[i]=(1LL)*sol[i]%mod;
            }
            if (j>=i)
            {
                sol[i]=(0LL)+sol[i]+(1LL)*nr[i-1][j]*s[j-i]%mod*i*(i-1)/2%mod;
                sol[i]=(1LL)*sol[i]%mod;
            }
        }
        for (j=0;j<=(i*(i+1)/2);j++)
        {
            if (j<=(i-1))
                nr[i][j]=(0LL)+s[j];
            else
            {
                nr[i][j]=(0LL)+s[j]-s[j-i];
                if (nr[i][j]<0)
                    nr[i][j]=(0LL)+nr[i][j]+mod;
            }
        }
    }
    printf ("%I64d\n", sol[n]);
    return 0;
}
