#include #define LL long long #define FOR(i,c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++) #define F first #define S second using namespace std; const LL mod = 1e9 + 7; template T gcd(T a, T b) { return b == 0?a: gcd(b, a % b); } template T LCM(T a, T b) { return a*(b/gcd(a, b)); } template T expo(T b, S e, const T &m){if(e <= 1)return e == 0?1: b;\ return (e&1) == 0?expo((b*b)%m, e>>1, m): (b*expo((b*b)%m, e>>1, m))%m;} template T expo(T b, S e){if(e <= 1)return e == 0?1: b;\ return (e&1) == 0?expo((b*b), e>>1): (b*expo((b*b), e>>1));} template T modinv(T a, S mod) { return expo(a, mod-2, mod); } template std::ostream& operator<<(std::ostream &os, const std::pair &t) { os<<"("< std::ostream& operator<<(std::ostream &os, const std::vector &t) { os<<"["; FOR(it,t) { if(it != t.begin()) os<<", "; os<<*it; } os<<"]"; return os; } #define gc getchar_unlocked template void in(T &x) { T c = gc(); while(((c < 48) || (c > 57)) && (c!='-')) c = gc(); bool neg = false; if(c == '-') neg = true; x = 0; for(;c < 48 || c > 57;c=gc()); for(;c > 47 && c < 58;c=gc()) x = (x*10) + (c - 48); if(neg) x = -x; } const int MAXN = 2e5 + 3; int n, x, y; struct city { int a, b, h; LL val; int idx; bool operator<(const city &other) const { return h < other.h; } } data[MAXN]; LL dp[MAXN]; LL res = 0; int main() { in(n), in(x), in(y); for(int i = 0; i < n; i++) { in(data[i].a), in(data[i].b), in(data[i].h), in(data[i].val); data[i].idx = i; } sort(data, data + n); for(int i = 0; i < n; i++) { dp[i] = data[i].val; for(int j = i - 1; j >= 0; j--) { if(abs(data[i].a - data[j].a) <= x and abs(data[i].b - data[j].b) <= y and data[i].h > data[j].h) { dp[i] = max(dp[i], dp[j] + data[i].val); } } res = max(res, dp[i]); } printf("%lld\n", res); return 0; }