#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define int long long typedef vector VI; typedef pair pii; typedef vector VP; typedef vector VS; typedef priority_queue PQ; templatebool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define fore(i,a) for(auto &i:a) #define REP(i,n) for(int i=0;i, greater > q2; VI G[5000]; int match[5010]; bool used[5010]; int N; bool dfs(int v) { used[v] = true; REP(i, G[v].size()) { int u = G[v][i], w = match[u]; if (w < 0 || (!used[w] && dfs(w))) { match[v] = u; match[u] = v; return true; } } return false; } int solve() { int res = 0; memset(match, -1, sizeof(match)); REP(v, N) { if (match[v] < 0) { memset(used, 0, sizeof(used)); if (dfs(v))res++; } } return res; } signed main() { cin.tie(0); ios::sync_with_stdio(false); int H, W; cin >> H >> W; VS S(H); REP(i, H)cin >> S[i]; N = H * W; mapmp; int w = 0, b = 0; int k = 0; REP(i, H)REP(j, W)mp[pii(i,j)] = k++; int dx[] = { 0,0,-1,1 }; int dy[] = { -1,1,0,0 }; REP(i, H) { REP(j, W) { if (S[i][j] == 'w')w++; if (S[i][j] == 'b')b++; REP(k, 4) { int nx = i + dx[k], ny = j + dy[k]; if (nx >= 0 && nx < H&&ny >= 0 && ny < W) { if (S[i][j] != S[nx][ny] && S[i][j] != '.' && S[nx][ny] != '.') { G[mp[pii(i, j)]].push_back(mp[pii(nx, ny)]); } } } } } int ans = solve() * 100; w -= ans / 100; b -= ans / 100; ans += min(w, b) * 10; ans += abs(w - b); cout << ans << endl; return 0; }