#C664. Group and Sort Numbers

    ID: 50422 Type: Default 1000ms 256MiB

Group and Sort Numbers

Group and Sort Numbers

You are given a list of integers. Your task is to group all identical numbers together, sort each group, and then print each group such that the groups themselves are sorted in ascending order based on their smallest element. In each group, the number appears as many times as it occurs in the input. The groups should be printed on separate lines.

For example, if the input list is [3, 1, 2, 2, 3, 1, 4, 1], the groups would be formed as follows:

  • Number 1 appears three times, so group is "1 1 1".
  • Number 2 appears two times, so group is "2 2".
  • Number 3 appears two times, so group is "3 3".
  • Number 4 appears once, so group is "4".

When sorted by the smallest number in each group, the output becomes:

1 1 1
2 2
3 3
4

Note: All formulas, if any, must be represented in LaTeX format. For instance, if you mention a formula it should be enclosed in \( ... \) or $$ ... $$.

inputFormat

The first line contains an integer n \((1 \leq n \leq 10^5)\), the number of integers.

The second line contains n space-separated integers. Each integer may range over any value that fits in the standard integer type.

outputFormat

Output the groups on separate lines. Each line should contain the corresponding group as space-separated numbers. The groups are ordered in ascending order of their smallest element.

## sample
8
3 1 2 2 3 1 4 1
1 1 1

2 2 3 3 4

</p>