#K43677. Sort Students Based on Scores

    ID: 27363 Type: Default 1000ms 256MiB

Sort Students Based on Scores

Sort Students Based on Scores

Given a list of students with their names and scores, your task is to sort the students in non-increasing order based on their scores. In case two or more students have the same score, they should be sorted in alphabetical order by their names. This sorting criteria can be mathematically represented as follows: For two students A and B with scores \(s_A\) and \(s_B\) and names \(name_A\) and \(name_B\), A comes before B if \(s_A > s_B\) or (\(s_A = s_B\) and \(name_A < name_B\)).

The input is provided via standard input (stdin) and the sorted list of student names should be printed to standard output (stdout), one per line.

inputFormat

The first line of input contains an integer \(n\) (\(1 \leq n \leq 10^5\)), representing the number of students. Each of the following \(n\) lines contains a student's name and score separated by a space. The name is a string without spaces and the score is an integer.

outputFormat

Output the sorted list of student names, each on a new line, according to the criteria specified above.

## sample
4
Alice 90
Bob 95
Charlie 85
David 95
Bob

David Alice Charlie

</p>