# Yuki 421 しろくろチョコレート ( Greedy, Maximum Bipartite Matching )

No.421 しろくろチョコレート - yukicoder

N, M ≤ 50

???
If someone could tell me...

```from itertools import product

dx = [ 0, 1, 0, -1 ]
dy = [ 1, 0, -1, 0 ]

N, M = map( int, input().split() )
G = [ input() for i in range( N ) ]

adj = [ [] for i in range( N * M ) ]

for i in range( N ):
for j in range( M ):
if G[ i ][ j ] != 'w': continue
for di in range( 4 ):
ni, nj = i + dx[ di ], j + dy[ di ]
if not ( 0 <= ni and ni < N and 0 <= nj and nj < M ): continue
if G[ ni ][ nj ] == '.': continue
adj[ i * M + j ].append( ni * M + nj )

def find_mate( u, bf, vis = None ):
if vis is None:
vis = [ False for i in range( N * M ) ]
for v in adj[ u ]:
if vis[ v ]: continue
vis[ v ] = True
if bf[ v ] == -1 or find_mate( bf[ v ], bf, vis ):
bf[ v ] = u
return True
return False

bf = [ -1 for i in range( N * M ) ]
match_cnt = 0
for i in range( 0, N * M ):
if G[ i // M ][ i % M ] != 'w': continue
match_cnt += find_mate( i, bf )

rw = sum( G[ i ][ j ] == 'w' for i, j in product( range( N ), range( M ) ) ) - match_cnt
rb = sum( G[ i ][ j ] == 'b' for i, j in product( range( N ), range( M ) ) ) - match_cnt
print( match_cnt * 100 + min( rw, rb ) * 10 + abs( rw - rb ) )
```