Problem:
 Score : 700 points    Problem 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.      Constraints  2 \leq H \leq 2000  2 \leq W \leq 2000  |S_i| = W  S_i consists of # and . .         Input Input is given from Standard Input in the following format:  H  W  S_1  S_2  :  S_H       Output Print the maximum possible area of Snuke's rectangle.        Sample Input 1 3 3
..#
##.
.#.      Sample Output 1 6  If the first row from the top and the third column from the left are inverted, a 2 \times 3 rectangle can be drawn, as shown below:        Sample Input 2 4 4
....
....
....
....      Sample Output 2 16       Sample Input 3 10 8
##...#.#
##...#.#
..###.#.
#.##.#.#
.#..#.#.
..##.#.#
##.#.#..
...#.#..
###.#.##
###..###      Sample Output 3 27

Solution (Python):
import sys
input = sys.stdin.readline
from collections import deque

h,w = map(int,input().split())
s = []
for i in range(h):
  q = input().rstrip()
  s.append(q)

chk = [[0]*(w-1) for i in range(h-1)]
for i in range(w-1):
  for j in range(h-1):
    chk[j][i] = 1-int((s[j][i]=='

def f(a):
  a += [0]
  stack = deque()
  ans = -1
  for i in range(w):
    if stack == deque():
        stack.append((a[i], i))
    elif stack[-1][0] < a[i]:
        stack.append((a[i], i))
    elif stack[-1][0] > a[i]:
      while stack and stack[-1][0] >= a[i]:
        x, y = stack.pop()
        ans = max((x+1)*(i-y+1), ans)
      stack.append((a[i], y))
  return ans
  
dp = [[0]*(w-1) for i in range(h-1)]
for i in range(w-1):
  dp[0][i] = chk[0][i]
  
for i in range(1,h-1):
  for j in range(w-1):
    if chk[i][j]:
      dp[i][j] = dp[i-1][j]+1

ans=max(h,w)
for i in range(h-1):
    ans=max(ans,f(dp[i]))
    
print(ans)

Solution (Python):
import sys

input=sys.stdin.readline
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())

def main():
    h, w = MI()
    s = [[c == "
    
    
    
    
    t = [[-1] * (w - 1) for _ in range(h - 1)]
    for i in range(h - 1):
        si = s[i]
        si1 = s[i + 1]
        t[i] = [1 - (sum(si[j:j + 2]) + sum(si1[j:j + 2])) % 2 for j in range(w - 1)]
    
    
    ti=t[0]
    for i in range(1, h - 1):
        ti1=ti
        ti=t[i]
        for j in range(w - 1):
            if ti[j]: ti[j] = ti1[j] + 1
    
    ans = 0
    for i in range(h - 1):
        jtol = [0] * (w - 1)
        jtor = [0] * (w - 1)
        ti=t[i]
        
        stack = [[-1, 0]]
        for j in range(w - 1):
            tij=ti[j]
            while stack[-1][0] >= tij: stack.pop()
            jtol[j] = stack[-1][1]
            stack.append([tij, j + 1])

        stack = [[-1, w - 1]]
        for j in range(w - 2, -1, -1):
            tij=ti[j]
            while stack[-1][0] >= tij: stack.pop()
            jtor[j] = stack[-1][1]
            stack.append([tij, j])

        for j in range(w - 1):
            tmp = (jtor[j] - jtol[j] + 1) * (ti[j] + 1)
            if tmp > ans: ans = tmp
    print(max(ans,h,w))

main()

Solution (Python):
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'')

H,W


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
    
    stack=[]
    for j,h in enumerate(height+[0]):
        while stack:
            prev_h = height[stack[-1]]
            if prev_h < h:
                break
            stack.pop()
            left_end = -1 if not stack else stack[-1]
            area = (j-left_end)*prev_h
            if max_area < area:
                max_area = area
        stack.append(j)


if max_area < max(W,H):
    max_area = max(W,H)
print(max_area)

Solution (Python):
H,W=map(int,input().split())
ans=max(H, W)
S=[input() for i in range(H)]
T = [[0]*(W-1)]
for i in range(H-1):
    t,ts=[],[]
    for j in range(W-1):
      r=S[i][j:j+2]+S[i+1][j:j+2]
      t.append(r.count('.')%2)
      if t[j]==0:
        ts.append(T[-1][j]+1)
      else:
        ts.append(0)
    T.append(ts)
for L in T[1:]:
    stack=[]
    for i,l in enumerate(L+[0]):
      w=-1
      while stack and stack[-1][1]>=l:
        w,h=stack.pop()
        ans = max(ans, (h+1)*(i-w+1))
      if w!=-1:
        stack.append((w,l))
        continue
      stack.append((i,l))
print(ans)

Solution (Python):
from collections import deque
H,W=map(int,input().split())
S=[input() for i in range(H)]
table=[[0]*(W-1) for i in range(H-1)]
for i in range(W-1):
    for j in range(H-1):
        table[j][i]=(int(S[j][i]=='

def get_rec(L):
    a = len(L)
    arr = L + [0]
    stack = deque()
    ans = -1
    for i in range(a + 1):
        
        if len(stack)==0:
            stack.append((arr[i], i))
        elif stack[-1][0] < arr[i]:
            stack.append((arr[i], i))
        elif stack[-1][0] > arr[i]:
            while len(stack) != 0 and stack[-1][0] >= arr[i]:
                x, y = stack.pop()
                ans = max((x+1) * (i - y+1), ans)
            
            stack.append((arr[i], y))
        
    return ans
dp=[[0]*(W-1) for i in range(H-1)]
for i in range(W-1):
    for j in range(H-1):
        if j==0:
            dp[0][i]=table[0][i]
            continue
        if table[j][i]==1:
            dp[j][i]=dp[j-1][i]+1
ans=max(H,W)
for j in range(H-1):
    ans=max(ans,get_rec(dp[j]))
print(ans)

Solution (Python):
def inpl(): return [int(i) for i in input().split()]

H, W = inpl()
ans = max(H, W)
S = [input() for _ in range(H)]
T = [[0]*(W-1)]
for i in range(H-1):
    t = []
    for j in range(W-1):
        r = S[i][j:j+2] + S[i+1][j:j+2]
        t.append(r.count('.')%2)
    ts = [T[-1][i] + 1 if not k else 0 for i, k in enumerate(t) ]
    T.append(ts)
for iT in T[1:]:
    stack = []
    for i, l in enumerate(iT+[0]):
        dw = -1
        while stack and stack[-1][1] >= l:
            dw, dh = stack.pop()
            ans = max(ans, (dh+1)*(i-dw+1))
        if dw != -1:
            stack.append((dw,l))
            continue
        stack.append((i, l))
print(ans)

Solution (Python):
H, W = map(int, input().split())
S = [input() for _ in range(H)]

ans = max(H, W)

f = [1] * W
for i in range(1, H):
    f = [(f[j]+1) if (S[i-1][j:j+2] + S[i][j:j+2]).count('
    stk = []
    for j, v in enumerate(f):
        while len(stk) > 0 and f[stk[-1]] >= v:
            ans = max(ans, f[stk.pop()] * (j - (stk[-1] if len(stk) > 0 else -1)))
        stk.append(j)

print(ans)