#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char buf[10000000], *ptr = buf - 1;
inline int readint(){
int n = 0;
char ch = *++ptr;
while(ch < ‘0‘ || ch > ‘9‘) ch = *++ptr;
while(ch <= ‘9‘ && ch >= ‘0‘){
n = (n << 1) + (n << 3) + ch - ‘0‘;
ch = *++ptr;
}
return n;
}
const int maxn = 1000000 + 10, maxm = 1000 + 10;
struct Node{
int s, e, p;
Node(){}
Node(int _s, int _e, int _p): s(_s), e(_e), p(_p){}
bool operator < (const Node &x) const {
return e < x.e;
}
}a[maxm];
int dp[maxn] = {0};
int main(){
freopen("in.txt", "r", stdin);
fread(buf, sizeof(char), sizeof(buf), stdin);
int N, M, R;
N = readint();
M = readint();
R = readint();
for(int i = 1; i <= M; i++){
a[i].s = readint();
a[i].e = readint();
a[i].p = readint();
}
sort(a + 1, a + M + 1);
int time = 0, ans = 0;
for(int i = 1; i <= M; i++){
while(time <= a[i].s){
dp[time + 1] = max(dp[time], dp[time + 1]);
time++;
}
if(a[i].e + R >= N)
ans = max(ans, dp[a[i].s] + a[i].p);
else dp[a[i].e + R] = max(dp[a[i].e + R], dp[a[i].s] + a[i].p);
}
for(int i = 0; i < N; i++)
ans = max(ans, dp[i]);
printf("%d\n", ans);
return 0;
};