Problem:
Score : 1200 points

Problem Statement

N problems have been chosen by the judges, now it's time to assign scores to them!

Problem i must get an integer score A_i between 1 and N, inclusive.
The problems have already been sorted by difficulty: A_1 \le A_2 \le \ldots \le A_N must hold.
Different problems can have the same score, though.

Being an ICPC fan, you want contestants who solve more problems to be ranked higher.
That's why, for any k (1 \le k \le N-1), you want the sum of scores of any k problems to be strictly less than the sum of scores of any k+1 problems.

How many ways to assign scores do you have? Find this number modulo the given prime M.

Constraints

2 \leq N \leq 5000

9 \times 10^8 < M < 10^9

M is a prime.

All input values are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of ways to assign scores to the problems, modulo M.

Sample Input 1

2 998244353

Sample Output 1

3

The possible assignments are (1, 1), (1, 2), (2, 2).

Sample Input 2

3 998244353

Sample Output 2

7

The possible assignments are (1, 1, 1), (1, 2, 2), (1, 3, 3), (2, 2, 2), (2, 2, 3), (2, 3, 3), (3, 3, 3).

Sample Input 3

6 966666661

Sample Output 3

66

Sample Input 4

96 925309799

Sample Output 4

83779

Solution in C++14 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define int ll
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
#define x first
#define y second
#define pb push_back
#define sz(x) int(x.size())

int MOD = 1;

struct mi {
	int value;
	mi(ll x = 0) : 
		value(int(x % MOD)) {}
};
mi operator+(mi a, mi b) {
	return (a.value + b.value) % MOD;
}
void operator+=(mi &a, mi b) {
	a = a + b;
}
mi operator-(mi a, mi b) {
	return (a.value + MOD - b.value) % MOD;
}
void operator-=(mi &a, mi b) {
	a = a - b;
}
mi operator*(mi a, mi b) {
	return (ll)a.value * b.value % MOD;
}
void operator*=(mi &a, mi b) {
	a = a * b;
};
mi powmod(mi a, int p) {
	mi x = 1;
	for (; p > 0; p >>= 1) {
		if (p & 1) {
			x *= a;
		}
		a *= a;
	}
	return x;
}
mi inv(mi a) {
	return powmod(a, MOD - 2);
}
mi operator/(mi a, mi b) {
	return a * inv(b);
}
void operator/=(mi &a, mi b) {
	a = a / b;
}
ostream &operator<<(ostream &out, mi a) {
	return out << a.value;
}

const int N = 5002;
int n;
int c[N];
mi dp[N][N];

signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> MOD;
	int h = (n - 1) / 2;
	for (int i = 0; i < h; ++i) {
		int l = i + 1;
		int r = n - i - 1;
		for (int j = l + 1; j <= r; ++j) {
			c[j] += 1;
		}
	}
	for (int j = 1; j < n; ++j) {
		++c[j];
	}

	//for (int i = 0; i < n; ++i) {
	//	cerr << c[i] << " ";
	//}
	//cerr << endl;

	dp[1][0] = 1;
	for (int i = 1; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			for (int k = 0; j + c[i] * k < n; ++k) {
				dp[i + 1][j + c[i] * k] += dp[i][j];
			}
		}
	}
	
	mi answer = 0;
	for (int j = 0; j < n; ++j) {
		answer += (n - j) * dp[n][j];
	}
	cout << answer << "\n";
	return 0;
}