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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T>
vector<vector<T> > make_v(size_t a,size_t b){
  return vector<vector<T> >(a,make_v<T>(b));
}
template<typename T>
vector<vector<vector<T> > > make_v(size_t a,size_t b,size_t c){
  return vector<vector<vector<T> > > (a,make_v<T>(b,c));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int h,w;
  cin>>h>>w;
  vector<string> s(h+1);
  for(Int i=1;i<=h;i++) cin>>s[i],s[i]=s[i][0]+s[i]+s[i][w-1];
  s[0]=s[1];
  //for(Int i=0;i<=h;i++) cout<<s[i]<<endl;
  auto check=[&](Int y,Int x,Int z){
    Int a=0,b=0;
    for(Int i=0;i<2;i++){
      for(Int j=0;j<2;j++){
	a+=s[y-i][x-j];
	b+=s[y-i][x-j+1];
      }
    }
    if(z==0) return b%2==0;
    if(z==2) return a%2==0;
    return a%2==0 && b%2==0;
  };
  
  auto dp=make_v<Int>(3,h+1,w+2);
  fill_v(dp,0);
  for(Int k=0;k<3;k++){
    for(Int i=1;i<=h;i++){
      for(Int j=1;j<=w;j++){
	if(check(i,j,k)) dp[k][i][j]=dp[k][i-1][j]+1;
	else dp[k][i][j]=1;
	//cout<<dp[k][i][j];
      }
      //cout<<endl;
    }
    //cout<<endl;
  }
  
  Int ans=0;
  for(Int i=1;i<=h;i++){
    using P = pair<Int, Int>;
    stack<P> s;
    for(Int j=1;j<=w;j++){
      int pos=j;
      while(!s.empty()&&s.top().first>dp[1][i][j]){
	pos=s.top().second;
	chmax(ans,(j-pos)*s.top().first);
	chmax(ans,(j-pos+1)*min(s.top().first,dp[2][i][j]));
	s.pop();
      }
      s.emplace(dp[0][i][j],pos);
    }
    while(!s.empty()){
      chmax(ans,(w-s.top().second+1)*s.top().first);
      s.pop();
    }
  }
  
  cout<<ans<<endl;
  return 0;
}