using System; using System.Text; using System.Linq; using System.Collections.Generic; class Program { private static readonly Scanner sc = new Scanner(); static void Main(string[] args) { int n = sc.Int; int m = sc.Int; string[] srkr = new string[n]; Flow mf = new Flow(n * m + 2); int s = n * m; int t = n * m + 1; for (int i = 0; i < n; i++) srkr[i] = sc.Str; int cntw = 0; int cntb = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (srkr[i][j] == 'w') { mf.AddEdge(s, i * m + j, 1); cntw++; } if (srkr[i][j] == 'b') { mf.AddEdge(i * m + j, t, 1); cntb++; } } } int[] dx = new int[] {1, -1, 0, 0}; int[] dy = new int[] {0, 0, 1, -1}; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { for (int k = 0; k < 4; k++) { int nx = i + dx[k], ny = j + dy[k]; if (nx < 0 || n <= nx || ny < 0 || m <= ny) continue; if (srkr[nx][ny] == 'b') mf.AddEdge(m * i + j, m * nx + ny, 1); } } } int cntpair = mf.MaximumFlow(s, t); int cnttwo = Math.Min(cntw, cntb) - cntpair; int cntone = Math.Max(cntw, cntb) - cntpair - cnttwo; Console.WriteLine(100 * cntpair + 10 * cnttwo + cntone); } } class Scanner { private string[] _str = new string[0]; private int _i; public string Str { get { if (_i >= _str.Length) { _str = Console.ReadLine().Split(' '); _i = 0; } return _str[_i++]; } } public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } } class Flow { private readonly List[] _rn; private readonly int _n; private readonly int[] _level; private readonly int[] _itr; private class Edge { public int To; public int Cap; public int Rev; } public Flow(int n) { _n = n; _rn = new List[n]; _level = new int[n]; _itr = new int[n]; for (var i = 0; i < n; i++) _rn[i] = new List(); } public void AddEdge(int from, int to, int cap) { _rn[from].Add(new Edge { To = to, Cap = cap, Rev = _rn[to].Count }); _rn[to].Add(new Edge { To = from, Cap = 0, Rev = _rn[from].Count-1 }); } public int MaximumFlow(int s, int t) { var sum = 0; while (BFS(s, t)) { int d; Array.Clear(_itr, 0, _n); while ((d = DFS(s, t, int.MaxValue)) != 0) sum += d; } return sum; } private bool BFS(int s, int t) { for (var i = 0; i < _n; i++) _level[i] = -1; var q = new Queue(); q.Enqueue(s); _level[s] = 0; while (q.Count != 0) { var v = q.Dequeue(); foreach (var e in _rn[v]) { if (e.Cap > 0 && _level[e.To] == -1) { q.Enqueue(e.To); _level[e.To] = _level[v] + 1; } } } return _level[t] != -1; } private int DFS(int v, int t, int f) { if (v == t) return f; for (; _itr[v] < _rn[v].Count; _itr[v]++) { var e = _rn[v][_itr[v]]; var reve = _rn[e.To][e.Rev]; if (e.Cap > 0 && _level[v] + 1 == _level[e.To]) { var d = DFS(e.To, t, Math.Min(f, e.Cap)); if (d != 0) { e.Cap -= d; reve.Cap += d; return d; } } } return 0; } }