#include #include #include #include #include #include #include using namespace std; char a[128], b[128], ga, gb; map score, goluri; set countries; struct nod { string name; int score, goals; nod(){}; nod(string n, int s, int g) { name = n; score = s; goals = g; } }; struct cmp { bool operator()(const nod &a, const nod &b) const { if (a.score > b.score) return true; if (a.score == b.score && a.goals > b.goals) return true; if (a.score == b.score && a.goals == b.goals) return a.name < b.name; return false; } }; vector v; int main() { //freopen ("b.in", "r", stdin); while (scanf ("%s %s %d %d", &a, &b, &ga, &gb) == 4) { goluri[a] += ga; goluri[b] += gb; if (ga == gb) score[a] += 1, score[b] += 1; else if (ga > gb) score[a] += 3; else score[b] += 3; countries.insert(a); countries.insert(b); memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); } for (set::iterator it = countries.begin(); it != countries.end(); ++it) v.push_back(nod(*it, score[*it], goluri[*it] ) ); //printf ("%s %d\n", it->first, it->second); sort(v.begin(), v.end(), cmp()); for (int i = 0; i < v.size(); ++i) printf ("%s\n", v[i].name.c_str()); }