#include<bits/stdc++.h>
#define int long long
using namespace std;
int k,n,c,ans;
const int N=2e4+10;
struct que{
int l,r,m;
}q[N];
struct tree{
int l,r,mx,add;
}tr[N*4];
void pushup(int p){
tr[p].mx=max(tr[p*2].mx,tr[p*2+1].mx);
}
void pushdown(int p){
if(tr[p].add){
tr[p*2].add+=tr[p].add;
tr[p*2+1].add+=tr[p].add;
tr[p*2].mx+=tr[p].add;
tr[p*2+1].mx+=tr[p].add;
tr[p].add=0;
}
}
void build(int p,int l,int r){
tr[p].l=l,tr[p].r=r;
if(l==r){
return ;
}
int mid=l+r>>1;
build(p*2,l,mid);
build(p*2+1,mid+1,r);
}
void updata(int p,int x,int y,int k){
if(tr[p].l>=x&&tr[p].r<=y){
tr[p].mx+=k;
tr[p].add+=k;
return ;
}
int mid=tr[p].l+tr[p].r>>1;
pushdown(p);
if(x<=mid){
updata(p*2,x,y,k);
}
if(y>mid){
updata(p*2+1,x,y,k);
}
pushup(p);
}
int query(int p,int x,int y){
if(tr[p].l>=x&&tr[p].r<=y){
return tr[p].mx;
}
int mid=tr[p].r+tr[p].l>>1;
pushdown(p);
int maxn=-INT_MAX;
if(x<=mid){
maxn=query(p*2,x,y);
}
if(y>mid){
maxn=max(maxn,query(p*2+1,x,y));
}
return maxn;
}
bool cmp(que a,que b){
return a.r<b.r;
}
signed main(){
cin>>k>>n>>c;
build(1,1,n);
for(int i=1;i<=k;i++){
cin>>q[i].l>>q[i].r>>q[i].m;
}
sort(q+1,q+1+k,cmp);
for(int i=1;i<=k;i++){
int l=q[i].l,r=q[i].r,m=q[i].m;
int mx=query(1,l,r-1);
int x=min(c-mx,m);
updata(1,l,r-1,x);
ans+=x;
}
cout<<ans;
return 0;
}