#K95337. Top Three Students by Average Score

    ID: 38841 Type: Default 1000ms 256MiB

Top Three Students by Average Score

Top Three Students by Average Score

Given a list of student score records, your task is to compute the average score for each student and output the names of the top three students with the highest averages. In the case of a tie, the names should be sorted in alphabetical order. If there are fewer than three students, output the names of all students.

The input will be given through standard input. The first line contains an integer n denoting the number of records. Each of the following n lines contains a record in the format Name,Score (without spaces). The score is an integer.

The output should be printed to standard output, where each line contains the name of a student in the resulting top list, following the order described above.

Note: The sorting criterion is given by:

[ \text{Sort}(s) = (-\text{average}(s), s) ]

This means that students are primarily sorted by their average score in descending order and, if tied, by their name in ascending (alphabetical) order.

inputFormat

The first line contains an integer n (1 ≤ n ≤ 105), representing the number of student records. Each of the next n lines contains a record in the format Name,Score, where Name is a string without spaces and Score is an integer.

outputFormat

Output the names of the top three students based on their average score. If there are fewer than three students, output all of them. Each name should be printed on a separate line. The ordering is defined first by average score in descending order and then alphabetically in case of ties.

## sample
7
Alice,88
Bob,72
Alice,95
Charlie,85
Bob,78
Charlie,90
Daisy,93
Daisy

Alice Charlie

</p>