#include using namespace std; typedef pair pii; typedef long long ll; const int MAX = 2e5; int n, X, Y; ll res; struct NodePoint{ int x, y, h; ll p; } points[MAX + 1]; struct NodeIT1{ ll mx; NodeIT1 *lef, *rig; NodeIT1() : lef(NULL), rig(NULL), mx(0) {} static int get_mx(NodeIT1*const& root){ if (root == NULL) return 0; return root->mx; } static void insert(const int& pos, const ll& val, NodeIT1 *&root, const int& lef = 1, const int& rig = MAX){ if (root == NULL) root = new NodeIT1; if (lef == rig){ root->mx = max(root->mx, val); return; } int mid = (lef + rig) >> 1; if (pos <= mid) insert(pos, val, root->lef, lef, mid); else insert(pos, val, root->rig, mid + 1, rig); root->mx = max(get_mx(root->lef), get_mx(root->rig)); } static ll get(const int& u, const int& v, NodeIT1 *&root, const int& lef = 1, const int& rig = MAX){ if (root == NULL) return 0; if (lef == u && rig == v) return root->mx; int mid = (lef + rig) >> 1; if (v <= mid) return get(u, v, root->lef, lef, mid); else if (u > mid) return get(u, v, root->rig, mid + 1, rig); else return max(get(u, mid, root->lef, lef, mid), get(mid + 1, v, root->rig, mid + 1, rig)); } }; struct NodeIT2{ NodeIT1 *child; NodeIT2 *lef, *rig; NodeIT2() : lef(NULL), rig(NULL), child(NULL) {} static void insert(const pii& pos, const ll& val, NodeIT2 *&root, const int& lef = 1, const int& rig = MAX){ if (root == NULL) root = new NodeIT2; NodeIT1::insert(pos.second, val, root->child); if (lef == rig) return; int mid = (lef + rig) >> 1; if (pos.first <= mid) insert(pos, val, root->lef, lef, mid); else insert(pos, val, root->rig, mid + 1, rig); } static ll get(const pii& u, const pii& v, NodeIT2 *&root, const int& lef = 1, const int& rig = MAX){ if (root == NULL) return 0; if (lef == u.first && rig == v.first) return NodeIT1::get(u.second, v.second, root->child); int mid = (lef + rig) >> 1; if (v.first <= mid) return get(u, v, root->lef, lef, mid); else if (u.first > mid) return get(u, v, root->rig, mid + 1, rig); else return max(get(u, pii(mid, v.second), root->lef, lef, mid), get(pii(mid + 1, u.second), v, root->rig, mid + 1, rig)); } }; NodeIT2 *root; int main(){ //freopen("in.txt", "r", stdin); scanf("%d %d %d", &n, &X, &Y); for (int i = 1; i <= n; ++i) scanf("%d %d %d %lld", &points[i].x, &points[i].y, &points[i].h, &points[i].p); sort(points + 1, points + 1 + n, [](const NodePoint& a, const NodePoint& b)->bool{ return a.h < b.h; }); for (int i = 1, j = 1; i <= n; ++i){ while (j < i && points[j].h < points[i].h){ NodeIT2::insert(pii(points[j].x, points[j].y), points[j].p, root); ++j; } points[i].p += NodeIT2::get(pii(max(1, points[i].x - X), max(1, points[i].y - Y)), pii(min(MAX, points[i].x + X), min(MAX, points[i].y + Y)), root); res = max(res, points[i].p); } printf("%lld", res); return 0; }