#P1565. AP's Majestic Palace

    ID: 14851 Type: Default 1000ms 256MiB

AP's Majestic Palace

AP's Majestic Palace

AP is planning to build a magnificent rectangular palace on a land plot of dimensions \(N \times M\). The land is divided into grid cells where each cell \((i,j)\) has an altitude \(a_{i,j}\). AP wishes his palace to have an average altitude above sea level (assume the sea level is at height zero) and at the same time the palace should be as large as possible so that more people can come to worship him.

A palace corresponds to a subrectangle of the given grid. Note that for any subrectangle, the condition that its average altitude is above 0 is equivalent to its total sum being greater than 0. Your task is to find the maximum area (i.e. number of cells) of a subrectangle with a positive total altitude sum. If no such subrectangle exists, output 0.

Note: The average condition \(\frac{\text{sum}}{\text{area}} > 0\) is equivalent to \(\text{sum} > 0\).

inputFormat

The first line contains two integers \(N\) and \(M\) denoting the number of rows and columns respectively.

Then follow \(N\) lines. Each line contains \(M\) integers \(a_{i,j}\) representing the altitude of the cell at row \(i\) and column \(j\).

\(1 \leq N, M \leq 100\) (assumed) and \(|a_{i,j}|\) can be any integer.

outputFormat

Print a single integer: the area of the largest subrectangle whose total sum of altitudes is greater than 0. If no such subrectangle exists, print 0.

sample

3 3
1 -1 2
-2 3 -1
1 1 -1
9