#K58772. Sort Students by Score and Name

    ID: 30717 Type: Default 1000ms 256MiB

Sort Students by Score and Name

Sort Students by Score and Name

You are given a list of students, where each student is described by a name and a score. Your task is to sort the list according to the following rules:

  • Students are sorted in descending order of their scores.
  • If two students have the same score, they are sorted in ascending alphabetical order by their names.

The input will be read from stdin and the output should be printed to stdout.

In mathematical notation, if you denote the score as \(S\) and the name as \(N\), then for two students \(a\) and \(b\), the sorting order is defined as:

\[ \text{if } S_a \neq S_b, \text{ then } a \prec b \Longleftrightarrow S_a > S_b, \] \[ \text{if } S_a = S_b, \text{ then } a \prec b \Longleftrightarrow N_a

inputFormat

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

outputFormat

Output the sorted list of students, one per line. For each student, print the name and score separated by a space, adhering to the sorting rules described above.

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

Charlie 90 Alice 85 David 75

</p>