#C741. Largest Same Letter Rectangle

    ID: 51278 Type: Default 1000ms 256MiB

Largest Same Letter Rectangle

Largest Same Letter Rectangle

You are given a rectangular grid of size n rows and m columns. Each cell of the grid contains a single lowercase Latin letter. Your task is to determine the area of the largest sub-rectangle (i.e. a contiguous subgrid) that consists entirely of the same letter.

More formally, if we denote the grid by an array grid of size n × m, you need to find the maximum area among all rectangular regions such that every cell within the rectangle contains the same character.

Note that a rectangle is defined by its top-left and bottom-right coordinates and must consist of at least one cell.

The constraints are:

  • \(1 \le n \le 1000\)
  • \(1 \le m \le 1000\)

inputFormat

The input is given via standard input in the following format:

n m
row1
row2
... 
rown

Where:

  • n is the number of rows.
  • m is the number of columns.
  • Each of the next n lines contains a string of exactly m lowercase Latin letters representing a row of the grid.

outputFormat

Output a single integer via standard output, which is the area of the largest rectangle consisting entirely of the same letter.

## sample
3 4
aaaa
abab
aaaa
4