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

~/algor $ cat problems/matritsa-eng-katta-birlar-kvadrati

Largest square of ones

Medium 1000 ms 128 MB 66%
Share

A matrix of size $n \times m$ consisting only of $0$ and $1$ is given. Find the side length of the largest square submatrix made only of $1$.

The largest square part made of ones

Input

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

Output

One integer — the side length of the largest square ($0$ if there are no ones).

Note

$1 \le n, m \le 200$
$a_{i,j} \in \{0, 1\}$

Examples

Input #1
4 5
1 0 1 1 1
1 1 1 1 1
0 1 1 1 1
1 1 1 1 0
Output #1
3
Input #2
2 2
0 0
0 0
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.