output_description: Print the maximum possible area of Snuke's rectangle.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      H W
      S_1
      S_2
      :
      S_H
attempt: import sys
  
  read = sys.stdin.buffer.read
  readline = sys.stdin.buffer.readline
  readlines = sys.stdin.buffer.readlines
  
  """
  ・2x2内の偶奇が不変量。これが偶数なら、そこは単色でとれる
  ・単色でとれる領域を調べる -> 色変更なしに大きい長方形をとる問題になる
  ・ベースラインを固定すると、ヒストグラムの長方形の問題（アリ本）
  """
  
  H, W = map(int, readline().split())
  grid = read().replace(b"\r", b"").replace(b"\n", b"")
  
  # 左上に集める
  cnt = [0] * (H * W)
  for x in range(H * W):
      if grid[x] == ord("#"):
          # その場
          cnt[x] ^= 1
          # 左
          if x % W:
              cnt[x - 1] ^= 1
          # 上
          if x >= W:
              cnt[x - W] ^= 1
          if x % W and x >= W:
              cnt[x - W - 1] ^= 1
  
  max_area = 0
  height = [1] * (W - 1)
  for i in range(H - 1):
      for j in range(W - 1):
          if cnt[W * i + j]:
              height[j] = 1
          else:
              height[j] += 1
      # 最大長方形の変種。横幅を1乗せる
      stack = []
      for j, h in enumerate(height + [0]):
          while stack:
              prev_h = height[stack[-1]]
              if prev_h <= h:
                  break
              left_end = stack.pop()
              area = (j - left_end + 1) * height[left_end]
              if max_area < area:
                  max_area = area
          stack.append(j)
  
  # 幅1の長方形は2x2を素材としない
  if max_area < max(W, H):
      max_area = max(W, H)
  print(max_area)
  
problem_description: Statement
  
  We have a board with an H \times W grid. Each square in the grid is painted in
  black or white. The square at the i-th row from the top and j-th column from
  the left is black if the j-th character in S_i is `#`, and white if that
  character is `.`.
  
  Snuke can perform the following operation on the grid any number of times:
  
    * Select a row or column in the grid, and invert the color of all the squares in that row or column (that is, black squares become white and vice versa).
  
  Then, Snuke draws a rectangle along grid lines. Here, all the squares
  contained in the rectangle must be painted in black.
  
  Find the maximum possible area of Snuke's rectangle when the operation is
  performed optimally.
samples: [{"input": "3 3\n    ..#\n    ##.\n    .#.", "output": "6\n    \n\nIf the first row from the top and the third column from the left are inverted,\na 2 \\times 3 rectangle can be drawn, as shown below:\n\n![](https://atcoder.jp/img/arc081/2995c3921ed4dffc8ee528b63b9c6118.png)\n\n* * *"}, {"input": "4 4\n    ....\n    ....\n    ....\n    ....", "output": "16\n    \n\n* * *"}, {"input": "10 8\n    ##...#.#\n    ##...#.#\n    ..###.#.\n    #.##.#.#\n    .#..#.#.\n    ..##.#.#\n    ##.#.#..\n    ...#.#..\n    ###.#.##\n    ###..###", "output": "27"}]