#include #include #include int main() { int N; std::cin >> N; std::unordered_map profit_with_crane; long long profit = 0; while(N--) { int M; std::cin >> M; std::unordered_map cranes; while (M--) { int id, price; std::cin >> id >> price; cranes[id] = price; } for (const auto &crane : cranes) { if (profit_with_crane.count(crane.first)) profit = std::max(profit, profit_with_crane[crane.first] + crane.second); } for (const auto &crane : cranes) { if (!profit_with_crane.count(crane.first)) profit_with_crane[crane.first] = profit - crane.second; else profit_with_crane[crane.first] = std::max(profit_with_crane[crane.first], profit - crane.second); } } std::cout << profit << '\n'; return 0; }