In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of November 2nd
(this exercise will still be available for submission after that deadline, but without couting towards your grade)
[to understand the context of this problem, you should read the class #04 exercise sheet]


[AED016] Football Table

The football league needs your help to compute the final ranking of all teams!

The Problem

Given a list of N teams with their name, number of wins, draws, losses, goals scored and goals against, your task is to produce a ranking table, sorted in decreasing order of points (3 points per win, 1 point per draw). In case of a tie, the teams should come by decreasing order of goal average (difference of goals scored and against). If teams are tied in both points and goal average, they should come by increasing alphabetical order of their names.

Input

The first input line contains an integer N: the amount of teams to consider.

The following N lines give the team details, one per line, in the format NAME WINS DRAWS LOSSES GOALS_SCORED GOALS_AGAINST. The names of the teams will be formed by lowercase letters with no spaces.

Output

The output should contain N lines: the ranking table teams in the required order, in the format NAME POINTS GOAL_AVERAGE

Constraints

The following limits are guaranteed in all the test cases that will be given to your program:

1 ≤ N ≤ 105       Amount of teams
1 ≤ |NAME| ≤ 20       Length of a team name
1 ≤ WINS, DRAWS, LOSSES, GOALS_SCORED, GOALS_AGAINST ≤ 106       The numbers that detail the performance of the team

Example Input Example Output
20
crystalpalace 11 9 18 39 51
everton 11 14 13 59 55
afcbournemouth 11 9 18 45 67
manchesterunited 19 9 10 49 35
tottenham 19 13 6 69 35
arsenal 20 11 7 65 36
liverpool 16 12 10 63 50
swanseacity 12 11 15 42 52
newcastle 9 10 19 44 65
astonvilla 3 8 27 27 76
westham 16 14 8 65 51
leicestercity 23 12 3 68 36
watford 12 9 17 40 50
chelsea 12 14 12 59 53
norwichcity 9 7 22 39 67
southampton 18 9 11 59 41
sunderland 9 12 17 48 62
manchestercity 19 9 10 71 41
stokecity 14 9 15 41 55
westbromwich 10 13 15 34 48
leicestercity 81 32
arsenal 71 29
tottenham 70 34
manchestercity 66 30
manchesterunited 66 14
southampton 63 18
westham 62 14
liverpool 60 13
stokecity 51 -14
chelsea 50 6
everton 47 4
swanseacity 47 -10
watford 45 -10
westbromwich 43 -14
crystalpalace 42 -12
afcbournemouth 42 -22
sunderland 39 -14
newcastle 37 -21
norwichcity 34 -28
astonvilla 17 -49


Algorithms and Data Structures (L.EIC011) 2024/2025
DCC/FCUP & DEI/FEUP - University of Porto