Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/stack-eng-katta-tortburchak

Largest rectangle of ones

Hard 2000 ms 128 MB 95%
Share

Each cell of a table with $n$ rows and $m$ columns contains $0$ or $1$. Find the area (the number of cells) of the largest rectangle whose sides go along the table lines and which consists only of cells with $1$. If the table has no $1$, print $0$.

A table of zeros and ones: the largest rectangle consisting only of ones is highlighted

Input

The first line contains two positive integers: $n$ and $m$.
Each of the next $n$ lines contains a string of $m$ characters (0 or 1).

Output

One integer — the largest area.

Note

$1 \le n, m \le 300$

Examples

Input #1
4 5
10100
10111
11111
10010
Output #1
6
Input #2
1 1
0
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.