//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#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 LOCAL
~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__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=5007;
ll mod;
ll modk;

int n;

int lew, pra;

int dp1[nax][nax];
int dp2[nax][nax];

ll wyn;

ll stra[nax][nax];
ll zys[nax][nax];

void dod(int &a, int b)
{
	if ((a+=b)>=mod)
		a-=mod;
}

void dod(ll &a, ll b)
{
	if ((a+=b)>=mod)
		a-=mod;
}

void dod2(ll &a, ll b)
{
	//~ a=(a+b)%mod;
	if ((a+=b)>=modk)
		a-=modk;
}

int main()
{
	scanf("%d%lld", &n, &mod);
	modk=mod*mod*5;
	if (n==2)
	{
		printf("3\n");
		return 0;
	}
	int d=0;
	int g=0;
	lew=(n+1)/2;
	pra=lew-1;
	dp1[0][0]=1;
	debug() << "a";
	for (int i=lew-1; i; i--)
	{
		for (int j=0; i*j<=n; j++)
		{
			for (int l=i*j; l+i<=n; l++)
			{
				if ((dp1[j+1][l+i]+=dp1[j][l])>=mod)
					dp1[j+1][l+i]-=mod;
			}
		}
	}
	dp2[0][0]=1;
	debug() << "b";
	for (int i=pra-1; i>0; i--)
	{
		for (int j=0; j<=n; j++)
		{
			for (int l=min(n, i*j); l<=n; l++)
			{
				if ((dp2[j+1][min(l+i, n)]+=dp2[j][l])>=mod)
					dp2[j+1][min(l+i, n)]-=mod;
			}
		}
	}
	debug() << "c";
	for (int i=0; i<=n; i++)
	{
		for (int j=0; j<=n; j++)
		{
			dod(stra[i][j], dp1[i][j]);
			dod(stra[i+1][j], stra[i][j]);
		}
	}
	debug() << "d";
	for (int i=0; i<n; i++)
	{
		for (int j=0; j<=n; j++)
		{
			dod(zys[n-1-i][j], dp2[i][j]);
		}
	}
	debug() << "e";
	for (int i=n-1; i; i--)
	{
		for (int j=0; j<=n; j++)
		{
			dod(zys[i-1][j], zys[i][j]);
		}
	}
	int sr=(!(n&1));
	for (int i=0; i<n; i++)
	{
		for (int j=i; j<n; j++)
		{
			int mno=(j-i+1);
			if (!sr)
				mno=1;
			int juz=lew*i-pra*j;
			if (juz<0)
				break;
			ll sum=0;
			int najw=-1;
			int kt=0;
			for (int l=max(min(n, juz), 0); l>=0; l--)
			{
				//~ while(juz-l-(najw+1)>=0 && najw<n)
				//~ {
					//~ najw++;
					//~ dod(sum, zys[j][najw]);
				//~ }
				dod(sum, zys[j][kt]);
				kt++;
				dod2(wyn, stra[i][l]*sum*mno);
			}
		}
	}
	printf("%lld\n", wyn%mod);
	return 0;
}


Measured memory_bytes: 586368