#include #include #include #include #include int main() { std::ifstream f("b"); std::vector x; std::vector y; int l, r; while (f >> l >> r) { x.push_back(l); y.push_back(r); } std::sort(x.begin(), x.end()); std::sort(y.begin(), y.end()); long t = 0; int c = 0; auto p = y.begin(); for (size_t i = 0; i < 4000000; i++) { auto b = std::lower_bound(p, y.end(), x[i]); auto u = std::upper_bound(p, y.end(), x[i]); int c = u - b; t += x[i] * c; p = b; } std::cout << t; return 0; }