#include using namespace std; // #define NDEBUG #include #define MAX 50 int N, M; char S[MAX][MAX]; int f; int b, w, bt, wt; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; void dfs(int x, int y) { if (x < 0 || y < 0 || x >= N || y >= M || S[x][y] == '.') return; char c = S[x][y]; S[x][y] = '.'; if (c == 'b') bt++; if (c == 'w') wt++; for (int i = 0; i < 4; i++) { dfs(x + dx[i], y + dy[i]); } } int main() { f = b = w = 0; scanf("%d %d", &N, &M); for (int i = 0; i < N; i++) { char tmp[51]; scanf("%s", tmp); for (int j = 0; j < M; j++) { S[i][j] = tmp[j]; } } for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (S[i][j] == '.') { continue; } bt = wt = 0; dfs(i, j); f += min(bt, wt) * 100; if (bt > wt) b += bt - wt; if (bt < wt) w += wt - bt; } } if (b < w) swap(b, w); f += 10 * w; f += b - w; printf("%d", f); return 0; }