#K8766. Stable Book Sorting
Stable Book Sorting
Stable Book Sorting
You are given a list of books where each book is represented by an integer identifier and a title. Your task is to sort the books in ascending order based on their identifiers. If two books have the same identifier, they should retain their original order (i.e., the sort must be stable).
Note: Use the stable sorting algorithm to ensure that books with identical identifiers appear in the same order as in the input.
The mathematical condition for the sorting criterion is given by \(a_i \leq a_j\) for all books with identifiers when \(i \leq j\) after the sorting, where \(a_i\) represents the identifier of the book at position \(i\).
inputFormat
The input begins with an integer \(N\) (\(1 \leq N \leq 10^5\)) representing the number of books. Each of the next \(N\) lines contains an integer and a string separated by a space. The integer denotes the book's identifier and the string denotes the title of the book. The title may contain spaces.
outputFormat
Output the sorted list of books, one book per line. Each line should contain the book's identifier and title separated by a single space.
## sample5
123 The Art of Computer Programming
456 Clean Code
123 Introduction to Algorithms
789 Design Patterns
456 The Pragmatic Programmer
123 The Art of Computer Programming
123 Introduction to Algorithms
456 Clean Code
456 The Pragmatic Programmer
789 Design Patterns
</p>