#include <bits/stdc++.h>
using namespace std;
int n, m, d, head, tail;
long long ans1, ans2;
long long dp[2][150100];
struct node {
  int num;
  int val;
} q[150100];
struct fire {
  int a;
  int b;
  int t;
} fi[150100];
int main() {
  while (~scanf("%d%d%d", &n, &m, &d)) {
    ans1 = 0;
    for (int i = 1; i <= m; i++)
      scanf("%d%d%d", &fi[i].a, &fi[i].b, &fi[i].t), ans1 += fi[i].b;
    for (int i = 1; i <= n; i++) dp[0][i] = abs(fi[1].a - i);
    long long k;
    int now = 0;
    for (int j = 2; j <= m; j++) {
      k = 1ll * (fi[j].t - fi[j - 1].t) * d;
      if (k > n) k = n;
      head = tail = 0;
      for (int i = 1; i <= k; i++) {
        while (head < tail && dp[now][i] < q[tail - 1].val) tail--;
        q[tail].val = dp[now][i], q[tail++].num = i;
      }
      for (int i = 1; i <= n; i++) {
        int l, r;
        l = i - k, r = i + k;
        if (l <= 0) l = 1;
        while (head < tail && q[head].num < l) head++;
        if (r <= n) {
          while (head < tail && dp[now][r] < q[tail - 1].val) tail--;
          q[tail].val = dp[now][r], q[tail++].num = r;
        }
        dp[1 - now][i] = q[head].val + abs(fi[j].a - i);
      }
      now = 1 - now;
    }
    ans2 = 1e15;
    for (int i = 1; i <= n; i++) ans2 = min(ans2, dp[now][i]);
    cout << ans1 - ans2 << endl;
  }
  return 0;
}
