Sort by Custom Rule

MEDIUM · C · 2000ms

For the awards ceremony, Imran needs students sorted by their event score (highest first), and any exact ties broken alphabetically by name. Read N students, each with a name (no spaces) and a score. Print names sorted by score descending; if scores tie, sort those names alphabetically ascending.

Input

First line N, then N lines of "name score".

Output

N names, one per line, in sorted order.

Constraints

1 ≤ N ≤ 1000, 0 ≤ score ≤ 100

Sample Input

3
Amit 80
Rafi 90
Sadia 80

Sample Output

Rafi
Amit
Sadia
main.c
Loading editor…

Write C, then Run (custom I/O) or Submit (sample tests). ⌘/Ctrl+Enter submits.

Sort by Custom Rule · DIU ContestHub