Soccer Championship

A sports journalist has gained access to the results of a soccer league and wants to calculate the final standings. In this league, three points are given to the team winning a match, one point for each team in a draw, and none for a defeated team. The standing of each team in the league shall be determined as follows:

  1. greatest number of points obtained in all matches;
  2. greatest goal difference in all matches (i.e., goals scored minus goals against); 3. greatest number of goals scored in all matches; and
  3. greatest number of goals scored playing as visitor in all matches. If two or more teams are equal on the basis of the above criteria, their rankings shall be determined by lexicographic order on the team’s name (characters are sorted by ASCII value). The journalist also wants to determine the number of occurrences of the classic sports journalist’s paradox, namely, the number of matches in which the team losing the game has a better final standing than the one winning that game. Input The input consists of several test cases. The first line of each test case contains a natural number M indicating the number of matches (1 ≤ M ≤ 64). Each one of the next M lines contains the results of the matches in the format L X vs. Y V where X is the number of goals scored by the local team with name L (0 ≤ X ≤ 32, 1 ≤ |L| ≤ 100) and Y isthenumberofgoalsscoredbythevisitorteamwithnameV (0≤Y ≤32,1≤|V|≤100,V ̸=L). You can assume that each team name consists of uppercase characters ‘A’..‘Z’, digits ‘0’..‘9’, periods (.), and can contain blanks. However, blanks do not appear at the beginning or end of a name. Output For each test case, print a line with the text The paradox occurs X time(s). where X is the number of paradoxes found by the end of the league. This line should be followed by the final standings in the format
  4. N ame1
  5. N ame2 ... N. NameN where N is the number of teams in the league and such that the i-th place in the final standings is occupied by the team with name Namei.

2/2 Sample Input 13 B. DORTMUND 2 vs. 2 REAL MADRID SP. PORTUGAL 2 vs. 0 LEGIA SP. PORTUGAL 1 vs. 2 B. DORTMUND REAL MADRID 5 vs. 1 LEGIA B. DORTMUND 1 vs. 0 SP. PORTUGAL LEGIA 3 vs. 3 REAL MADRID MONACO 3 vs. 0 CSKA M. SP. PORTUGAL 1 vs. 2 REAL MADRID B. DORTMUND 8 vs. 4 LEGIA REAL MADRID 2 vs. 2 B. DORTMUND LEGIA 1 vs. 0 SP. PORTUGAL MONACO 1 vs. 0 SP. PORTUGAL CSKA M. 1 vs. 0 B. DORTMUND 2 TEAM 1 4 vs. 2 TEAM 2 TEAM 2 2 vs. 0 TEAM 1 Sample Output The paradox occurs 2 time(s).

  1. B. DORTMUND
  2. REAL MADRID
  3. MONACO
  4. LEGIA
  5. CSKA M.
  6. SP. PORTUGAL The paradox occurs 1 time(s).
  7. TEAM 2
  8. TEAM 1