#C7113. Book Sorting by Title and Identifier

    ID: 50949 Type: Default 1000ms 256MiB

Book Sorting by Title and Identifier

Book Sorting by Title and Identifier

Given a list of books, each with an identifier and a title, sort the books first by title in lexicographical order and then by identifier in ascending order if the titles are identical.

More formally, if a book is represented as a tuple ((id, title)), the books should be reordered so that for any two books ((id_1, title_1)) and ((id_2, title_2)), if (title_1 < title_2) then ((id_1, title_1)) comes first; if (title_1 = title_2) then the book with the smaller (id) comes first.

inputFormat

The input begins with an integer (n) ((0 \le n \le 10^5)), representing the number of books. Each of the next (n) lines contains an integer identifier and a title separated by a space. Note that the title may contain spaces (the first integer is the identifier, and the rest of the line forms the title).

outputFormat

Output the sorted list of books, each on a separate line in the format: "identifier title". The sort should be based first on the title (in lexicographical order) and then on the identifier (in ascending order) if titles are identical.## sample

4
3 The Hobbit
1 A Tale of Two Cities
2 A Tale of Two Cities
4 Moby Dick
1 A Tale of Two Cities

2 A Tale of Two Cities 4 Moby Dick 3 The Hobbit

</p>