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: Accepted)

#include<bits/stdc++.h>

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int maxn = 155;

class State{
public:
	int s0, s1, mx0, mx1;
	State(int _s0, int _s1, int _mx0, int _mx1): s0(_s0), s1(_s1), mx0(_mx0), mx1(_mx1){}
	bool operator < (const State &o)const{return MP(MP(s0, s1), MP(mx0, mx1)) < MP(MP(o.s0, o.s1), MP(o.mx0, o.mx1));}
};

int n, k, INF;
int f[maxn][maxn];
map<State, int> g[maxn];

inline void uadd(int &x, int y){
	(x += y) %= INF;
	return;
}

inline int mul(int x, int y){
	return 1ll * x * y % INF;
}

inline int solve(int _n, int _k){
	memset(f, 0, sizeof(f));
	f[0][0] = 1;
	FOR(i, 0, _n) REP(j, 0, _k){
		if(j != _k)
			uadd(f[i + 1][j + 1], f[i][j]);
		uadd(f[i + 1][0], f[i][j]);
	}
	int ret = 0;
	//printf("_n = %d _k = %d %d\n", _n, _k, f[_n][_k]);
	REP(i, 0, _k)
		uadd(ret, f[_n][i]);
	return ret;
}

inline int dfs(int pos, int s0, int s1, int mx0, int mx1){
	if(pos == n)
		return (mx0 == n && mx1 == n);
	if(mx0 < pos || mx1 < pos)
		return 0;
	s0 = min(s0, (k >> 1) + 1);
	s1 = min(s1, (k >> 1) + 1);
	State cur = State(s0, s1, mx0, mx1);
	if(g[pos].find(cur) != g[pos].end())
		return g[pos][cur];
	int mx0_ = n, mx1_ = n;
	if(pos % 2 == 0 && s1 * 2 - 1 >= k)
		mx1_ = pos + k - min(k / 2, s0) * 2;
	if(pos % 2 == 1 && s0 * 2 - 1 >= k)
		mx0_ = pos + k - min(k / 2, s1) * 2;
	int s0_ = s0 + (!(pos % 2)), s1_ = s1 + (pos % 2);
	int &ret = g[pos][cur];
	ret = 0;
	uadd(ret, dfs(pos + 1, s0_, s1_, min(mx0, mx0_), min(mx1, mx1_)));
	s0_ = (pos % 2) ? s0 : 0;
	s1_ = (pos % 2) ? 0 : s1;
	uadd(ret, dfs(pos + 1, s0_, s1_, (pos % 2 ? mx0 : n), (pos % 2 ? n : mx1)));
	return ret;
}

int main(){
	scanf("%d%d%d", &n, &k, &INF);
	if(!(k % 2)){
		printf("%d\n", mul(solve(n / 2, k / 2), solve(n - n / 2, k / 2)));
		return 0;
	}
	if(k == 1){
		printf("%d\n", solve(n, 2));
		return 0;
	}
	printf("%d\n", dfs(0, 0, 0, n, n));
	return 0;
}