#C6753. Categorize Scrolls

    ID: 50548 Type: Default 1000ms 256MiB

Categorize Scrolls

Categorize Scrolls

You are given several test cases representing ancient scrolls. Each test case begins with an integer (N) which denotes the number of scrolls, followed by (N) lines. Each of those lines contains a scroll's serial number and the name of its civilization. The sequence of test cases is terminated by a line with a single 0.

For each test case, count the scrolls belonging to each civilization and print the results. The civilizations for each test case must be output in alphabetical order along with their respective counts. All output lines for different test cases are concatenated sequentially.

Input is provided via stdin, and output must be written to stdout.

inputFormat

The input consists of multiple test cases. For each test case:

  • The first line contains an integer (N) ((N \geq 0)), which denotes the number of scrolls in that test case.
  • The next (N) lines each contain an integer and a string separated by a space. The integer represents the serial number of a scroll and the string represents the civilization the scroll belongs to.

The input terminates when a test case begins with 0.

outputFormat

For each test case, output several lines. Each line should contain a civilization name and the count of scrolls in that civilization separated by a space. The civilizations must be listed in alphabetical order for every test case. The outputs for all test cases are concatenated and printed to stdout.## sample

3
101 Mesopotamia
102 Egypt
103 Egypt
0
Egypt 2

Mesopotamia 1

</p>