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 Rust (1.15.1) (judge verdict: Wrong Answer)

#[allow(dead_code)]
fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

#[allow(unused_macros)]
macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

#[allow(unused_macros)]
// macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } }
macro_rules! debug { ($x: expr) => () }

#[allow(dead_code)]
fn show<T>(iter: T) -> String
where
    T: Iterator,
    T::Item: std::fmt::Display
{
    let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e));
    res.pop();
    res
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};

fn max_rectangle(v: &Vec<u64>) -> u64 {
    // let mut stack =  Vec::new();
    let f = |stack: &mut Vec<_>, (ind, x)| {
        let ind = ind+1;
        let mut y = 0;
        while let Some((top_val, pre_ind)) = stack.pop()  {
            if top_val < x {
                stack.push((top_val, pre_ind));
                y = pre_ind;
                break;
            }
        }
        stack.push((x, ind));
        Some((ind-y) as u64)
    };
    let l: Vec<_> = v.iter().cloned().enumerate()
        .scan(Vec::new(), &f).collect();
    let r: Vec<_> = v.iter().cloned().rev().enumerate()
        .scan(Vec::new(), &f).collect();
    let res = v.iter().zip(l.iter().zip(r.iter().rev())).enumerate()
        .map(|(i, (&x, (&l, &r)) )| {
            if i as u64 + 1 - l == 0 {
                debug!(x);
                (l+r-1)*x
            } else {
                (l+r)*x
            }
        }).max().unwrap();
    res
}

// fn naive(v: &Vec<Vec<bool>>) -> u64 {
//     let n = v.len();
//     let m = v[0].len();
//     let mut res = 0;
//     let mut mav = Vec::new();
//     for mask in 0..1<<(n+m) {
//         let mut v = v.clone();
//         for i in 0..n {
//             for j in 0..m {
//                 v[i][j] ^= ((mask>>i)&1) ^ ((mask>>(n+j))&1) == 1;
//             }
//         }
//         // {
//         //     v.iter().for_each(|x| debug!( show(x.iter().map(|&x| if x {1} else {0})) ));
//         // }
//         let mut vec = vec![0; m];
//         let mut ma = 0;
//         for row in &v {
//             for j in 0..m {
//                 if row[j]  {
//                     vec[j] = 0;
//                 } else {
//                     vec[j] += 1;
//                 }
//             }
//             // debug!(vec);
//             ma = max(ma, max_rectangle(&vec));
//         }
//         if res < ma {
//             res = ma;
//             mav = v;
//         }
//         // debug!(0);
//     }
//     mav.iter().for_each(|x| println!("{}", show(x.iter().map(|&x| if x {1} else {0}))));
//     res
// }

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }
    
    let (h, w) = readl!(usize, usize);
    let s: Vec<_> = (0..h)
        .map(|_| readl!(String)
                .chars()
                .map(|c| c == '#')
                .collect::<Vec<_>>())
        .collect();

    // debug!(naive(&s));
    // debug!(max_rectangle(&vec![2, 2, 2]));

    let mut d = vec![vec![false; w+1]; h+1];
    for i in 0..h {
        for j in 0..w {
            if s[i][j] {
                d[i][j] ^= true;
                d[i+1][j] ^= true;
                d[i][j+1] ^= true;
                d[i+1][j+1] ^= true;
            }
        }
    }

    // for row in &d {
    //     let row_str = show(row.iter().cloned().map(|f| if f {1} else {0})); 
    //     debug!(row_str);
    // }
    // debug!(0);

    // {
    //     let mut d = d.clone();
    //     for row in &mut d {
    //         for i in 0..row.len()-1 {
    //             row[i+1] ^= row[i];
    //         }
    //     }
    //     for j in 0..d[0].len() {
    //         for i in 0..d.len()^1 {
    //             d[i+1][j] ^= d[i][j];
    //         }
    //     }
    //     for row in &d {
    //         let row_str = show(row.iter().cloned().map(|f| if f {1} else {0})); 
    //         debug!(row_str);
    //     }
    // }

    // for i in 0..h {
    //     d[i][0] = false;
    // }
    // for j in 0..w {
    //     d[0][j] = false;
    // }

    let mut vec = vec![0; w];
    let mut ans = 0;
    for row in d.iter().take(h) {
        for i in 0..w {
            if row[i] {
                vec[i] = 1;
            } else {
                vec[i] += 1;
            }
        }
        debug!(vec);
        ans = max(ans, max_rectangle(&vec));
    }

    printfln!("{}", ans);

}