#include #include #include #include #include #include #include #include #include #include #include using namespace std; struct IoSetupNya { IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7); } } iosetupnya; constexpr long long TEN(int n) { return n ? TEN(n - 1) * 10 : 1; } #include "atcoder/modint.hpp" using mint = atcoder::dynamic_modint<-1>; #define rep(i, N) for (int i = 0; i < (int)(N); i++) struct Mat : vector> { using vector>::vector; static Mat gen(int a, int b) { return Mat(a, vector(b, mint{0})); } friend Mat operator*(Mat a, Mat b) { Mat c = Mat::gen(a.size(), b[0].size()); rep(i, a.size()) rep(k, a[0].size()) rep(j, b[0].size()) { c[i][j] += a[i][k] * b[k][j]; } return c; } }; int main() { int H, W, M; cin >> H >> W >> M; mint::set_mod(M); if (H % 2 != 0) { int ans = W == 1 ? 1 % M : 0; std::cout << ans << "\n"; exit(0); } Mat v = Mat::gen(W, 1); rep(i, W) v[i][0] = 1; Mat a = Mat::gen(W, W); Mat b = a; if (W % 2 == 0) { rep(i, W) rep(j, W) { if (i < j) { if (i % 2 == 0 and j % 2 == 1) a[i][j] = 1; } if (j < i) { if (i % 2 == 1 and j % 2 == 0) a[i][j] = 1; } } } else { rep(i, W) rep(j, W) { if (i % 2 == 0 and j % 2 == 0) { if (i == j and i != 0 and i != W - 1) continue; a[i][j] = 1; } } } rep(i, W) rep(j, W) { if (abs(i - j) <= 1) b[i][j] = 1; } v = a * v; rep(_, H / 2 - 1) { v = a * (b * v); } mint ans = 0; rep(i, W) ans += v[i][0]; cout << ans.val() << "\n"; }