#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; const int dx[] = {1, 0, -1, 0, -1, 1, -1, 1}; pair solve2(int sy, int sx); int h, w; vector s; vector > check; pair solve1(int sy, int sx) { queue > q, select; q.push(make_pair(sy, sx)); check[sy][sx] = true; while(!q.empty()){ int y = q.front().first; int x = q.front().second; q.pop(); for(int i=0; i<4; ++i){ int y2 = y + dy[i]; int x2 = x + dx[i]; if(!(0 <= y2 && y2 < h && 0 <= x2 && x2 < w) || check[y2][x2]) continue; if(s[y2][x2] == '.'){ check[y2][x2] = true; q.push(make_pair(y2, x2)); } else{ select.push(make_pair(y2, x2)); } } } pair ans(0, 0); while(!select.empty()){ int y = select.front().first; int x = select.front().second; select.pop(); if(!check[y][x]){ pair p = solve2(y, x); ans.first += p.first; ans.second += p.second; } } return ans; } pair solve2(int sy, int sx) { queue > q; q.push(make_pair(sy, sx)); check[sy][sx] = true; int cnt = 1; while(!q.empty()){ int y = q.front().first; int x = q.front().second; q.pop(); for(int i=0; i<8; ++i){ int y2 = y + dy[i]; int x2 = x + dx[i]; if(check[y2][x2]) continue; if(s[y2][x2] == 'x'){ check[y2][x2] = true; q.push(make_pair(y2, x2)); ++ cnt; } } } for(int i=0; i<4; ++i){ int y2 = sy + dy[i]; int x2 = sx + dx[i]; if(check[y2][x2]) continue; if(s[y2][x2] == '.'){ pair p = solve1(y2, x2); swap(p.first, p.second); p.second = max(p.second, p.first); p.first += cnt; return p; } } return make_pair(cnt, 0); } int main() { cin >> h >> w; h += 2; w += 2; s.assign(h, string(w, '.')); for(int y=1; y> s[y][x]; } } check.assign(h, vector(w, false)); pair ans = solve1(0, 0); cout << max(ans.first, ans.second) << endl; return 0; }