#include #include #include #include #include #include #include #include using namespace std; #define GET_ARG(a,b,c,F,...) F #define REP3(i,s,e) for (i = s; i <= e; i++) #define REP2(i,n) REP3 (i,0,(int)(n)-1) #define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__) #define RREP3(i,s,e) for (i = s; i >= e; i--) #define RREP2(i,n) RREP3 (i,(int)(n)-1,0) #define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__) #define DEBUG(x) cerr << #x ": " << x << endl string s[50]; int w = 0, b = 0, ans = 0; int dx[] = {0,1,0,-1}; int dy[] = {1,0,-1,0}; int n, m; bool used[50][50]; char dfs(int y, int x) { used[y][x] = true; int i; REP (i,4) { int ny = y + dy[i]; int nx = x + dx[i]; if (ny < 0 || ny >= n || nx < 0 || nx >= m || used[ny][nx] || s[ny][nx] == '.') continue; char res = dfs(ny,nx); if (res != '.') { if (s[y][x] != '.') { ans += 100; s[y][x] = '.'; } else if (res == 'w') w++; else b++; } } char ret = s[y][x]; s[y][x] = '.'; return ret; } int main(void) { int i, j; cin >> n >> m; REP (i,n) cin >> s[i]; REP (i,n) REP (j,m) if (s[i][j] != '.') { char res = dfs(i,j); if (res == 'w') w++; else if (res == 'b') b++; } int mn = min(w,b); ans += mn * 10 + w + b - 2 * mn; cout << ans << endl; return 0; }