Hide

Problem F
Street Artist

A street artist is playing guitar on the street. The artist is playing so well that a lot of people are gathered. For curiosity, everyone wants to see the artist playing. However, a person can see the artist only if their vision is not blocked by a taller or equally tall person standing in front of them in the line. Write a program to give the list of people who can see the artist if they are in a line.

Input

The input begins with an integer $n$ ($1 < n < 100\, 000$) that denotes the number of people in the line. After that, there are $n$ lines. Each line starts with a string $s$ representing the name and $h$ ($150 \le h \le 220$) for his/her height. Each string $s$ consists of only English letters and will contain between $1$ and $20$ characters. The order of the input shows the position of that person in the line, which means the first input person is standing at the end of the line and the last input person is standing at the front of the line.

Output

Display the names of the persons that can see the artist, separated by spaces on a single line. The line should begin with the name of the tallest person that can see the artist and end with the name of the shortest person that can see the artist.

Sample Input 1 Sample Output 1
4
Liam 175
Noah 160
Ava 170
Logan 165
Liam Ava Logan
Sample Input 2 Sample Output 2
6
Liam 155
Noah 160
Jacob 170
Logan 180
Olivia 185
Sophia 190
Sophia 

Please log in to submit a solution to this problem

Log in