#include using namespace std; #define all(c) (c).begin(),(c).end() #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++) #define rep(i,n) REP(i,0,n) #define iter(c) __typeof((c).begin()) #define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++) #define mem(a) memset(a,0,sizeof(a)) #define pd(a) printf("%.10f\n",a) #define pb(a) push_back(a) #define in(a) insert(a) #define pi M_PI #define R cin>> #define F first #define S second #define C class #define ll long long #define ln cout<<'\n' #define _(_1,_2,_3,N,...)N #define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__) templatevoid pr1(T a){cout<void pr2(T a,T2 b){cout<void pr3(T a,T2 b,T3 c){cout<void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<=0&&x=0&&y P; int n,m; string s[1111]; int c[1111][1111],u[1111][1111],uu[1111][1111],cnt,d[1111111],M; vector v[1111111]; void dfs(int nx,int ny,int f,int z) { if(f&&s[nx][ny]!='x') return; if(f) u[nx][ny]=1,cnt++; uu[nx][ny]=1; c[nx][ny]=z; if(f) { rep(i,8) { int x=nx+dx[i],y=ny+dy[i]; if(check(n,m,x,y)&&!u[x][y]) dfs(x,y,f,z); } } else { rep(i,4) { int x=nx+dxx[i],y=ny+dyy[i]; if(!check(n,m,x,y)) M=0; if(u[x][y]&&M>c[x][y]) M=c[x][y]; if(check(n,m,x,y)&&!u[x][y]&&c[x][y]!=z) dfs(x,y,f,z); } } } P solve(int x) { P p=P(0,0); rep(i,v[x].size()) { P q=solve(v[x][i]); p.F+=q.S; if(q.F>q.S) p.S+=q.F; else p.S+=q.S; } p.F+=d[x]; return p; } void Main() { cin >> n >> m; rep(i,n) cin >> s[i]; int k=1; rep(i,n) { rep(j,m) { if(s[i][j]=='x'&&!u[i][j]) { cnt=0; dfs(i,j,1,k); d[k]=cnt; k++; } } } mem(uu); rep(i,n) { rep(j,m) { if(s[i][j]!='x'&&uu[i][j]==0) { M=MAX; dfs(i,j,0,-1); dfs(i,j,0,M); } } } int e[1111111]; fill(e,e+1111111,MAX); rep(i,n) { rep(j,m) { if(!c[i][j]) continue; rep(k,4) { int x=i+dxx[k],y=j+dyy[k]; if(!check(n,m,x,y)) e[c[i][j]]=0; else if(e[c[i][j]]>c[x][y]) e[c[i][j]]=c[x][y]; } } } rep(i,1111111) { if(e[i]!=MAX) v[e[i]].pb(i); } P p=solve(0); pr(max(p.F,p.S)); } int main() { ios::sync_with_stdio(0);cin.tie(0); Main();return 0; }