#include #include #include #include using namespace std; map M; struct team { string name; int points; int totGoals; } x[5]; int teamCnt = 0; char team1[111], team2[111]; int findId(string xx) { if (M.find(xx) != M.end()) return M[xx]; x[++teamCnt].name = xx; return M[xx] = teamCnt; } inline bool comp(team A, team B) { if (A.points == B.points) { if (A.totGoals == B.totGoals) return A.name < B.name; return A.totGoals < B.totGoals; } return A.points < B.points; } int main() { for (int i = 1; i <= 6; ++i) { int xx, yy; scanf("%s %s %d %d\n", &team1, &team2, &xx, &yy); string t1 = string(team1); string t2 = string(team2); int idx1 = findId(t1); int idx2 = findId(t2); if (xx == yy) { x[idx1].points += 1; x[idx2].points += 1; } if (xx > yy) x[idx1].points += 3; if (xx < yy) x[idx2].points += 3; x[idx1].totGoals += xx; x[idx2].totGoals += yy; } sort(x + 1, x + 5, comp); for (int i = 4; i >= 1; --i) { for (int j = 0; j < x[i].name.size(); ++j) printf("%c", x[i].name[j]); printf("\n"); } return 0; }