Challenge: Leaderboard

Lab Python Beginner 10 points

Read n players with a name and a score. Print them from highest score to lowest; players with the same score are listed alphabetically. Use sorted with a key.

Input

Line 1: n. Then n lines name score.

Output

One line per player: name score.

Example

Input

4
Ravi 78
Asha 91
Meera 91
Zoya 85

Output

Asha 91
Meera 91
Zoya 85
Ravi 78
Sample input available Sample output available
Editor
Python

Hints

Store (name, score) tuples.

key=lambda p: (-p[1], p[0]) sorts by score high-to-low, then name A-to-Z.

Solution explanation

A tuple key sorts by the first part, then uses the second part to break ties.

Show solution
n = int(input())
players = []
for _ in range(n):
    name, score = input().split()
    players.append((name, int(score)))
for name, score in sorted(players, key=lambda p: (-p[1], p[0])):
    print(name, score)
Output
Answer
HOME LABS COMMUNITY DASHBOARD