#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std ;
struct data {
long long left , right , height ;
data() {}
data(long long _left , long long _right, long long _height ) {
left = _left , right = _right , height = _height ;
}
};
data arr[40000+5] ;
long long Tree[160000+5] ;
vector<long long>V ;
long long h ;
int l , r ;
void propagate( int nd , int i , int j ) {
if( j-i > 1 && Tree[nd] > 0 ) {
Tree[nd<<1] = h ;
Tree[(nd<<1)+1] = h ;
Tree[nd] = 0; ;
}
}
void build( int nd , int st , int en ) {
Tree[nd] = 0/*data(st,en,0)*/ ;
if( st+1 == en )return ;
build( (nd<<1) , st , (st+en)>>1 );
build( (nd<<1)+1 , (st+en)>>1 , en );
}
void update( int nd , int st , int en ) {
propagate(nd,st,en) ;
if( st == en ) return ;
if( st > r || en < l ) return ;
if( st>=l && en <= r ) {
Tree[nd] = max( Tree[nd] , h ) ;
return ;
}
if( st+1 == en ) return ;
update( (nd<<1) , st , (st+en)>>1 );
update( (nd<<1)+1 , (st+en)>>1 , en );
}
long long query( int nd , int st , int en ) {
propagate(nd,st,en) ;
if( st == en ) return 0 ;
if( en-st == 1 ) {
long long ans = (V[en]-V[st])*Tree[nd] ;
return ans ;
}
return query( (nd<<1) , st , (st+en)>>1 )
+query( (nd<<1)+1 , (st+en)>>1 , en );
}
int main() {
int n ;
scanf("%lld",&n);
for(int i = 0; i < n ; i++ ) {
scanf("%lld%lld%lld",&arr[i].left,&arr[i].right,&arr[i].height) ;
V.push_back(arr[i].left) ;
V.push_back(arr[i].right) ;
}
sort( V.begin() , V.end() ) ;
V.erase(unique(V.begin(),V.end()),V.end()) ;
build(1,0,V.size()-1);
for(int i = 0 ; i < n ; i++ ) {
l = upper_bound(V.begin(),V.end(),arr[i].left) - V.begin();
r = upper_bound(V.begin(),V.end(),arr[i].right) - V.begin();
h = arr[i].height ;
l--,r--;
update( 1 , 0 , V.size()-1 ) ;
}
cout << query( 1 , 0 , V.size()-1) << "\n" ;
return 0 ;
}
I2luY2x1ZGU8aW9zd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