atcoder#ABC193F. [ABC193F] Zebraness
[ABC193F] Zebraness
Score : points
Problem Statement
We have a grid with horizontal rows and vertical columns.
Let denote the square at the -th row from the top and -th column from the left. A character describes the color of .
B
means the square is painted black; W
means the square is painted white; ?
means the square is not yet painted.
Takahashi will complete the black-and-white grid by painting each unpainted square black or white. Let the zebraness of the grid be the number of pairs of a black square and a white square sharing a side. Find the maximum possible zebraness of the grid that Takahashi can achieve.
Constraints
- is
B
,W
, or?
.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
2
BB
BW
2
We have two pairs of a black square and a white square sharing a side: and , so the zebraness of this grid is .
3
BBB
BBB
W?W
4
Painting white makes the zebraness , and painting it black makes the zebraness .
5
?????
?????
?????
?????
?????
40