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>
#define	LL long long
using namespace std;

template <typename T> void chkmax(T &x, T y){x = max(x, y);}
template <typename T> void chkmin(T &x, T y){x = min(x, y);}
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

int n,P,f[5005][5005];
#define upd(x) x >= P ? x -= P : 0
int main(){
	int i,j,k; int m;
	read(n),read(P); m=(n-1)/2;
	if (n==1){cout<<1%P<<endl;return 0;}
	for (i = 0; i <= m; ++i) f[0][i] = 1;
	for (i = 1; i <= n; ++i)
	for (j = 1; j <= m; ++j)
	for (k = 0; j * k <= i; ++k) f[i][j] += (LL)f[i-k*j][j-1] * (k+1) % P,upd(f[i][j]);
	if (n%2==1){
		LL ans = 0;
		for (i = 1; i <= n; ++i)
		for (j = 0; j * (m+1) <= n-i; ++j) ans += f[n-i-j*(m+1)][m];
		ans %= P;
		cout << ans << endl;
		return 0;
	}
	LL ans = 0;
	for (i = 1; i <= n; ++i)
	for (j = 0; j * (m+1) <= n-i; ++j) ans += 1ll * f[n-i-j*(m+1)][m] * (j+1) % P;
	ans %= P;
	cout << ans << endl;
	return 0;
}