#include<vector> #include<utility> usingnamespace std; intsum_intervals(std::vector<std::pair<int, int>> A){ sort(begin(A), end(A)); longlong res = 0, le = -2147483648ll, ri = -2147483648ll; for(auto [l,r] : A) { if(l < ri) ri = max(ri, r * 1ll); else { res += ri - le; le = l, ri = r; } } res += ri - le; return res; }