Hide

Problem J
The Book Club

Emilie and Poppy are very fond of reading. Especially obscure books by obscure authors. This means that the books they find sometimes have strange authors and titles. Sometimes both the books, and the authors, have very long names. This is troublesome when they want to shelf the books. Every book needs to be in the bookcase, sorted by author then title. They also like to make a note, writing how many books they have of the authors, to see which author they can put on hold and which author they should read more of.

Input

The input is composed of $1 \leq N \leq 10^5$ lines, each line containing the authors name, $a = M$, and the title of the book, $b = M$, $1 \leq M\leq 10^3$ words, separated by a comma. There can be repetitions in the input. Books repeated should only be counted once. Multiple authors can write books of the same name, those are considered different books.

Output

The output should consist of a lexicographical list of authors, with a note on how many books we have by that author. Each author has a sublist containing their books, also in lexicographical order.

Sample Input 1 Sample Output 1
Jonquil Ashraf, wildebeest mobbing courtier
Aubrei Emmitt Chrishawn, describers slapping selfrestraint
Lynnetta Tuongvi Lexie, illuminates stranglers
Lynnetta Tuongvi Lexie, intestinal bier
Salman Leighanna, adduce apparatuses
Shadawn Esteven Moneisha, looses creditable
Andrew Kristinia Chenay, scrooge desperately owing
1 book by Andrew Kristinia Chenay:
> scrooge desperately owing
1 book by Aubrei Emmitt Chrishawn:
> describers slapping selfrestraint
1 book by Jonquil Ashraf:
> wildebeest mobbing courtier
2 books by Lynnetta Tuongvi Lexie:
> illuminates stranglers
> intestinal bier
1 book by Salman Leighanna:
> adduce apparatuses
1 book by Shadawn Esteven Moneisha:
> looses creditable

Please log in to submit a solution to this problem

Log in