{"raw_statement":[{"iden":"problem statement","content":"There is a grid with $H$ rows and $W$ columns, where each square is painted black or white.\nYou are given $H$ strings $S_1, S_2, ..., S_H$, each of length $W$. If the square at the $i$\\-th row from the top and the $j$\\-th column from the left is painted black, the $j$\\-th character in the string $S_i$ is `#`; if that square is painted white, the $j$\\-th character in the string $S_i$ is `.`.\nFind the number of pairs of a black square $c_1$ and a white square $c_2$ that satisfy the following condition:\n\n*   There is a path from the square $c_1$ to the square $c_2$ where we repeatedly move to a vertically or horizontally adjacent square through an alternating sequence of black and white squares: black, white, black, white..."},{"iden":"constraints","content":"*   $1 \\leq H, W \\leq 400$\n*   $|S_i| = W$ ($1 \\leq i \\leq H$)\n*   For each $i$ ($1 \\leq i \\leq H$), the string $S_i$ consists of characters `#` and `.`."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$H$ $W$\n$S_1$\n$S_2$\n$:$\n$S_H$"},{"iden":"sample input 1","content":"3 3\n.#.\n..#\n#.."},{"iden":"sample output 1","content":"10\n\nSome of the pairs satisfying the condition are $((1, 2), (3, 3))$ and $((3, 1), (3, 2))$, where $(i, j)$ denotes the square at the $i$\\-th row from the top and the $j$\\-th column from the left."},{"iden":"sample input 2","content":"2 4\n....\n...."},{"iden":"sample output 2","content":"0"},{"iden":"sample input 3","content":"4 3\n###\n###\n...\n###"},{"iden":"sample output 3","content":"6"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}