#K181. Generate Borrowers List

    ID: 24597 Type: Default 1000ms 256MiB

Generate Borrowers List

Generate Borrowers List

Given a list of borrowing records, generate a JSON dictionary where each key is the name of a borrower and the corresponding value is a sorted list of books they have borrowed. The borrower names must be sorted alphabetically, and the list of books for each borrower must also be sorted in lexicographical order.

The input is read from standard input (stdin) and the output must be printed to standard output (stdout).

The problem can be mathematically stated as follows:

Given an integer ( n ) and ( n ) pairs ( (name, book) ), form a function ( f: Name \to {Book1, Book2, ...} ) such that for each name, the corresponding list of books is sorted alphabetically, and the keys in ( f ) are sorted in alphabetical order when output as a JSON dictionary.

inputFormat

The first line contains an integer ( n ), representing the number of records. Each of the following ( n ) lines contains a borrower's name and a book title separated by a comma. For example:

4 Alice,War and Peace Bob,1984 Alice,To Kill a Mockingbird Bob,Animal Farm

outputFormat

Print a JSON-formatted dictionary on a single line where each key is a borrower's name (sorted alphabetically) and the corresponding value is an array of book titles (sorted lexicographically). For instance, the output for the above sample should be:

{"Alice": ["To Kill a Mockingbird", "War and Peace"], "Bob": ["1984", "Animal Farm"]}## sample

4
Alice,War and Peace
Bob,1984
Alice,To Kill a Mockingbird
Bob,Animal Farm
{"Alice": ["To Kill a Mockingbird", "War and Peace"], "Bob": ["1984", "Animal Farm"]}