#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<limits.h>
#include<cmath>
#define L(x) (x<<1)
#define R(x) (x<<1 |1)
#define MAX 80000
using namespace std;
long long int cx[4*MAX];
class line
{
public:
long long int x1,x2,y;
line(){};
line(long long int a,long long int b,long long int c):x1(a),x2(b),y(c)
{}
bool operator <(line b)const
{
return y<b.y;
}
}lines[4*MAX];
struct node
{
int l,r;
long long int cover;
}a[MAX*4];
void build(int t, int l, int r)
{
a[t].l=l;
a[t].r=r;
a[t].cover=0;
if(r-l==1)return ;
int mid=(l+r)/2;
build(L(t),l,mid);
build(R(t),mid,r);
}
void set(int t, line s)
{
if(s.y<a[t].cover)return ;
if(s.x1<=cx[a[t].l]&&s.x2>=cx[a[t].r])
{
a[t].cover=max(s.y,a[t].cover);
return ;
}
if(a[t].r-a[t].l==1)return ;
if(a[t].cover>0)
{
a[L(t)].cover=a[t].cover;
a[R(t)].cover=a[t].cover;
a[t].cover=0;
}
long long int mid=(a[t].r+a[t].l)/2;
if(s.x1<=cx[mid])
set(L(t),s);
if(s.x2>cx[mid])
set(R(t),s);
}
long long int query(int t,long long int l,long long int r)
{
if(a[t].cover>0)
{
return (cx[a[t].r]-cx[a[t].l])*a[t].cover;
}
if(a[t].r-a[t].l==1)return 0;
long long int mid = (a[t].r+a[t].l)/2;
long long int ll=0;
if(l<=mid)
ll+=query(L(t),l,r);
if(r>mid)
ll+=query(R(t),l,r);
return ll;
}
int main()
{
int n,m,i,j;
long long int x1,x2,y;
while(scanf("%d",&n)!=EOF)
{
m=0;
memset(a,0,sizeof(a));
for(i=0;i<n;i++)
{
scanf("%lld%lld%lld",&x1,&x2,&y);
lines[i]=line(min(x1,x2),max(x1,x2),y);
cx[m++]=x1;
cx[m++]=x2;
}
sort(lines,lines+n);
sort(cx,cx+m);
m=unique(cx,cx+m)-cx;
build(1,0,m-1);
for(i=0;i<n;i++)
set(1,lines[i]);
printf("%lld\n",query(1,0,m-1));
}
return 0;
}