PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000014. Những hồ nước (The Lakes)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Những hồ nước (The Lakes)

The Lakes

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A region is represented by a grid of nn rows and mm columns. The integer ai,ja_{i,j} gives the water depth at cell (i,j)(i,j). Cells of depth 00 are land. Positive-depth cells belong to the same lake if they can be connected through other positive-depth cells by moving up, down, left, or right.

The volume of a lake is the sum of depths of its cells. Find the maximum lake volume.

Input

The first line contains two integers n,mn,m. Each of the next nn lines contains mm integers giving the depths ai,ja_{i,j}.

Output

Print the volume of the largest lake, or 0 if the grid contains no lake.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le 12; 1≤m≤121\le m\le 12; n⋅m≤144n\cdot m\le 144; 0≤ai,j≤10000\le a_{i,j}\le 1000.
  • Subtask 2 (30 points): 1≤n≤1001\le n\le 100; 1≤m≤1001\le m\le 100; n⋅m≤10000n\cdot m\le 10000; 0≤ai,j≤10000\le a_{i,j}\le 1000.
  • Subtask 3 (50 points): 1≤n≤10001\le n\le 1000; 1≤m≤10001\le m\le 1000; n⋅m≤1000000n\cdot m\le 1000000; 0≤ai,j≤10000\le a_{i,j}\le 1000.

Examples

Input

3 3
1 2 0
3 4 0
0 0 5

Output

10

Explanation

The four positive cells at the top left form a lake of volume 1+2+3+4=101+2+3+4=10. The cell of depth 55 forms another lake, so the answer is 1010.