407110: GYM102697 081 It's a Mess!

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

081. It's a Mess!time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

You have an in-home library, but its organization is a mess! Fantasy books next to non-fiction biographies, detective novels next to ancient classics, and worst of all, the author's names aren't in alphabetical order!

To fix this problem, you decide to create a program that is able to divide the books into different genre groups, with the authors of the genres listed in alphabetical order.

Input

The first line will contain the number of books that are in the library, and the following lines will contain books in this format, with the author's last name as the first word, and the genre as the second word, with both being separated by a space.

Output

Output a line of string that will contain a single Genre, and the list of authors writing in that genre in alphabetical order, in this format: <genre>: <aauthor1>, <bauthor>, <cauthor>

ExampleInput
7
Bradbruy scifi
Asimov scifi
Kafka dystopian
Huxley dystopian
Tolkien fantasy
Collins dystopian
Herbert scifi
Output
dystopian: Collins, Huxley, Kafka
fantasy: Tolkien
scifi: Asimov, Bradbruy, Herbert
Note

(For the order of the genres, please make sure that they are also in alphabetical order.)

(It can also be assumed that all genres and authors will contain one word, but last names will have proper capitalization conventions.)

加入题单

上一题 下一题 算法标签: