#include #include #include #include #include #include #include using namespace std; const int MAX_V = 2500; int V; bool G[MAX_V][MAX_V]; int match[MAX_V]; bool used[MAX_V]; bool dfs(int v) { used[v] = true; for(int i = 0; i < V; i++) { if(!G[v][i]) continue; int u = i, w = match[u]; if(w < 0 || (!used[w] && dfs(w))) { match[v] = u; match[u] = v; return true; } } return false; } int bipartite_matching() { int res = 0; memset(match, -1, sizeof(match)); for(int v = 0; v < V; v++) { if(match[v] < 0) { memset(used, 0, sizeof(used)); if(dfs(v)) { res++; } } } return res; } int N, M; int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 }; string c[50]; int toV(int x, int y) { return y * M + x; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M; V = N * M; for(int i = 0; i < N; i++) { cin >> c[i]; } int bc = 0, wc = 0; for(int y = 0; y < N; y++) { for(int x = 0; x < M; x++) { if(c[y][x] == '.') continue; if(c[y][x] == 'b') bc++; if(c[y][x] == 'w') wc++; for(int k = 0; k < 4; k++) { int nx = x + dx[k], ny = y + dy[k]; if(0 <= nx && nx < M && 0 <= ny && ny < N && c[ny][nx] != '.') { G[toV(x, y)][toV(nx, ny)] = G[toV(nx, ny)][toV(x, y)] = true; } } } } int m = bipartite_matching(); bc -= m, wc -= m; int ans = m * 100 + min(bc, wc) * 10 + (max(bc, wc) - min(bc, wc)); cout << ans << endl; }