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 in Pascal (FPC 2.6.2) (judge verdict: Wrong Answer)

{$goto+}
uses math;
label 1,2,3,4,5,6,7,8,9,a;
var go:array[0..2000,0..2000]of boolean;
    mp:array[0..2000,0..2000]of 0..1;
    de:array[0..2000,0..2000]of longint;
    l,r,s:array[0..2000]of longint;
    top,h,w,ans,i,j,cnt:longint;
    t:char;
begin
  readln(h,w);
  i:=1;4:
  j:=1;6:
  read(t);
  if t='#' then goto 1;
  mp[i,j]:=0;
  goto 2;
  1:mp[i,j]:=1;
  2:j:=-not j;
  if j>w then goto 5;
  goto 6;
  5:readln;
  i:=-not i;
  if i>h then goto 3;
  goto 4;
  3:i:=1;
  7:j:=1;
  9:go[i,j]:=(mp[i,j]+mp[-not i,j]+mp[i,-not j]+mp[-not i,-not j]) and 1=0;
  if j>w-1 then
    goto a;
  j:=-not j;
  goto 9;
  a:if i>h-1 then goto 8;
  i:=-not i;
  goto 7;
  8:
  for i:=1 to h do
    for j:=1 to w do
      if not go[i,j] then
        de[i,j]:=0
      else
        de[i,j]:=de[i-1,j]+1;
  for i:=1 to h do
  begin
    top:=1;
    s[1]:=0;
    for j:=1 to w-1 do
    begin
      while (top<>0) and (de[i-1,s[top]]>=de[i-1,j]) do
        dec(top);
      l[j]:=s[top];
      inc(top);
      s[top]:=j;
    end;
    top:=1;
    s[top]:=w;
    for j:=w-1 downto 1 do
    begin
      while (top<>0) and (de[i-1,s[top]]>=de[i-1,j]) do
        dec(top);
      r[j]:=s[top];
      inc(top);
      s[top]:=j;
    end;
    for j:=1 to w-1 do
      ans:=max(ans,(de[i-1,j]+1)*(r[j]-l[j]));
  end;
  writeln(max(ans,max(h,w)));
end.