キャディプログラミングコンテスト2021(AtCoder Beginner Contest 193)
F
Zebraness
AtCoder
⌀ 2475
原题
← E→
翻译中…

Problem Statement

翻译中…

We have a grid with $N$ horizontal rows and $N$ vertical columns. Let $(i, j)$ denote the square at the $i$-th row from the top and $j$-th column from the left. A character $c_{i,j}$ describes the color of $(i, j)$. 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

翻译中…
  • $1 ≤ N ≤ 100$
  • $c_{i, j}$ is B, W, or ?.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
c_{1,1} \dots c_{1,N}
\hspace{20pt}\vdots
c_{N,1} \dots c_{N,N}

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
2
BB
BW
Output #1
2
We have two pairs of a black square and a white square sharing a side: $(1, 2), (2, 2)$ and $(2, 1), (2, 2)$, so the zebraness of this grid is $2$.
Input #2
3
BBB
BBB
W?W
Output #2
4
Painting $(3, 2)$ white makes the zebraness $3$, and painting it black makes the zebraness $4$.
Input #3
5
?????
?????
?????
?????
?????
Output #3
40
题目信息
题号
abc193_f
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。