Under construction

Still being built. Things may change

Un-bear-able Zoo

Time limit1sMemory limit1024 MB

Summary
Given several test cases of animal descriptions, count each animal by its last word and print the kinds in alphabetical order with their counts.
Level

Easy3 of 10

Topics
Hash map, Sorting, String
Solved
No attempts yet

Problem

Dr. Back runs a zoo in his free time, when he is not busy hacking computers. Every morning he gets up and checks that none of the animals have escaped. He has a long list of all the animals and checks each one off as he sees it, but he thinks this is very inefficient. Animals of the same kind share a cage, so he only needs to know what kind of animal each one is. For example, if he has a white tiger and a Siberian tiger, he only wants to know that he has 2 tigers.

Given an integer n and n lines describing animals, output the animals Dr. Back has in his zoo in alphabetical order, each followed by its count.

Input

The input contains multiple test cases. Each test case starts with a line containing an integer n (0 ≤ n ≤ 103), followed by n lines, each describing one animal. Every line contains at least one word. An animal name may consist of several words in uppercase or lowercase, and the last word is the kind of animal. The input ends when n is 0.

Output

For each test case, print the list number in the form "List k:", where k starts at 1. Then print the animals Dr. Back has, in lowercase and alphabetical order. Each line has the animal kind, one space, the delimiter |, one space, and then the count.

Examples1

  1. Example 1

    Input
    6
    African elephant
    White tiger
    Indian elephant
    Siberian tiger
    Tiger
    Panda bear
    1
    Blue Russian Penguin
    0
    
    Expected output
    List 1:
    bear | 1
    elephant | 2
    tiger | 3
    List 2:
    penguin | 1