#include using namespace std; map > M; struct Team { string n; int g; int p; inline bool operator<(const struct Team& other) const { if (p > other.p) { return true; } if (p == other.p) { if (g > other.g) { return true; } if (g == other.g) { if (n < other.n) { return true; } } } return false; } }; vector V; void init(string s) { if (!M.count(s)) { M[s] = make_pair(0, 0); } } int main() { #if 0 freopen("test.in", "r", stdin); #endif string tA, tB; int gA, gB; int n; while (cin >> tA >> tB >> gA >> gB) { init(tA); init(tB); if (gA > gB) { M[tA].second += 3; } else if (gA < gB) { M[tB].second += 3; } else { M[tA].second += 1; M[tB].second += 1; } M[tA].first += gA; M[tB].first += gB; } for (map >::iterator it = M.begin(); it != M.end(); it++) { Team t; t.n = it->first; t.g = it->second.first; t.p = it->second.second; V.push_back(t); } sort(V.begin(), V.end()); for (vector::iterator it = V.begin(); it != V.end(); it++) { cout << it->n << endl; //cout << it->n << " " << it-> p << " " << it->g << endl; } return 0; }