#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
const long double PI = 3.14159265358979;
long long binpow(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
bool parity(long long x, long long y) {
  bool f = ((x ^ y) < 0);
  return !f;
}
string getBase(long long x, long long b) {
  string ans;
  while (x) {
    ans += ('0' + x % b);
    x /= b;
  }
  return ans;
}
long long dp[2][150010];
long long a[310];
long long b[310];
long long t[310];
long long maxval[150010];
long long pref[150010];
long long suffix[150010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m, d;
  cin >> n >> m >> d;
  for (long long i = 1; i <= (m); i++) {
    cin >> a[i] >> b[i] >> t[i];
  }
  for (long long i = 1; i <= (m); i++) {
    for (long long j = 1; j <= (n); j++) {
      if (i == 1)
        dp[i & 1][j] = b[i] - abs(j - a[i]);
      else {
        long long currsize = d * (t[i] - t[i - 1]);
        long long take;
        if ((j - currsize >= 1) and (j + currsize <= n))
          take = dp[(i - 1) & 1][maxval[j - currsize]];
        else if ((j - currsize) < 1)
          take = pref[min(n, j + currsize)];
        else if ((j + currsize) > n)
          take = suffix[max(1LL, j - currsize)];
        dp[i & 1][j] = take + b[i] - abs(j - a[i]);
      }
    }
    if (i == m) break;
    long long currsize = t[i + 1] - t[i];
    currsize *= 2 * d;
    currsize++;
    currsize = min(n, currsize);
    deque<long long> dq;
    for (int j = 1; j < currsize; j++) {
      if (dq.empty()) {
        dq.push_back(j);
        continue;
      }
      while (!dq.empty() and dp[i & 1][j] >= dp[i & 1][dq.back()])
        dq.pop_back();
      dq.push_back(j);
    }
    long long cnt = 1;
    for (int j = currsize; j <= n; j++) {
      if (dq.empty()) {
        dq.push_back(j);
        maxval[cnt++] = dq.front();
        continue;
      }
      if (dq.front() <= (j - currsize)) dq.pop_front();
      while (!dq.empty() and dp[i & 1][j] >= dp[i & 1][dq.back()])
        dq.pop_back();
      dq.push_back(j);
      maxval[cnt++] = dq.front();
    }
    pref[1] = dp[i & 1][1];
    for (int j = 2; j <= n; j++) pref[j] = max(pref[j - 1], dp[i & 1][j]);
    suffix[n] = dp[i & 1][n];
    for (int j = n - 1; j >= 1; j--)
      suffix[j] = max(suffix[j + 1], dp[i & 1][j]);
  }
  long long ans = -1e17;
  for (long long i = 1; i <= (n); i++) {
    ans = max(dp[m & 1][i], ans);
  }
  cout << ans << '\n';
  return 0;
}
