#K46677. Maximal Rectangle

    ID: 28030 Type: Default 1000ms 256MiB

Maximal Rectangle

Maximal Rectangle

You are given a binary matrix of dimensions \(m \times n\) where each cell contains either a 0 or a 1. Your task is to find the area of the largest contiguous rectangle consisting entirely of 1s within the matrix.

The input is provided via standard input (stdin) and the output should be printed to standard output (stdout) as a single integer representing the maximal area.

For example, given the matrix:

4 5
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0

The largest rectangle of 1s has an area of \(6\).

inputFormat

The first line of input contains two integers \(m\) and \(n\) which represent the number of rows and columns of the matrix, respectively. The next \(m\) lines each contain \(n\) space-separated integers (each either 0 or 1), representing the binary matrix.

outputFormat

Output a single integer, the area of the largest rectangle consisting entirely of 1s.

## sample
4 5
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0
6