#K15901. Library Organizer

    ID: 24459 Type: Default 1000ms 256MiB

Library Organizer

Library Organizer

You are given a series of datasets representing collections of ancient scrolls. Each dataset starts with a positive integer n which specifies the number of scroll entries in that dataset. This is followed by n lines, each containing two integers: the first integer represents the topic t of the scroll, and the second represents the scroll's length l.

Your task is to organize the scrolls by their topic. For each dataset:

  • Group all scrolls by their topic.
  • Within each topic group, sort the scroll lengths in non-decreasing order.
  • Output the groups in ascending order of topic. For each group, first print the topic number on its own line, then each scroll length on separate lines. Separate different topic groups with an empty line.

The input terminates with a line containing a single 0.

Note: If there is only one scroll group in a dataset, do not output an extra blank line at the end.

Mathematically, if you denote the dataset by \(D = \{(t_i, l_i) : 1 \leq i \leq n\}\), then for each distinct topic \(k\) in \(D\), you must output \[ k, \quad \text{followed by} \quad l_{k,1} \le l_{k,2} \le \cdots \le l_{k,m_k}, \] with an empty line separating the outputs for different topics.

inputFormat

The input is read from standard input (stdin) and consists of one or more datasets. Each dataset begins with an integer n (\(n \ge 1\)), followed by n lines, each containing two space‐separated integers denoting the topic and the scroll length. The input ends with a line containing the number 0, which should not be processed.

outputFormat

For each dataset, output the scrolls organized by topic to standard output (stdout). For each topic group (in increasing order of topic number), print the topic on its own line, followed by the sorted scroll lengths (one per line). Separate successive topic groups by an empty line. There should be no extra blank line at the end of the output.

## sample
1
1 5
0
1

5

</p>