#K82932. Consolidate Borrowed Books

    ID: 36085 Type: Default 1000ms 256MiB

Consolidate Borrowed Books

Consolidate Borrowed Books

You are given a list of book borrowing transactions. Each transaction consists of a friend's name and a book title. Your task is to consolidate these transactions by grouping the books borrowed by the same friend. The friends should appear in alphabetical order in the consolidated record. For each friend, print the friend's name followed by the list of book titles in the order they were borrowed.

Details:

  • The first line of input contains an integer \( N \) indicating the number of transactions.
  • The following \( N \) lines each contain two strings: a friend's name and a book title, separated by a space.
  • Output the consolidated records. For each friend (in alphabetical order), print the friend's name on a new line followed by each book title on subsequent new lines.

Note: All formulas, if any, are given in LaTeX format.

inputFormat

The input is given via standard input (stdin). The first line contains an integer \( N \) representing the number of transactions. Each of the next \( N \) lines contains two space-separated strings: the friend's name and the book title.

outputFormat

Output the consolidated book borrowing records to standard output (stdout). For each friend (in alphabetical order), print the friend's name on one line, followed by each borrowed book on separate lines in the order they appeared.

## sample
4
Alice WarAndPeace
Bob Frankenstein
Alice AnnaKarenina
Eve MobyDick
Alice

WarAndPeace AnnaKarenina Bob Frankenstein Eve MobyDick

</p>