#abc193f. [abc193_f]Zebraness
[abc193_f]Zebraness
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.
Sample Input 1
2
BB
BW
Sample Output 1
2
We have two pairs of a black square and a white square sharing a side: and , so the zebraness of this grid is .
Sample Input 2
3
BBB
BBB
W?W
Sample Output 2
4
Painting white makes the zebraness , and painting it black makes the zebraness .
Sample Input 3
5
?????
?????
?????
?????
?????
Sample Output 3
40