Problem:
Score : 1600 points

Problem Statement

There is a blackboard on which all integers from -10^{18} through 10^{18} are written, each of them appearing once. Takahashi will repeat the following sequence of operations any number of times he likes, possibly zero:

Choose an integer between 1 and N (inclusive) that is written on the blackboard. Let x be the chosen integer, and erase x.

If x-2 is not written on the blackboard, write x-2 on the blackboard.

If x+K is not written on the blackboard, write x+K on the blackboard.

Find the number of possible sets of integers written on the blackboard after some number of operations, modulo M.
We consider two sets different when there exists an integer contained in only one of the sets.

Constraints

1 \leq K\leq N \leq 150

10^8\leq M\leq 10^9

N, K, and M are integers.

Input

Input is given from Standard Input in the following format:

N K M

Output

Print the number of possible sets of integers written on the blackboard after some number of operations, modulo M.

Sample Input 1

3 1 998244353

Sample Output 1

7

Every set containing all integers less than 1, all integers greater than 3, and at least one of the three integers 1, 2, and 3 satisfies the condition. There are seven such sets.

Sample Input 2

6 3 998244353

Sample Output 2

61

Sample Input 3

9 4 702443618

Sample Output 3

312

Sample Input 4

17 7 208992811

Sample Output 4

128832

Sample Input 5

123 45 678901234

Sample Output 5

256109226

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include<cstdio>
#include<iostream>
#define RI register int
#define CI const int&
using namespace std;
const int N=150;
int n,k,mod;
inline void inc(int& x,CI y)
{
	if ((x+=y)>=mod) x-=mod;
}
namespace Case1 //Even number solver
{
	int f[N][N];
	inline int calc(CI n,CI k)
	{
		RI i,j; for (f[0][0]=i=1;i<=n;++i) for (f[i][0]=f[i-1][0],j=1;j<=k;++j)
		inc(f[i][0],f[i-1][j]),f[i][j]=f[i-1][j-1];
		int ret=0; for (i=0;i<=k;++i) inc(ret,f[n][i]); return ret;
	}
	inline void solve(void)
	{
		printf("%d",1LL*calc(n>>1,k>>1)*calc(n-(n>>1),k>>1)%mod);
	}
};
namespace Case2 //Odd number solver
{
	int f[N][N][N],ans;
	inline void solve(void)
	{
		RI i,j,p; for (f[0][0][0]=i=1;i<=n;++i)
		{
			int r=i<<1,l=r-k,fl=1<=l&&l<=n,fr=1<=r&&r<=n;
			for (j=0;j<=n;++j) for (p=0;p<=k+1;++p)
			{
				inc(f[i][0][0],f[i-1][j][p]); if (fr) inc(f[i][j+1][0],f[i-1][j][p]);
				if (fl&&p+1<k+2) inc(f[i][0][p?p+1:p],f[i-1][j][p]);
				if (fl&&fr&&max(j+2,p+1)<k+2) inc(f[i][j+1][max(j+2,p+1)],f[i-1][j][p]);
			}
		}
		for (i=0;i<=n;++i) for (j=0;j<=k+1;++j)
		inc(ans,f[n][i][j]); printf("%d",ans);
	}
};
int main()
{
	scanf("%d%d%d",&n,&k,&mod); if (k&1) Case2::solve();
	else Case1::solve(); return 0;
}