/* -*- coding: utf-8 -*- * * 628.cc: No.628 Tagの勢い - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ /* typedef */ typedef map msi; typedef pair pis; typedef vector vpis; /* global variables */ msi tmap; vpis ts; /* subroutines */ bool cmppis(const pis &a, const pis &b) { return (a.first > b.first || (a.first == b.first && a.second < b.second)); } /* main */ int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int no, m, si; cin >> no >> m >> si; for (int j = 0; j < m; j++) { string t; cin >> t; tmap[t] += si; } } for (msi::iterator mit = tmap.begin(); mit != tmap.end(); mit++) ts.push_back(pis(mit->second, mit->first)); sort(ts.begin(), ts.end(), cmppis); for (int i = 0; i < ts.size() && i < 10; i++) cout << ts[i].second << ' ' << ts[i].first << endl; return 0; }