Welcome to ZOJ
 Problem Sets Information Select Problem Runs Ranklist
ZOJ Problem Set - 3680
E - Cup 1

Time Limit: 3 Seconds      Memory Limit: 65536 KB

The 2012 European Football Championship is underway now. But the UEFA (Union of European Football Association) has modified the rules of upgrading in group round robin. Because of the intricate rules, some commentators cannot understand clearly. They want to find a program to help them. There are N teams in a group, and each team must compete with all other teams. On the other hand, there are N*(N-1)/2 matches.

Rules:

1.If a team wins one match, they can get 3 points. And a tie can get 1 point, lose cannot get the point. The team who has higher point ranks more ahead.
2.If there is two or more teams have the same point, they will rank by following rules.

• a) Higher number of points obtained in the matches played between the teams which have same point;
• b) Superior goal difference resulting from the matches played between the teams which have same point;
• c) Higher number of goals scored in the matches played between the teams which have same point;
• d) If, after having applied criteria a) to c), two or more teams still have an equal ranking, criteria a) to c) are reapplied exclusively to the matches between the two or more teams in question to determine the final rankings of the two teams. If this procedure does not lead to a decision, criteria e) to g) apply in the order given;
• e) superior goal difference in all group matches;
• f) higher number of goals scored in all group matches;
• g) position in the UEFA national team coefficient ranking system.
Now, give you all of matches of one group and UEFA national team coefficient ranking. Please output the rank of all teams.We assume that there aren't two or more teams have the same ranking.

#### Input

There are multiple test cases(no more than 100). For each test case:
The first line contain one integer N(4 ≤ N ≤ 500), the number of teams in group.And in next N*(N-1)/2 lines, the format of each line is s1 p1:p2 s2, s1,s2 are strings that is the name of two teams(no two teams have same name), p1,p2(0 ≤ p1,p2 ≤ 10) are two integers which are the goals of team1 and team2.
Next line contains an integer M(N ≤ M ≤ 1000), the number of all teams. Next M lines the UEFA national team coefficient ranking. Each line contain a string that is name of team. The ith line is ranking ith. We assume that if a name included in a group, it must be included in this M lines.

#### Output

In each test case, output the name of teams in order. There is a blank between two test cases.

```4
ESP 1:1 ITA
ITA 1:1 HRV
HRV 3:1 IRL
IRL 0:4 ESP
ITA 2:0 IRL
ESP 1:0 HRV
4
ESP
HRV
ITA
IRL

4
ESP 1:1 ITA
ITA 1:1 HRV
HRV 3:1 IRL
IRL 0:4 ESP
ITA 2:0 IRL
ESP 2:2 HRV
4
ESP
HRV
ITA
IRL
```

```ESP
ITA
HRV
IRL

ESP
HRV
ITA
IRL
```

#### HINT

1.ESP has 7 points, ITA has 5 points, HRV has 4 points, IRL has 0 point.

2.ESP, ITA, HRV all have 5 points and 0 superior goal with each other. But ESP and HRV have 3(1+2) total goals and ITA only has 2(1+1) total goals.And ESP is better than HRV in UEFA national team coefficient ranking system.

Author: ZHOU, Xiao
Contest: ZOJ Monthly, January 2013
Submit    Status