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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    int H, W;

    void calc()
    {
        cin = new Scanner();
        H = cin.nextInt();
        W = cin.nextInt();

        int ans = 0;
        string[] S = new string[H];
        for (int i = 0; i < H; i++)
        {
            S[i] = cin.next();
        }
        ans = Math.Max(ans, calc2(S));

        for (int i = 0; i < H; i++)
        {
            S[i] = rev(S[i]);
        }
        ans = Math.Max(ans, calc2(S));
        
        for (int i = 0; i < H / 2; i++)
        {
            swap(ref S[i], ref S[H - 1 - i]);
        }
        ans = Math.Max(ans, calc2(S));
        
        for (int i = 0; i < H; i++)
        {
            S[i] = rev(S[i]);
        }
        ans = Math.Max(ans, calc2(S));

        Console.WriteLine(ans);
    }

    //swap
    void swap<T>(ref T a, ref T b)
    {
        T c = a;
        a = b;
        b = c;
    } 

    string rev(string S)
    {
        StringBuilder sb = new StringBuilder();
        for (int i = S.Length - 1; i >= 0; i--)
        {
            sb.Append(S[i]);
        }
        return sb.ToString();
    }

    int calc2(string[] S)
    {
        int[,] board = new int[H, W];

        for (int y = 1; y < H; y++)
        {
            for (int x = 1; x < W; x++)
            {
                if ((S[y - 1][x - 1] == S[y - 1][x]) != (S[y][x - 1] == S[y][x]))
                {
                    board[y, x] = 1;
                }
            }
        }

        int[,] dist = new int[H, W];
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                if (i == 0) dist[i, j] = 1;
                else
                {
                    if (board[i, j] == 1) dist[i, j] = 0;
                    else
                    {
                        dist[i, j] = dist[i - 1, j] + 1;
                    }
                }
            }
        }

        /*
        for (int i = 0; i < H; i++)
        {
            Console.WriteLine(S[i]);
        }

        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                if (dist[i, j] == 0) Console.Write('-');
                else Console.Write(dist[i, j] % 10);
            }
            Console.WriteLine();
        }
        */

        int ans = Math.Max(H, W);

        for (int i = 0; i < H; i++)
        {
            //pos, num
            Stack<Tuple<int, int>> t = new Stack<Tuple<int, int>>();
            for (int j = 0; j < W; j++)
            {
                int num = dist[i, j] + 1;
                if (num > i + 1) num = i + 1;
                while (t.Count != 0 && t.Peek().Item2 > num)
                {
                    var now = t.Pop();
                    //Console.WriteLine(i + " " + j + " " + ((j + 1 - now.Item1) * now.Item2));

                    ans = Math.Max(ans, (j - now.Item1) * now.Item2);
                }
                if (t.Count == 0 || t.Peek().Item2 != num)
                {
                    t.Push(Tuple.Create(Math.Max(0, j - 1), num));
                }
            }

            while (t.Count != 0)
            {
                var now = t.Pop();
                ans = Math.Max(ans, (W - now.Item1) * now.Item2);
            }
        }
        //Console.WriteLine(ans);
        return ans;
    }
    

    class Heap<T> where T : IComparable
    {
        public HeapNode<T> top;

        public Heap() { }

        public void push(T val)
        {
            top = HeapNode<T>.meld(top, new HeapNode<T>(val));
        }

        public T pop()
        {
            T ret = top.val;
            top = HeapNode<T>.meld(top.r, top.l);
            return ret;
        }

        public void merge(Heap<T> h2)
        {
            top = HeapNode<T>.meld(top, h2.top);
        }

        public class HeapNode<NT> where NT : IComparable
        {
            public HeapNode<NT> l, r;
            public NT val;

            public HeapNode(NT _val)
            {
                val = _val;
            }

            public static HeapNode<NT> meld(HeapNode<NT> a, HeapNode<NT> b)
            {
                if (a == null) return b;
                if (b == null) return a;
                if (a.val.CompareTo(b.val) > 0)
                {
                    HeapNode<NT> temp = a;
                    a = b;
                    b = temp;
                }
                a.r = meld(a.r, b);
                HeapNode<NT> temph = a.l;
                a.l = a.r;
                a.r = temph;
                return a;
            }
        }
    }

}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}