#K5806. Largest Same Animal Area

    ID: 30558 Type: Default 1000ms 256MiB

Largest Same Animal Area

Largest Same Animal Area

You are given a grid with n rows and m columns. Each cell in the grid is either an animal represented by a lowercase English letter or an empty cell represented by a dot ..

Your task is to find the largest rectangular area in the grid where all non-empty cells contain the same animal. In other words, for some animal c (where c is a lowercase letter), you need to choose a subrectangle such that every cell in that rectangle is equal to c. Note that the rectangle must be continuous in both rows and columns.

The area of a rectangle is given by \(Area = width \times height\).

If no such rectangle exists, the area is considered to be 0.

inputFormat

The input is given via standard input (stdin) and has the following format:

  • The first line contains two integers \(n\) and \(m\) separated by a space, representing the number of rows and columns of the grid respectively.
  • The next \(n\) lines each contains a string of length \(m\) representing a row of the grid. Each character is either a lowercase letter (an animal) or a dot . representing an empty cell.

outputFormat

Output a single integer to standard output (stdout): the area of the largest rectangle that contains only one type of animal.

## sample
4 5
aabba
abbba
aabba
bbbaa
6