#K88262. Cluster Species

    ID: 37270 Type: Default 1000ms 256MiB

Cluster Species

Cluster Species

You are given an integer \( n \) which denotes the number of plants, and a list of \( n \) integers representing the species numbers of these plants. Your task is to group these species numbers into clusters where each cluster consists of consecutive numbers. Two numbers are consecutive if the difference between them is exactly 1.

First, sort the list of species numbers in increasing order. Then, form clusters such that if the current number is exactly 1 more than the previous number, it belongs to the same cluster. Otherwise, start a new cluster.

Input: The first line of input contains a single integer \( n \). The second line contains \( n \) space-separated integers representing the species numbers.

Output: Output the total number of clusters in the first line. Then, for each cluster, output a line containing the sorted species numbers in that cluster, separated by a single space.

Example:

Input:
7
2 1 9 3 5 4 7

Output: 3 1 2 3 4 5 7 9

</p>

inputFormat

The input consists of two lines:

  • The first line contains the integer \( n \), denoting the number of plants.
  • The second line contains \( n \) space-separated integers which represent the species numbers.

outputFormat

The output should contain \( k+1 \) lines where \( k \) is the number of clusters:

  • The first line contains the number of clusters.
  • The following \( k \) lines each contain the species numbers of one cluster, printed in increasing order and separated by a single space.
## sample
7
2 1 9 3 5 4 7
3

1 2 3 4 5 7 9

</p>