#include #include #include #include using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i void chmin(A& l, const A& r){ if(r < l) l = r; } template void chmax(A& l, const A& r){ if(l < r) l = r; } using namespace std; #include namespace nachia{ template class Comb{ private: std::vector F; std::vector iF; public: void extend(int newN){ int prevN = (int)F.size() - 1; if(prevN >= newN) return; F.resize(newN+1); iF.resize(newN+1); for(int i=prevN+1; i<=newN; i++) F[i] = F[i-1] * Modint::raw(i); iF[newN] = F[newN].inv(); for(int i=newN; i>prevN; i--) iF[i-1] = iF[i] * Modint::raw(i); } Comb(int n = 1){ F.assign(2, Modint(1)); iF.assign(2, Modint(1)); extend(n); } Modint factorial(int n) const { return F[n]; } Modint invFactorial(int n) const { return iF[n]; } Modint invOf(int n) const { return iF[n] * F[n-1]; } Modint comb(int n, int r) const { if(n < 0 || n < r || r < 0) return Modint(0); return F[n] * iF[r] * iF[n-r]; } Modint invComb(int n, int r) const { if(n < 0 || n < r || r < 0) return Modint(0); return iF[n] * F[r] * F[n-r]; } Modint perm(int n, int r) const { if(n < 0 || n < r || r < 0) return Modint(0); return F[n] * iF[n-r]; } Modint invPerm(int n, int r) const { if(n < 0 || n < r || r < 0) return Modint(0); return iF[n] * F[n-r]; } Modint operator()(int n, int r) const { return comb(n,r); } }; } // namespace nachia namespace nachia{ int Popcount(unsigned long long c) noexcept { #ifdef __GNUC__ return __builtin_popcountll(c); #else c = (c & (~0ull/3)) + ((c >> 1) & (~0ull/3)); c = (c & (~0ull/5)) + ((c >> 2) & (~0ull/5)); c = (c & (~0ull/17)) + ((c >> 4) & (~0ull/17)); c = (c * (~0ull/257)) >> 56; return c; #endif } // please ensure x != 0 int MsbIndex(unsigned long long x) noexcept { #ifdef __GNUC__ return 63 - __builtin_clzll(x); #else using u64 = unsigned long long; int q = (x >> 32) ? 32 : 0; auto m = x >> q; constexpr u64 hi = 0x88888888; constexpr u64 mi = 0x11111111; m = (((m | ~(hi - (m & ~hi))) & hi) * mi) >> 35; m = (((m | ~(hi - (x & ~hi))) & hi) * mi) >> 31; q += (m & 0xf) << 2; q += 0x3333333322221100 >> (((x >> q) & 0xf) << 2) & 0xf; return q; #endif } // please ensure x != 0 int LsbIndex(unsigned long long x) noexcept { #ifdef __GNUC__ return __builtin_ctzll(x); #else return MsbIndex(x & -x); #endif } } using Modint = atcoder::modint; void testcase(){ i64 H, W; cin >> H >> W; i64 K, M; cin >> K >> M; Modint::set_mod(M); vector adj(H*W); auto Idx = [&](i64 y, i64 x) -> i64 { return y * W + x; }; auto IdxBit = [&](i64 y, i64 x) -> i64 { return i64(1) << Idx(y,x); }; rep(y,H) rep(x,W-1) adj[Idx(y,x)] |= IdxBit(y,x+1); rep(y,H) rep(x,W-1) adj[Idx(y,x+1)] |= IdxBit(y,x); rep(y,H-1) rep(x,W) adj[Idx(y,x)] |= IdxBit(y+1,x); rep(y,H-1) rep(x,W) adj[Idx(y+1,x)] |= IdxBit(y,x); i64 N = H*W; auto comb = nachia::Comb(N+1); vector ipow2(N+1, 1); rep(i,N) ipow2[i+1] = ipow2[i] / 2; vector> F(N+1, vector(N+1)); rep(i,N+1) rep(j,N+1) if(i+j <= N){ Modint t1 = Modint(i).pow(K); //int k = N - i - j; //for(i64 f=0; f<=k; f++){ // 非隣接で塗る個数 // Modint t2 = t1 * comb(k, f); // for(i64 e=0; e<=j; e++){ // 隣接で塗る個数 // Modint t3 = t2 * comb(j,e) * comb.invOf((k-f)+(j-e)+1); // t3 *= comb.invComb(N, i+e+f) * ipow2[i+e]; // F[i][j] += t3; // } //} F[i][j] += t1 * ipow2[i+j]; } Modint ans = 0; vector vis(1<<(N)); vector bfs; rep(y,H) rep(x,W) bfs.push_back(IdxBit(y,x)); for(i64 v : bfs) vis[v] = 1; rep(i,bfs.size()){ i64 v = bfs[i]; i64 w = 0; rep(j,N) if((v>>j)&1) w |= adj[j]; w -= v & w; int pcv = nachia::Popcount(v); int pcw = nachia::Popcount(w); //cout << "pcv = " << pcv << " , pcw = " << pcw << endl; ans += F[pcv][pcw]; rep(j,N) if((w>>j)&1){ i64 nx = v | i64(1) << j; if(vis[nx]) continue; vis[nx] = 1; bfs.push_back(nx); } } Modint t = 0; for(int i=1; i<=N; i++) t += comb.invOf(i); ans *= t; cout << ans.val() << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); testcase(); return 0; }