#K85117. Genre Sorting Challenge

    ID: 36571 Type: Default 1000ms 256MiB

Genre Sorting Challenge

Genre Sorting Challenge

The task is to sort genre names based on their ratings in descending order. In cases where two genres have the same rating, they should be sorted in alphabetical order (ascending).

You are given an integer \(n\) representing the number of genres, followed by \(n\) lines. Each line contains a genre name and its integer rating separated by a space.

The sorting criteria is defined as follows:

\[ \text{For any two genres } g_i \text{ and } g_j:\\ \quad \text{if } rating_i \neq rating_j, \; g_i \text{ comes before } g_j \text{ if } rating_i > rating_j,\\ \quad \text{if } rating_i = rating_j, \; g_i \text{ comes before } g_j \text{ if } g_i \text{ is lexicographically smaller than } g_j. \]

inputFormat

The first line of input contains an integer \(n\) — the number of genres.

Each of the following \(n\) lines contains a genre name and its rating separated by a space.

outputFormat

Output a single line containing the sorted list of genre names separated by a single space. If \(n = 0\), output an empty line.

## sample
4
Mystery 90
Romance 95
Fantasy 90
ScienceFiction 85
Romance Fantasy Mystery ScienceFiction