#include <bits/stdc++.h>
using namespace std;
namespace std {
template <class T>
struct hash<vector<T> > {
  hash<T> fn;
  size_t operator()(const vector<T>& v) const {
    size_t seed = 0;
    for (auto x : v) seed ^= fn(x) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
    return seed;
  }
};
}  // namespace std
template <class K, class V>
ostream& operator<<(ostream& out, const pair<K, V>& v) {
  out << '(' << v.first << ',' << v.second << ')';
  return out;
}
template <class C, class = typename C::iterator>
struct _cprint {
  using type = void;
};
template <>
struct _cprint<string> {};
template <class C, class = typename _cprint<C>::type>
ostream& operator<<(ostream& out, const C& v) {
  for (auto x : v) out << x << ' ';
  return out;
}
template <class C>
inline void chmax(C& x, const C& a) {
  if (x < a) x = a;
}
template <class C>
inline void chmin(C& x, const C& a) {
  if (x > a) x = a;
}
template <class C>
string to_string(const C& x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
template <class C>
C from_string(const string& s) {
  stringstream ss(s);
  C x;
  ss >> x;
  return x;
}
template <class C>
inline C mod(C a, C b) {
  return (a % b + b) % b;
}
vector<string> split(const string& line, char delim = ' ') {
  vector<string> ret;
  stringstream ss(line);
  string s;
  while (getline(ss, s, delim)) ret.push_back(s);
  return ret;
}
long long n, m, d, sumb;
vector<long long> a, b, t;
int main() {
  cin >> n >> m >> d;
  a = b = t = vector<long long>(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> t[i];
    a[i];
    sumb += b[i];
  }
  vector<long long> grid = {0, n + 1}, val = {0, 0};
  for (int i = 0; i < m; i++) {
    auto delta = d * (t[i] - (i == 0 ? 1 : t[i - 1]));
    auto k = min_element((val).begin(), (val).end()) - val.begin();
    grid.insert(grid.begin() + k, grid[k]);
    val.insert(val.begin() + k, val[k]);
    for (int j = 0; j < k + 1; j++) grid[j] -= delta;
    for (int j = k + 1; j < int((grid).size()); j++) grid[j] += delta;
    k = lower_bound((grid).begin(), (grid).end(), a[i]) - grid.begin();
    val.insert(val.begin() + k,
               (val[k] * (a[i] - grid[k - 1]) + val[k - 1] * (grid[k] - a[i])) /
                   (grid[k] - grid[k - 1]));
    grid.insert(grid.begin() + k, a[i]);
    for (int j = 0; j < int((grid).size()); j++) val[j] += abs(grid[j] - a[i]);
  }
  cout << sumb - *min_element((val).begin(), (val).end()) << endl;
}
