#include #define int long long #define endl '\n' #define FOR(i, a, n) for (int i = (a); i < (n); ++i) #define REP(i, n) FOR(i, 0, n) using namespace std; class BipartiteMatching { bool dfs(int v) { used[v] = timestamp; for (auto& u : g[v]) { int w = match[u]; if (!alive[u]) continue; if (w < 0 || (used[w] != timestamp && dfs(w))) { match[v] = u; match[u] = v; return true; } } return false; } public: vector> g; vector match, alive, used; int timestamp; BipartiteMatching(int n) : g(n), match(n, -1), alive(n, 1), used(n, 0), timestamp(0) {} void add_edge(int u, int v) { g[u].push_back(v); g[v].push_back(u); } int bipartite_matching() { int res = 0; for (int i = 0; i < g.size(); ++i) { if (!alive[i] || ~match[i]) continue; ++timestamp; res += dfs(i); } return res; } void print() { for (int i = 0; i < g.size(); ++i) { if (i < match[i]) { cout << i << " - " << match[i] << endl; } } } }; const int dy[] = {-1, 0, 0, 1}; const int dx[] = {0, -1, 1, 0}; int N, M; string S[50]; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> M; REP (i, N) cin >> S[i]; BipartiteMatching g(N * M); REP (i, N) REP (j, M) if ((i + j) % 2 == 0 && S[i][j] != '.') { REP (k, 4) { int ny = i + dy[k]; int nx = j + dx[k]; if (ny >= 0 && ny < N && nx >= 0 && nx < M && S[ny][nx] != '.') { g.add_edge(i * M + j, ny * M + nx); } } } int w = 0, b = 0; REP (i, N) REP (j, M) { w += (S[i][j] == 'w'); b += (S[i][j] == 'b'); } int num = g.bipartite_matching(); w -= num, b -= num; cout << 100 * num + 10 * min(w, b) + max(w, b) - min(w, b) << endl; }