**I think that problem statement of this problem doesn't agree with input and output data but somehow one person have solved it.**

Here is how the classification is made:

1. For a win 3 points will be awarded; for a tie, 1 point; for a defeat, 0 points

2. For establishing the final places, the following criteria will be applied, in descending order of priority:

* Number of points

* Goal-Average (difference between goals scored and given)

* Number of wins (victories)

* Number of goals scored

So after the games are taken in account, this parameters are all calculated. Things get interesting when there is more than one team with the same number of points. In that case, a sub-league is considered. You must now imagine that only the games between the tied teams count, and see the new sub-classification. If that does not break the tie (in points) for all the teams, you must do a sub-sub-league for all the teams that are still tied, and so on. There is only one case when a sub-league should not be partitioned. That is when all the teams in that sub-league have the same number of points and obviously, the partition would give the exact same group of teams and parameters. In that cases, teams should be ranked according to the four parameters calculated for that sub-league. If the parameters are not sufficient, then the teams should be considered to be in the same place, and they should appear in alphabetical order.

**Sample input provided in the problem descriprion**

6

portugal grecia 4 1

espanha russia 3 1

portugal russia 3 0

espanha grecia 1 2

portugal espanha 1 3

grecia russia 7 0

**Corresponding sample output**

1 portugal

2 espanha

3 grecia

4 russia

**Explanation of sample input / output according to the problem description**

Looking at the games, we see that "portugal", "espanha" and "grecia" made 6 points, and "russia" made 0 points (which automatically gives them the 4th place). A tie between the first three teams is achieved. A sub-league with only that three teams is then considered but in this sub-league all the three teams have 3 points. This tied group cannot be partitioned further and then the other parameters are considered.Since in that sub-league, "portugal" has the best goal-average, it achieves 1st place. Then comes "spain" (2nd goal-average) and finally "grecia".If necessary, the other parameters would have been taken in account.

**Consider ranking of teams having 3 points:**

portugal grecia 4 1

espanha grecia 1 2

portugal espanha 1 3

**=> total scored / missed**

portugal 5 - 4 (+1)

espanha 4 - 3 (+1)

grecia 3 - 5 (-2)

**=> grecia takes 3rd place**

ans we reconsider ranking again

ans we reconsider ranking again

portugal espanha 1 3

**In that cases, teams should be ranked according to the four parameters calculated for that sub-league.**

Then, we start again from the first parameter again.

Then, we start again from the first parameter again.

espanha 3 pts

portugal 0 pts

**=> final ranking is the following according to the problem description:**

1. espanha

2. portugal

3. grecia

4. russia

**=> but according to the sample output it is:**

1 portugal

2 espanha

3 grecia

4 russia

**Did I miss something or the problem description is wrong?**