Hide

Problem C
Troll Book

A team of archaeologists have just done an amazing discovery underneath the ancient Arkadiko Bridge. They found the pages of the oldest book ever discovered! They immediately concluded it was a troll book since there was only one word on each page (which, frankly, made the discovery even more thrilling). Now, they are working to figure out what the book actually says.

Since the pages of the book are all spread out, it is not immediately clear in what order they should be read; fortunately, however, each page is marked with a page number. You have been recruited to put the pages in order so the archaeologists can read what the book says.

Input

The first line contains a single integer $n$, the number of pages. Then follows $n$ lines, one for each page; the $i$’th such line consists of a single word $w_ i$, the word on the page, and an integer $p_ i$, the page number.

Constraints

  • $1 \leq n \leq 100\, 000$

  • $1 \leq |w_ i| \leq 8$

  • $1 \leq p_ i \leq n$

Output

Output a single line with the entire contents of the book in the proper order.

Sample Input 1 Sample Output 1
6
my 5
horrible 2
bike 6
A 1
man 3
ate 4
A horrible man ate my bike

Please log in to submit a solution to this problem

Log in