#define _USE_MATH_DEFINES #include using namespace std; //template #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(a);i>(b);i--) #define ALL(v) (v).begin(),(v).end() typedef long long int ll; typedef pair P; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } templatevoid Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);} const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2; //template end int main(){ int n,m,a; scanf("%d%d%d",&n,&m,&a); ll dp[100010]={}; vector> vec(100010); rep(i,0,m){ int l,r,p; scanf("%d%d%d",&l,&r,&p); vec[r].push_back({l,p}); } ll maxx=0; rep(i,1,n+1){ dp[i]=maxx-a; for(P p:vec[i]){ int l=p.first,w=p.second; chmax(dp[i],dp[l-1]+w-(i==n?0:a)); } chmax(maxx,dp[i]); } printf("%lld\n",maxx); return 0; }