11778 - Final Exam - Problem D   

Description

Problem D - Grade

Now HT gives a list of students and their score, your task is to sort their score in decreasing order.

If there are many students with the same score, you need to maintain their relative order in the original list.

That is, if whenever there are two students A and B with the same score and with A appearing before B in the original list, A will appear before B in the sorted list.

Input

The input consists of a single test case in the following format.

n

s1 c1

s2 c2

...

...

scn

The first line contains one integer n satisfying 1 ≤ n ≤ 1000n denotes the total number students on the given list. The next n lines show the information of students. The i-th line of them contains a string si whose length is between 1 and 50, inclusive, and an integer ci satisfying 0 ≤ ci ≤ 100, which means that the i-th student has the name si and his/her score is ci.

Output

Print the list of students' names after sorting, each name with a line.

Sample Input  Download

Sample Output  Download

Tags




Discuss