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: h, w = list(map(int, input().split()))
  field = []
  for i in range(h):
      si = input()
      field.append([c for c in si])
  
  
  def visalizer():
      global field
      print("=========================")
      for i in range(h):
          for j in range(w):
              print(field[i][j], end=" ")
          print("\n")
      print("=========================")
  
  
  def maeke_last(c):
      if c == "#":
          return "."
      else:
          return "#"
  
  
  pair_list = []
  dx = [0, 0, -1, 1]
  dy = [1, -1, 0, 0]
  
  
  def dfs(
      last,
      s_row=0,
      s_colmun=0,
      row=0,
      column=0,
  ):
      global field
      global dict
      if not ((0 <= row and row <= h - 1) and (0 <= column and column <= w - 1)):
          return
      if field[row][column] == "@":
          return
  
      here = field[row][column]
  
      if here == last:
          return
      else:
          if not ((s_row, s_colmun), (row, column)) in pair_list:
              if here == ".":
                  pair_list.append(((s_row, s_colmun), (row, column)))
  
      here_was = field[row][column]
      field[row][column] = "@"
      # visalizer()
      for i in range(len(dx)):
          n_row = row + dx[i]
          n_column = column + dy[i]
          dfs(last=here, s_row=s_row, s_colmun=s_colmun, row=n_row, column=n_column)
      field[row][column] = here_was
  
  
  # for s_row in range(h):
  #     for s_column in range(w):
  #         dfs(last = field[s_row][s_column],  s_row=s_row, s_colmun=s_column, row=s_row, column=s_column)
  
  for s_row in range(h):
      for s_column in range(w):
          if field[s_row][s_column] == "#":
              dfs(
                  last=maeke_last(field[s_row][s_column]),
                  s_row=s_row,
                  s_colmun=s_column,
                  row=s_row,
                  column=s_column,
              )
  
  for ele in pair_list:
      if ele[0] == ele[1]:
          pair_list.remove(ele)
      # pair_list.remove((ele[1], ele[0]))
  
  pair_list2 = []
  # for ele in pair_list:
  #     if (not (ele[1], ele[0]) in pair_list2) :
  #         pair_list2.append(ele)
  
  # for ele in pair_list2:
  #     print(ele)
  print(len(pair_list))
  
  
  # visalizer()
  
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"}]