Sort Students by ScoreEasy

Sort Students by Score

EasyPractice library · +10 XPsortingcustom order

You are given a list of student names and their corresponding scores. Sort the students based on their scores in descending order. If two students have the same score, their relative order should be maintained as in the original input (this is known as a stable sort). Print the names of the students in the sorted order.

Input

The first line contains an integer N, the number of students. The next N lines each contain a string (student name) and an integer (score), separated by a space.

Output

Print N lines, each containing a student name, in the order determined by the sorting criteria.

Constraints

1 <= N <= 1000. Student names consist of lowercase English letters and have length between 1 and 10. Scores are integers between 0 and 100.

Time limit 1 s (native code; slower languages get more)Memory 256 MB12 hidden tests

Example 1

Input
5
Alice 85
Bob 92
Charlie 78
David 92
Eve 85
Output
Bob
David
Alice
Eve
Charlie

Bob and David have the same score (92), Bob appears before David in input, so Bob is printed first. Alice and Eve have score 85, Alice appears before Eve.

Example 2

Input
3
Zoe 100
Amy 90
Ben 95
Output
Zoe
Ben
Amy

Students are sorted by score in descending order.

Hints