#K8101. Island Sizes

    ID: 35658 Type: Default 1000ms 256MiB

Island Sizes

Island Sizes

You are given a binary matrix where \(1\) represents land and \(0\) represents water. An island is defined as a group of connected lands (\(1\)s) connected horizontally or vertically (but not diagonally). Your task is to determine the sizes of all islands present in the matrix. The result should be sorted in ascending order.

The input is provided via standard input (stdin), and the output should be printed to standard output (stdout).

inputFormat

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

outputFormat

Print the sizes of all islands in ascending order separated by a single space. If there are no islands, print nothing.

## sample
4 5
1 1 0 0 0
1 1 0 0 1
0 0 0 1 1
0 0 0 0 0
3 4

</p>