#if !defined(__clang__) && defined(__GNUC__) #include #else #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #endif // !defined(__clang__) && defined(__GNUG__) #include #include #include #include #include using namespace std; int main() { int64_t N; std::cin >> N; struct Img { int64_t no; int64_t score; std::vector tags; }; std::vector imgs; for (decltype(N) i = 0; i < N; ++i) { Img t; int64_t m; std::cin >> t.no >> m >> t.score; for (int64_t j = 0; j < m; ++j) { std::string s; std::cin >> s; t.tags.push_back(s); } imgs.push_back(t); } std::map sum; for (auto& img: imgs) { for (auto& t: img.tags) { sum[t] += img.score; } } struct Tags { std::string tag; int64_t score; }; std::vector tags; for (auto& s: sum) { tags.push_back({s.first, s.second}); } std::sort(std::begin(tags), std::end(tags), [](const auto& a, const auto& b) { return a.score == b.score ? a.tag < b.tag : a.score > b.score; }); for (size_t i = 0; i < std::min((size_t)10, tags.size()); ++i) { std::cout << tags[i].tag << " " << tags[i].score << std::endl; } return 0; }