#include #include #include #include using namespace std; //1-indexed #include template struct BIT{ int n; vectorbit; BIT(int n_=0,T a=0):n(n_),bit(n_+1,a){} T sum(int i) { T ans=0; for(;i>0;i-=i&-i)ans+=bit[i]; return ans; } void add(int i,T a) { if(i==0)return; for(;i<=n;i+=i&-i)bit[i]+=a; } }; int n; main() { cin>>n; vector > >a; vectorid; for(int i=0;i>u>>v>>w; a.push_back(make_pair(u,make_pair(v,w))); id.push_back(v); id.push_back(w); } mapM; int sz=0; sort(id.begin(),id.end()); for(int i=0;iP(sz); long ans=0; for(int i=0;i