#include int main() { using namespace std; unsigned H, W; cin >> H >> W; enum class state { plus, minus, stop }; vector field(H, vector(W)); for (auto &row : field) for (auto &cell : row) { char c; cin >> c; cell = c == 'o' ? state::plus : c == 'x' ? state::minus : state::stop; } unsigned possible_roots{}; for (unsigned i{}; i < (1U << H - 1) << (W - 1); ++i) if (popcount(i) == H - 1) possible_roots += [&]() -> int { unsigned now_jewels{}, x{}, y{}; for (unsigned j{}; j < H + W - 2; ++j) { if (field[x][y] == state::plus) ++now_jewels; if (field[x][y] == state::minus) { if (now_jewels == 0) return 0; --now_jewels; } if (field[x][y] == state::stop) return 0; ++(i >> j & 1 ? x : y); } if (field.back().back() == state::plus) return 1; return now_jewels != 0; }(); cout << possible_roots << '\n'; return 0; }