#include <cstdio>
#include <climits>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long lint;
int main()
{
int N, M, D;
int a[1000], b[1000], t[1000];
lint dp[2][300001];
scanf("%d %d %d", &N, &M, &D);
for (int i = 0; i < M; i++){
scanf("%d %d %d", a + i, b + i, t + i);
}
for (int i = 1; i <= N; i++){
dp[0][i] = 0;
}
int p = 1;
int pT = 1;
for (int i = 0; i < M; i++){
deque<int> dq;
lint interval = min((lint)N, (lint)(t[i] - pT) * D);
for (lint j = 1; j <= interval; j++){
while (dq.size() && dp[1 - p][dq[dq.size() - 1]] <= dp[1 - p][(int)j]) dq.pop_back();
dq.push_back((int)j);
}
for (lint j = 1; j <= (lint)N; j++){
lint k = j + interval;
if (k <= (lint)N){
while (dq.size() && dp[1 - p][dq[dq.size() - 1]] <= dp[1 - p][(int)k]) dq.pop_back();
dq.push_back((int)k);
}
dp[p][j] = dp[1 - p][dq[0]] + (lint)(b[i] - abs(a[i] - j));
while (dq.size() && dq[0] <= (int)(j - interval)) dq.pop_front();
}
pT = t[i];
p = 1 - p;
}
lint ans = LLONG_MIN;
for (int i = 1; i <= N; i++)
ans = max(ans, dp[1 - p][i]);
printf("%I64d\n", ans);
return (0);
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNsaW1pdHM+CiNpbmNsdWRlIDxkZXF1ZT4KI2luY2x1ZGUgPGFsZ29yaXRobT4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsaW50OwoKaW50IG1haW4oKQp7CiAgICBpbnQgTiwgTSwgRDsKICAgIGludCBhWzEwMDBdLCBiWzEwMDBdLCB0WzEwMDBdOwogICAgbGludCBkcFsyXVszMDAwMDFdOwogICAgCiAgICBzY2FuZigiJWQgJWQgJWQiLCAmTiwgJk0sICZEKTsKICAgIAogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBNOyBpKyspewogICAgICAgIHNjYW5mKCIlZCAlZCAlZCIsIGEgKyBpLCBiICsgaSwgdCArIGkpOwogICAgfQogICAgCiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBOOyBpKyspewogICAgICAgIGRwWzBdW2ldID0gMDsKICAgIH0KICAgIAogICAgaW50IHAgPSAxOwogICAgaW50IHBUID0gMTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgTTsgaSsrKXsKICAgICAgICBkZXF1ZTxpbnQ+IGRxOwogICAgICAgIGxpbnQgaW50ZXJ2YWwgPSBtaW4oKGxpbnQpTiwgKGxpbnQpKHRbaV0gLSBwVCkgKiBEKTsKICAgICAgICAKICAgICAgICBmb3IgKGxpbnQgaiA9IDE7IGogPD0gaW50ZXJ2YWw7IGorKyl7CiAgICAgICAgICAgIHdoaWxlIChkcS5zaXplKCkgJiYgZHBbMSAtIHBdW2RxW2RxLnNpemUoKSAtIDFdXSA8PSBkcFsxIC0gcF1bKGludClqXSkgZHEucG9wX2JhY2soKTsKICAgICAgICAgICAgZHEucHVzaF9iYWNrKChpbnQpaik7CiAgICAgICAgfQogICAgICAgIAogICAgICAgIGZvciAobGludCBqID0gMTsgaiA8PSAobGludClOOyBqKyspewogICAgICAgICAgICBsaW50IGsgPSBqICsgaW50ZXJ2YWw7CiAgICAgICAgICAgIGlmIChrIDw9IChsaW50KU4pewogICAgICAgICAgICAgICAgd2hpbGUgKGRxLnNpemUoKSAmJiBkcFsxIC0gcF1bZHFbZHEuc2l6ZSgpIC0gMV1dIDw9IGRwWzEgLSBwXVsoaW50KWtdKSBkcS5wb3BfYmFjaygpOwogICAgICAgICAgICAgICAgZHEucHVzaF9iYWNrKChpbnQpayk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZHBbcF1bal0gPSBkcFsxIC0gcF1bZHFbMF1dICsgKGxpbnQpKGJbaV0gLSBhYnMoYVtpXSAtIGopKTsKICAgICAgICAgICAgd2hpbGUgKGRxLnNpemUoKSAmJiBkcVswXSA8PSAoaW50KShqIC0gaW50ZXJ2YWwpKSBkcS5wb3BfZnJvbnQoKTsKICAgICAgICB9CiAgICAgICAgcFQgPSB0W2ldOwogICAgICAgIHAgPSAxIC0gcDsKICAgIH0KICAgIAogICAgbGludCBhbnMgPSBMTE9OR19NSU47CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBOOyBpKyspCiAgICAgICAgYW5zID0gbWF4KGFucywgZHBbMSAtIHBdW2ldKTsKICAgIAogICAgcHJpbnRmKCIlSTY0ZFxuIiwgYW5zKTsKICAgIAogICAgcmV0dXJuICgwKTsKfQ==