cswork / OAOpen practice workspace

HSBCOA #3

Find Largest House Area

Estimated MediumJudge-ready

Topics (AI-labelled)Grid Search

In the grid, 1 represents a roof and 0 represents open ground. Only 1s adjacent up, down, left or right belong to the same house; diagonal cells are not connected. Find the number of cells covered by the largest house.

The original problem's connectivity rule is clear; this site adds the grid size and the result for a grid with no houses.

Input

The first line contains n m (1≤n,m, and nm≤200000); each of the next n lines contains m values, each 0 or 1.

Output

Output the area of the largest connected component; output 0 if there is no 1.

Example 1

Input:

4 3
0 0 0
0 1 1
0 0 0
1 1 0

Output:

2

Example 2

Input:

2 2
1 0
0 1

Output:

1

Example 3

Input:

1 1
0

Output:

0

Editorial

Loading solution…