#include using namespace std; template class dynamic_segtree { public: dynamic_segtree(size_t n) : n(n), root(nullptr) {} void set(size_t p, S x) { assert(p < n); set(root, 0, n, p, x); } S get(size_t p) const { assert(p < n); return get(root, 0, n, p); } S prod(size_t l, size_t r) const { assert(l <= r && r <= n); return prod(root, 0, n, l, r); } S all_prod() const { return root ? root->product : e(); } void reset(size_t l, size_t r) { assert(l <= r && r <= n); return reset(root, 0, n, l, r); } template size_t max_right(size_t l) const { return max_right(l, [](S x) { return f(x); }); } template size_t max_right(size_t l, const F& f) const { assert(l <= n); S product = e(); assert(f(product)); return max_right(root, 0, n, l, f, product); } template size_t min_left(size_t r) const { return min_left(r, [](S x) { return f(x); }); } template size_t min_left(size_t r, const F& f) const { assert(r <= n); S product = e(); assert(f(product)); return min_left(root, 0, n, r, f, product); } private: struct node; using node_ptr = std::unique_ptr; struct node { size_t index; S value, product; node_ptr left, right; node(size_t index, S value) : index(index), value(value), product(value), left(nullptr), right(nullptr) {} void update() { product = op(op(left ? left->product : e(), value), right ? right->product : e()); } }; const size_t n; node_ptr root; void set(node_ptr& t, size_t a, size_t b, size_t p, S x) const { if (!t) { t = std::make_unique(p, x); return; } if (t->index == p) { t->value = x; t->update(); return; } size_t c = (a + b) >> 1; if (p < c) { if (t->index < p) std::swap(t->index, p), std::swap(t->value, x); set(t->left, a, c, p, x); } else { if (p < t->index) std::swap(p, t->index), std::swap(x, t->value); set(t->right, c, b, p, x); } t->update(); } S get(const node_ptr& t, size_t a, size_t b, size_t p) const { if (!t) return e(); if (t->index == p) return t->value; size_t c = (a + b) >> 1; if (p < c) return get(t->left, a, c, p); else return get(t->right, c, b, p); } S prod(const node_ptr& t, size_t a, size_t b, size_t l, size_t r) const { if (!t || b <= l || r <= a) return e(); if (l <= a && b <= r) return t->product; size_t c = (a + b) >> 1; S result = prod(t->left, a, c, l, r); if (l <= t->index && t->index < r) result = op(result, t->value); return op(result, prod(t->right, c, b, l, r)); } void reset(node_ptr& t, size_t a, size_t b, size_t l, size_t r) const { if (!t || b <= l || r <= a) return; if (l <= a && b <= r) { t.reset(); return; } size_t c = (a + b) >> 1; reset(t->left, a, c, l, r); reset(t->right, c, b, l, r); t->update(); } }; using S = long long; S op(S a, S b){ return max(a, b); } S e(){ return 0; }; int main(){ long long n, s, h; cin >> n >> s >> h; vector x(n), y(n), z(n); for(int i = 0; i < n; i++){ cin >> x[i] >> y[i] >> z[i]; } vector ch; for(int i = 0; i < n; i++){ ch.push_back(x[i]); ch.push_back(y[i]); ch.push_back(x[i]-s); ch.push_back(y[i]-s); ch.push_back(x[i]-h); ch.push_back(y[i]-h); ch.push_back(x[i]+s+h); ch.push_back(y[i]+s+h); ch.push_back(x[i]+s-h); ch.push_back(y[i]+s-h); ch.push_back(x[i]-s+h); ch.push_back(y[i]-s+h); ch.push_back(x[i]-s-h); ch.push_back(y[i]-s-h); } sort(ch.begin(), ch.end()); dynamic_segtree d(1LL<<31); int pz = 3; if(n < 150000) pz = 4; if(n < 100000) pz = 5; if(n < 50000) pz = 8; vector> p(pz); vector sum(pz); for(auto a:ch){ if(a < 0) continue; if(a >= (1LL<<31)) continue; long long cnt = 0; for(int i = 0; i < pz; i++){ while(a-(s+h)*(i+1) > x[p[i].first] && p[i].first < n){ sum[i] -= z[p[i].first]; p[i].first++; } while(a-(s+h)*(i+1)+s >= y[p[i].second] && p[i].second < n){ sum[i] += z[p[i].second]; p[i].second++; } cnt += sum[i]; long long u = d.prod(0, max(0LL, a-(s+h)*(i+1))) + cnt; d.set(a, max(d.get(a), u)); } } cout << d.prod(0, 1LL<<31) << endl; }