#include #define FL(i,a,b) for(ll i=(a);i<=(b);i++) #define FR(i,a,b) for(ll i=(a);i>=(b);i--) #define ll long long #define id(x,y) (x-1)*m+y using namespace std; const ll MAXN = 50 + 10; ll n,m,sumb=0,sumw=0,ans=0; ll match[MAXN*MAXN],vis[MAXN*MAXN]; char s[MAXN][MAXN]; vectorG[MAXN*MAXN]; bool dfs(ll u,ll idx){ for(ll v:G[u]){ if(vis[v]!=idx){ vis[v]=idx; if(!match[v]||dfs(match[v],idx)){ match[v]=u; return 1; } } } return 0; } signed main(){ scanf("%lld%lld",&n,&m); FL(i,1,n) scanf("%s",s[i]+1); FL(i,1,n){ FL(j,1,m){ if(s[i][j]=='.') continue; else if(s[i][j]=='w') sumw++; else sumb++; if(i!=1&&s[i-1][j]!='.') G[id(i,j)].push_back(id(i-1,j)); if(j!=1&&s[i][j-1]!='.') G[id(i,j)].push_back(id(i,j-1)); if(i!=n&&s[i+1][j]!='.') G[id(i,j)].push_back(id(i+1,j)); if(j!=m&&s[i][j+1]!='.') G[id(i,j)].push_back(id(i,j+1)); } } FL(i,1,n*m) ans+=dfs(i,i); ans/=2; // printf("%d %d %d\n",ans,sumw,sumb); printf("%lld\n",ans*100+(min(sumb,sumw)-ans)*10+abs(sumb-sumw)); }