#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MAX_MOD 1000000007 #define REP(i,n) for(int i = 0;i < n;++i) #define LONGINF 1000000000000000000 int choko[1000][1000] = {}; int already_got[1000][1000] = {}; int moved[4] = { 0,0,-1,1 }; int mmove[4] = { 1,-1,0,0 }; int main() { int n, m; cin >> n >> m; REP(i, n) { string hoge; cin >> hoge; REP(q, m) { if (hoge[q] == 'w') { choko[i+1][q+1] = 1; } else if(hoge[q] == 'b') { choko[i+1][q+1] = 2; } } } for (int i = 1;i <= n;++i) { for (int q = 1;q <= m;++q) { if (choko[i][q] != 0&&already_got[i][q] == false) { queue,pair>> tmp; for (int j = 0;j < 4;++j) { if (choko[i + mmove[j]][q + moved[j]] != 0&&already_got[i+mmove[j]][q + moved[j]] == 0) { tmp.push(make_pair(make_pair(i + mmove[j], q + moved[j]),make_pair(i,q))); already_got[i + mmove[j]][q+moved[j]] = 1; already_got[i][q] = 1; goto aaa; } } aaa:; while (tmp.empty() == false) { pair te = tmp.front().first; pair to = tmp.front().second; tmp.pop(); int can_go[2] = {-1,-1}; for (int j = 0;j < 4;++j) { if (choko[te.first + mmove[j]][te.second + moved[j]] != 0&&already_got[te.first + mmove[j]][te.second + moved[j]] == false) { can_go[0] = j; } if (choko[to.first + mmove[j]][to.second + moved[j]] != 0 && already_got[to.first + mmove[j]][to.second + moved[j]] == false) { can_go[1] = j; } } if (can_go[0] != -1 && can_go[1] != -1) { already_got[te.first + mmove[can_go[0]]][te.second + moved[can_go[0]]] = true; already_got[to.first + mmove[can_go[1]]][to.second + moved[can_go[1]]] = true; tmp.push(make_pair(te, make_pair(te.first + mmove[can_go[0]], te.second + moved[can_go[0]]))); tmp.push(make_pair(te, make_pair(to.first + mmove[can_go[1]], to.second + moved[can_go[1]]))); } } } } } long long white = 0; long long black = 0; long long win = 0; for (int i = 0;i <= n + 1;i++) { for (int q = 0;q <= m + 1;++q) { if (already_got[i][q] == 1) { win++; } else { if (choko[i][q] == 1) { white++; } if (choko[i][q] == 2) { black++; } } } } long long ans = win * 50; int hoge = min(white, black); ans += hoge * 10; ans += max(white, black) - hoge; cout <