#include #include #include #include #include #include #include using namespace std; using PSI = pair; int main() { int n, n0, m, s; string tag; map tags; cin >> n; for (int i = 0; i < n; i++) { cin >> n0 >> m >> s; for (int j = 0; j < m; j++) { cin >> tag; tags[tag] += s; } } vector ranking(tags.begin(), tags.end()); sort(ranking.begin(), ranking.end(), [](PSI &a, PSI &b) { if (a.second == b.second) { return a.first < b.first; } else { return a.second > b.second; } }); if (ranking.size() > 10) { ranking.erase(ranking.begin() + 10, ranking.end()); } for (auto p: ranking) { cout << p.first << " " << p.second << endl; } return 0; }