#include #include #include using namespace std; int H, W; const int64_t MOD = 1000000007; int64_t solve(vector map) { int64_t ret = 1; vector t1(map.size(), true), t2(map.size(), true); for(size_t i = 0; i < map.size(); i++) { for(size_t j = 0; j < map[i].size(); j++) { if(map[i][j] == '?') continue; if(map[i][j] == static_cast((j) % 2 + '0')) t1[i] = false; if(map[i][j] == static_cast((j + 1) % 2 + '0')) t2[i] = false; } ret = (ret * ((t1[i] ? 1 : 0) + (t2[i] ? 1 : 0))) % MOD; } return ret; } int64_t solve2(vector map) { bool c1 = true, c2 = true; for(size_t i = 0; i < map.size(); i++) { for(size_t j = 0; j < map[i].size(); j++) { if(map[i][j] == '?') continue; if(map[i][j] == static_cast((i + j) % 2 + '0')) c1 = false; if(map[i][j] == static_cast((i + j + 1) % 2 + '0')) c2 = false; } } return (c1 ? 1 : 0) + (c2 ? 1 : 0); } int main() { cin >> H >> W; vector map(H); for(string &s: map) cin >> s; vector map2(W); for(int i = 0; i < W; i++) { string t; for(int j = 0; j < H; j++) { t += map[j][i]; } map2[i] = t; } int64_t answer = solve(map) + solve(map2) - solve2(map); answer %= MOD; if(answer < 0) answer += MOD; cout << answer << endl; }