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 = map(int, input().split())
  s = [None] * h
  for i in range(h):
      s[i] = list(input())
  
  # 横
  a = [[0] * w for i in range(h)]
  if w >= 2:
      for i in range(h):
          for j in range(w - 2, -1, -1):
              if s[i][j] != s[i][j + 1]:
                  a[i][j] += 1
                  if j + 2 < w:
                      a[i][j] += a[i][j + 2]
  
  # 縦
  b = [[0] * w for i in range(h)]
  if h >= 2:
      for j in range(w):
          for i in range(h - 2, -1, -1):
              if s[i][j] != s[i + 1][j]:
                  b[i][j] += 1
                  if i + 2 < h:
                      b[i][j] += b[i + 2][j]
  
  dp = [[0] * w for i in range(h)]
  
  
  def f(x, j):
      pp = 0
      if x + 1 < w and s[x][j] != s[x + 1][j]:
          k[r] = 1
  
  
  for i in range(h - 1, -1, -1):
      for j in range(w - 1, -1, -1):
          c = [0, 0, 0]
          if i + 1 < h and s[i + 1][j] != s[i][j]:
              dp[i][j] += 1
              if i + 2 < h and s[i + 2][j] == s[i][j]:
                  c[0] = 1
              if j + 1 < w and s[i + 1][j + 1] == s[i][j]:
                  c[1] = 1
          if j + 1 < w and s[i][j + 1] != s[i][j + 1]:
              dp[i][j] += 1
              if i + 1 < h and s[i + 1][j + 1] == s[i][j]:
                  c[1] = 1
              if j + 2 < w and s[i][j + 2] == s[i][j]:
                  c[2] = 1
  
          if c == [1, 0, 0]:
              dp[i][j] += dp[i + 2][j]
          elif c == [0, 1, 0]:
              dp[i][j] += dp[i + 1][j + 1]
          elif c == [0, 0, 1]:
              dp[i][j] += dp[i][j + 2]
          elif c == [1, 1, 0]:
              dp[i][j] += dp[i + 2][j] + b[i + 1][j + 1]
          elif c == [0, 1, 1]:
              dp[i][j] += dp[i][j + 2] + a[i + 1][j + 1]
          elif c == [1, 1, 1]:
              dp[i][j] += dp[i + 2][j] + b[i + 1][j + 1] + b[i][j + 2]
  
          elif c == [1, 0, 1]:
              dp[i][j] += dp[i][j + 2] + a[i + 2][j]
  
              for r in range(i + 2, w):
                  if s[i][r] != s[i + 1][r] and s[i + 1][r] != s[i][j]:
                      dp[i][j] += 1
  
  res = 0
  for i in range(h):
      for j in range(w):
          res += dp[i][j]
  print(res)
  
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"}]