UptoSkills Arena RankerEasy

UptoSkills Arena Ranker

Easy+10 XP · +5 Aurasortingcustom sortbeginner

The UptoSkills Arena needs to rank students for an upcoming event. The ranking criteria are simple: first, sort by the number of problems solved in ascending order. If two students solved the same number of problems, sort them by their college ID in ascending order. Given a list of students with their problem counts and college IDs, print their ranking.

Input

The first line contains an integer N, the number of students. The next N lines each contain two integers: the number of problems solved (P) and the college ID (C).

Output

Print N lines, each containing the college ID of a student in the ranked order.

Constraints

1 <= N <= 1000 0 <= P <= 1000 1 <= C <= 100000

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

Example 1

Input
4
5 101
3 102
5 100
2 103
Output
103
102
100
101

Students are ranked by problems solved (2, 3, 5, 5), then by ID for ties (100 before 101).

Example 2

Input
3
10 50
10 40
10 60
Output
40
50
60

All students solved 10 problems, so they are ranked by ID (40, 50, 60).

Hints