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;
typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define mp(a,b) make_pair(a, b)
#define __builtin_popcount __builtin_popcountll

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; for(auto it = t.begin(); it != t.end(); ++ it) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; for(auto &it : t) {if(it!=t.begin()) os<<","; os<<it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; for(const auto &it : t) {if(it!=t.begin()) os<<","; os<<it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, h, w;

int max_rect(vi &data){
    data.push_back(0);
    vector<pii> q;
    q.emplace_back(0, -1);
    int res = 0;
    for (int i = 0; i < data.size(); ++i) {
        int ni = i;
        int x = data[i];
        while(!q.empty() && q.back().first >= x) {
            int y, j; tie(y, j) = q.back(); q.pop_back();
            res = max(res, y * (i - j + 1));
            ni = j;
        }
        q.emplace_back(x, ni);
    }
    return res;
}

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    scanf("%d%d", &h, &w);
    vector<vi> raw(h, vi(w));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            char c;
            scanf(" %c", &c);
            raw[i][j] = c == '#';
        }
    }
    int ans = max(h, w);
    vector<vi> data(w, vi(h));
    for (int i = 1; i < h; ++i) {
        int p1 = 0, p2 = 0;
        for (int j = (int) w - 1; j >= 0; --j) {
            if (raw[i][j] == raw[i-1][j]) {
                p1 = 0;
                p2 ++;
            } else {
                p1 ++;
                p2 = 0;
            }
            data[j][i] = max(p1, p2);
        }
    }
    for (int j = 0; j < w; ++j) {
        ans = max(ans, max_rect(data[j]));
    }
    cout << ans << endl;
    return 0;
}