class maxFlow{ import std.typecons, std.conv, std.algorithm; // , std.stdio; alias T=int; alias Edge=Tuple!(int, "to", int, "rev", T, "cap"); Edge[][] g; bool[] vis; auto inf=(1_000_000_000).to!(T); this(int sz){ g.length=sz; vis.length=sz; } void addEdge(int from, int to, T cap){ g[from]~=Edge(to, (g[to].length).to!(int), cap); g[to]~=Edge(from, (g[from].length-1).to!(int), (0).to!(T)); } T flow(int i, T curf, int sink){ if(i==sink) return curf; vis[i]=true; foreach(ref e; g[i]){ if(vis[e.to] || e.cap==0) continue; auto tmpf=flow(e.to, min(curf, e.cap), sink); if(tmpf>0){ e.cap-=tmpf; g[e.to][e.rev].cap+=tmpf; return tmpf; } } return 0; } T ford(int source, int sink){ auto maxf=(0).to!(T); while(true){ fill(vis, false); auto f=flow(source, inf, sink); if(f>0) maxf+=f; else return maxf; } } } void main(){ import std.stdio, std.string, std.conv, std.algorithm; import std.math; int n, m; rd(n, m); auto c=new char[][](n, m); foreach(i; 0..n) c[i]=readln.chomp.to!(char[]); auto dir=[[1, 0], [-1, 0], [0, 1], [0, -1]]; auto mf=new maxFlow(n*m+2), s=n*m, t=s+1; int bk=0, wh=0; foreach(i; 0..n)foreach(j; 0..m){ if(c[i][j]=='.') continue; if((i+j)&1){ bk++; mf.addEdge(s, i*m+j, 1); foreach(d; dir){ auto ni=i+d[0], nj=j+d[1]; if(ni<0 || ni>=n || nj<0 || nj>=m) continue; if(c[ni][nj]=='.') continue; mf.addEdge(i*m+j, ni*m+nj, 1); } }else{ wh++; mf.addEdge(i*m+j, t, 1); } } auto fmax=mf.ford(s, t); bk-=fmax; wh-=fmax; writeln(fmax*100+min(bk, wh)*10+(bk-wh).abs); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; assert(l.length==x.length); foreach(i, ref e; x){ e=l[i].to!(typeof(e)); } }