#t554. 运动会奖牌榜

运动会奖牌榜

Medal Standings

Problem Description

After a sports meet, the medal standings of all participating countries must be compiled. Each country has a name, and a number of gold, silver, and bronze medals. The ranking rules are as follows:

  • Gold medals: more comes first;
  • If gold medals are equal, more silver medals comes first;
  • If silver medals are also equal, more bronze medals comes first;
  • If bronze medals are also equal, order by country name in ascending lexicographic order.

If two countries have exactly the same numbers of gold, silver, and bronze medals, they share the same rank. Subsequent ranks are assigned by the actual position after sorting. For example, after two countries tied at rank 1, the next country is rank 3.

Input Format

The first line contains an integer nn, the number of countries.

The following nn lines each contain a country's information: its name, number of gold medals, number of silver medals, and number of bronze medals. The country name contains no spaces.

Output Format

Output nn lines. Each line has the format: rank name gold silver bronze.

Sample Input

5
China 10 8 5
USA 10 10 3
Japan 8 12 10
Korea 10 10 3
France 5 5 5

Sample Output

1 Korea 10 10 3
1 USA 10 10 3
3 China 10 8 5
4 Japan 8 12 10
5 France 5 5 5

Sample Explanation

There are 55 countries in total. After sorting:

  • Korea and USA both have 1010 gold, 1010 silver, and 33 bronze, so they tie for rank 11. Since "Korea" precedes "USA" lexicographically, Korea is listed first.
  • China has 1010 gold, 88 silver, 55 bronze. Its gold equals Korea's and USA's, but it has fewer silver, so it ranks after them as rank 33.
  • Japan has 88 gold, 1212 silver, 1010 bronze, with fewer gold than the top three, so it is rank 44.
  • France has 55 gold, 55 silver, 55 bronze, the fewest gold, so it is rank 55.

Constraints

1≤n≤100001 \le n \le 10000.