#C6482. Sort Books

    ID: 50247 Type: Default 1000ms 256MiB

Sort Books

Sort Books

You are given a list of books, where each book is represented by a publication year and a title. Your task is to sort the list of books first by their publication year in ascending order, and then by their title in lexicographical order for books with the same year.

Sorting Criteria:

  • Sort by year: If book A was published earlier than book B, it should come first.
  • If books have the same year, sort by title in lexicographical order.

Example: Consider the following input:

4
1993 TheAlchemist
2023 DeepLearning
1993 JurassicPark
2023 ArtificialIntelligence
After sorting we obtain:
JurassicPark
TheAlchemist
ArtificialIntelligence
DeepLearning

Note: The comparison of strings follows the standard lexicographical order.

inputFormat

The input is read from standard input and has the following format:

 n
 year1 title1
 year2 title2
 ...
 yearn titlen

where n is an integer representing the number of books, and each of the next n lines contains an integer year and a string title separated by a space. The title will not contain spaces.

outputFormat

Print the sorted list of book titles to standard output, each on a separate line, following the sorting order described above.

## sample
4
1993 TheAlchemist
2023 DeepLearning
1993 JurassicPark
2023 ArtificialIntelligence
JurassicPark

TheAlchemist ArtificialIntelligence DeepLearning

</p>