408631: GYM103241 F Books

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Bookstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Ryan is a bookworm. He has many books on his shelf, and he wants to sort them alphabetically by their first letter. Furthermore, he wants to sort the books that have the same starting letter by their published years, from oldest to most recent. Note that all the book titles are one word, with all lowercase letters.

Input

The first line has an integer $$$1 < N < 10000$$$, representing the number of books Ryan has on his shelf.

The next $$$N$$$ lines contain $$$A$$$ and $$$B$$$, where $$$A$$$ is the name of the book (the length of the book title will be $$$3 \leq A < 13$$$) and $$$0 \leq B < 10000$$$ is the publish year.

Output

Print the final sorted bookshelf, with the name of each book on a separate line.

ExampleInput
4
harry 1987
orange 1776
hotels 1973
moon 2018
Output
hotels
harry
moon
orange
Note

Problem idea: Spark

Problem preparation: Spark

Occurances: Novice 6

加入题单

上一题 下一题 算法标签: