#include #include #include using namespace std; using namespace atcoder; using mint = modint; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001LL bool f[1<<25]; mint powK[27]; mint combi[27][27]; mint ans; int H,W; void dfs(int bit){ if(f[bit])return; f[bit] = true; int ok = H*W; rep(i,H*W){ if((bit>>i)&1){ ok --; continue; } bool tf = true; if(i-W>=0 && ((bit>>(i-W))&1)){ dfs(bit|(1<>(i+W))&1)){ dfs(bit|(1<>(i-1))&1)){ dfs(bit|(1<>(i+1))&1)){ dfs(bit|(1<>H>>W>>K>>M; mint::set_mod(M); rep(i,H*W+1)powK[i] = mint(i).pow(K); combi[0][0] = 1; for(int i=1;i<=26;i++){ for(int j=0;j<=i;j++){ combi[i][j] += combi[i-1][j]; if(j!=0)combi[i][j] += combi[i-1][j-1]; } } rep(i,H*W){ dfs(1<