output_description: Print the maximum possible number of operations in a line.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      S_1
      S_2
      \vdots
      S_N
attempt: from collections import deque
  import numpy as np
  
  N, M = map(int, input().split())
  S = [list(input()) for _ in range(N)]
  moves = [(1, 0), (0, 1)]
  
  starts = []
  for i in range(N):
      for j in range(M):
          if S[i][j] == "o":
              starts.append((i, j))
  
  answer = 0
  for start in starts:
      visited = np.full((N, M), -1)
      start_y, start_x = start
  
      q = deque()
      q.append((start_y, start_x))
      visited[start_y, start_x] = 0
  
      while q:
          y, x = q.popleft()
  
          for dy, dx in moves:
              moved_y = y + dy
              moved_x = x + dx
  
              if moved_y < 0 or N - 1 < moved_y or moved_x < 0 or M - 1 < moved_x:
                  continue
              if S[moved_y][moved_x] == "#" or S[moved_y][moved_x] == "o":
                  continue
              if visited[moved_y, moved_x] != -1:
                  continue
              visited[moved_y, moved_x] = visited[y, x] + 1
              q.append((moved_y, moved_x))
  
      answer += np.max(visited)
  
  print(answer)
  
problem_description: 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.
samples: [{"input": "3 3\n    o..\n    ...\n    o.#", "output": "4\n    \n\nYosupo can perform operations 4 times as follows:\n\n    \n    \n    o..      .o.      ..o      ...      ...\n    ...  ->  ...  ->  ...  ->  ..o  ->  ..o\n    o.#      o.#      o.#      o.#      .o#\n    \n\n* * *"}, {"input": "9 10\n    .#....o#..\n    .#..#..##o\n    .....#o.##\n    .###.#o..o\n    #.#...##.#\n    ..#..#.###\n    #o.....#..\n    ....###..o\n    o.......o#", "output": "24"}]