output_description: Print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      H W
      S_1
      S_2
      :
      S_H
attempt: import numpy as np
  
  H, W = map(int, input().split())
  s_list_list = [input() for _ in range(H)]
  
  color_matrix = []
  for l in s_list_list:
      new_l = []
      for string in l:
          if string == "#":
              new_l.append(1)
          else:
              new_l.append(0)
      color_matrix.append(new_l)
  
  color_matrix = np.array(color_matrix)
  score_matrix = np.zeros((H, W))
  
  for row in range(H):
      for col in range(W):
          masu = color_matrix[row][col]
          score = 0
          if masu == 1:
              if not col == 0:
                  if color_matrix[row][col - 1] == 0:
                      score += 1
              if not col == W - 1:
                  if color_matrix[row][col + 1] == 0:
                      score += 1
              if not row == 0:
                  if color_matrix[row - 1][col] == 0:
                      score += 1
              if not row == H - 1:
                  if color_matrix[row + 1][col] == 0:
                      score += 1
          score_matrix[row][col] += score
  
  new_score_matrix = np.zeros((H, W))
  
  
  for row in range(H):
      for col in range(W):
          masu = score_matrix[row][col]
          if masu > 0:
              if not (row == 0 or col == 0):
                  hidariue = score_matrix[row - 1][col - 1]
              else:
                  hidariue = 0
              if not col == 0 and not row == H - 1:
                  hidarisita = score_matrix[row + 1][col - 1]
              else:
                  hidarisita = 0
              if not row == 0 and not col == W - 1:
                  migiue = score_matrix[row - 1][col + 1]
              else:
                  migiue = 0
              if not (row == H - 1 or col == W - 1):
                  migisita = score_matrix[row + 1][col + 1]
              else:
                  migisita = 0
              if hidariue > 0:
                  unions = [color_matrix[row][col - 1], color_matrix[row - 1][col]]
                  unions = (np.array(unions) - 1) * (-1)
                  masu += hidariue - sum(unions)
              if hidarisita > 0:
                  unions = [color_matrix[row][col - 1], color_matrix[row + 1][col]]
                  unions = (np.array(unions) - 1) * (-1)
                  masu += hidarisita - sum(unions)
              if migiue > 0:
                  unions = [color_matrix[row][col + 1], color_matrix[row - 1][col]]
                  unions = (np.array(unions) - 1) * (-1)
                  masu += migiue - sum(unions)
              if migisita > 0:
                  unions = [color_matrix[row][col + 1], color_matrix[row + 1][col]]
                  unions = (np.array(unions) - 1) * (-1)
                  masu += migisita - sum(unions)
  
          new_score_matrix[row][col] = masu
  
  print(int(sum(new_score_matrix.flatten())))
  
problem_description: Statement
  
  There is a grid with H rows and W columns, where each square is painted black
  or white.
  
  You 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 `.`.
  
  Find the number of pairs of a black square c_1 and a white square c_2 that
  satisfy the following condition:
  
    * 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...
samples: [{"input": "3 3\n    .#.\n    ..#\n    #..", "output": "10\n    \n\nSome of the pairs satisfying the condition are ((1, 2), (3, 3)) and ((3, 1),\n(3, 2)), where (i, j) denotes the square at the i-th row from the top and the\nj-th column from the left.\n\n* * *"}, {"input": "2 4\n    ....\n    ....", "output": "0\n    \n\n* * *"}, {"input": "4 3\n    ###\n    ###\n    ...\n    ###", "output": "6"}]