#B2159. Grade Sorting

    ID: 11241 Type: Default 1000ms 256MiB

Grade Sorting

Grade Sorting

Given the transcript for a course containing student names and their scores, sort the records in descending order of scores. If two or more students have the same score, sort them by their names in lexicographical order (i.e., dictionary order, ascending).

The first line of input contains an integer n which represents the number of records. Each of the next n lines contains a student's name and score, separated by a space.

Output the sorted list, with each record printed on a new line in the format: name score.

inputFormat

The first line contains an integer n denoting the number of records. The following n lines each contain a student's name and an integer score separated by a space.

outputFormat

Print the sorted records. Each line should contain a student's name and score separated by a space. Records must be sorted in descending order of the score; if scores are equal, sort by the student name in ascending lexicographical order.

sample

3
Alice 90
Bob 95
Charlie 90
Bob 95

Alice 90 Charlie 90

</p>