#include #include #include #include #include #define ll long long #define Maxn 100010 using namespace std; ll a[Maxn]; pair pa[Maxn]; vector > d; int main() { int t,n; ll l,r,L,R; cin>>t; while(t--){ cin>>n>>l>>r; for(int i=0;i=R){ d.push_back(make_pair(L,R)); L=pa[i].first,R=pa[i].second; } else R=max(R,pa[i].second); } d.push_back(make_pair(L,R)); ll ans=0; for(int i=0;i