rt
code:
#include<bits/stdc++.h>
// #pragma GCC optimize(1,2,3,"Ofast","inline")
#define endl "\n"
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
inline void print(int x){
if(x<0) putchar('-'),x=-x;
if(x>9) print(x/10);
putchar(x%10+'0');
}
// #define int long long
int n;
struct node{int d,h,bh;bool flag;}p[80005];
struct node1{
int bh,h;
bool operator<(const node1& b)const{
return h<b.h;
}
};
priority_queue<node1>q;
bool cmp(node a,node b){
if(a.d==b.d) return a.flag>b.flag;
return a.d<b.d;
}
bool fl[40005];
void solve(){
n=read();
for(int i=1;i<=n;i++){
int a=read(),b=read(),c=read();
p[i*2-1]={a,c,i,0};
p[i*2]={b,c,i,1};
}
sort(p+1,p+n*2+1,cmp);
int now=p[1].d,sum=0;
q.push({p[1].bh,p[1].h});
// cout<<p[1].flag<<" "<<sum<<" "<<p[1].d<<" "<<p[1].h<<" "<<p[1].bh<<" "<<now<<"\n";
for(int i=2;i<=n*2;i++){
node x=p[i];
if(!x.flag){
sum+=q.top().h*(p[i].d-now);
now=p[i].d;
q.push({p[i].bh,p[i].h});
}else{
sum+=q.top().h*(p[i].d-now);
now=p[i].d;
fl[p[i].bh]=1;
while(!q.empty()&&q.top().bh==p[i].bh) q.pop();
}
// cout<<x.flag<<" "<<sum<<" "<<x.d<<" "<<x.h<<" "<<x.bh<<" "<<now<<"\n";
}
cout<<sum;
}
signed main(){
int T=1;
// T=read();
while(T--) solve();
return 0;
}