#!/usr/bin/env python3 # from typing import * import sys import io import math import collections import decimal import itertools import bisect import heapq def input(): return sys.stdin.readline()[:-1] # sys.setrecursionlimit(1000000) # _INPUT = """# paste here... # """ # sys.stdin = io.StringIO(_INPUT) class Dinic: def __init__(self, n): self.n = n self.links = [[] for _ in range(n)] self.depth = None self.progress = None def add_link(self, _from, to, cap): self.links[_from].append([cap, to, len(self.links[to])]) self.links[to].append([0, _from, len(self.links[_from]) - 1]) def bfs(self, s): depth = [-1] * self.n depth[s] = 0 q = collections.deque([s]) while q: v = q.popleft() for cap, to, rev in self.links[v]: if cap > 0 and depth[to] < 0: depth[to] = depth[v] + 1 q.append(to) self.depth = depth def dfs(self, v, t, flow): if v == t: return flow links_v = self.links[v] for i in range(self.progress[v], len(links_v)): self.progress[v] = i cap, to, rev = link = links_v[i] if cap == 0 or self.depth[v] >= self.depth[to]: continue d = self.dfs(to, t, min(flow, cap)) if d == 0: continue link[0] -= d self.links[to][rev][0] += d return d return 0 def max_flow(self, s, t): flow = 0 while True: self.bfs(s) if self.depth[t] < 0: return flow self.progress = [0] * self.n current_flow = self.dfs(s, t, INF) while current_flow > 0: flow += current_flow current_flow = self.dfs(s, t, INF) INF = 10**10 H, W = map(int, input().split()) S = [input() for _ in range(H)] # 2分グラフ: S -> (W) -> (B) -> T mf = Dinic(H*W+2) n_w, n_b = 0, 0 for h in range(H): for w in range(W): if S[h][w] == 'w': n_w += 1 mf.add_link(0, h*W+w+1, 1) if 0 < w and S[h][w-1] != '.': mf.add_link(h*W+w+1, h*W+(w-1)+1, 1) if w < W-1 and S[h][w+1] != '.': mf.add_link(h*W+w+1, h*W+(w+1)+1, 1) if 0 < h and S[h-1][w] != '.': mf.add_link(h*W+w+1, (h-1)*W+w+1, 1) if h < H-1 and S[h+1][w] != '.': mf.add_link(h*W+w+1, (h+1)*W+w+1, 1) elif S[h][w] == 'b': n_b += 1 mf.add_link(h*W+w+1, H*W+1, 1) flow = mf.max_flow(0, H*W+1) n_w -= flow n_b -= flow m = min(n_w, n_b) score = flow*100 + m*10 + (n_w-m) + (n_b-m) print(score)