#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
int N, M, R; // N个小时, M个时间间隔, R个休息时间
const int maxn = 1000 + 24;
struct Cow {
int start;
int end;
int value;
Cow(int s = 0, int e = 0, int v = 0) : start(s), end(e), value(v) {
}
} cows[maxn + 24];
//按开始时间先后排序
inline bool cmp(const Cow& a, const Cow& b) {
return a.start < b.start;
}
int dp[maxn + 24];
void solve()
{
scanf("%d%d%d", &N, &M, &R);
for (int i = 0; i < M; i++) {
scanf("%d%d%d", &cows[i].start, &cows[i].end, &cows[i].value);
cows[i].end += R;
}
sort(cows, cows + M, cmp);
for (int i = 0; i < M; i++)
{
dp[i] = cows[i].value;
for (int j = 0; j < i; j++) {
//前面事件结束时间,如果比当前的事件的开始时间 早
if (cows[j].end <= cows[i].start) {
//dp[i] = max(当前i事件算得的value, 前j个合理事件+当前事件.value)
dp[i] = max(dp[i], dp[j] + cows[i].value);
}
}
}
//此时已经得到 到第i个事件 计算最大的效率
cout << *max_element(dp, dp + M) << endl;
}
int main()
{
solve();
return 0;
}