P26054 [AtCoder] Moving Pieces
提高-
题目描述

Problem Statement

There is a board with N rows and M columns.
The information of this board is represented by $N strings S_1,S_2,\ldots,S_N$.
Specifically, the state of the square at the i-th row from the top and the j-th column from the left is represented as follows:

  • S_{i,j}=. : the square is empty.
  • S_{i,j}=# : an obstacle is placed on the square.
  • S_{i,j}=o : a piece is placed on the square.

Yosupo repeats the following operation:

  • Choose a piece and move it to its right adjecent square or its down adjacent square.
    Moving a piece to squares with another piece or an obstacle is prohibited.
    Moving a piece out of the board is also prohibited.

Yosupo wants to perform the operation as many times as possible.
Find the maximum possible number of operations.

Input

Input is given from Standard Input in the following format:
N M
S_1
S_2
$\vdots$
S_N

Output

Print the maximum possible number of operations in a line.

Constraints

  • $1 \leq N \leq 50$
  • $1 \leq M \leq 50$
  • S_i is a string of length M consisting of ., # and o.
  • $1 \leq ($ the number of pieces $)\leq 100$.
    In other words, the number of pairs (i, j) that satisfy S_{i,j}=o is between 1 and 100, both inclusive.

Sample Input 1

3 3
o..
...
o.#

Sample Output 1

4

Yosupo can perform operations 4 times as follows:
o.. .o. ..o ... ...
... -> ... -> ... -> ..o -> ..o
o.# o.# o.# o.# .o#

Sample Input 2

9 10
.#....o#..
.#..#..##o
.....#o.##
.###.#o..o

.#...##.

..#..#.###

o.....#..

....###..o
o.......o#

Sample Output 2

24

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 3 o.. ... o.#
样例输出
4