#include #include #include #include #include #include using namespace std; typedef long long LL; typedef vector VI; #define REP(i,n) for(int i=0, i##_len=(n); i inline void amin(T &x, const T &y) { if (y inline void amax(T &x, const T &y) { if (x void rprintf(const char *fmt, Iter begin, Iter end) { for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); } putchar('\n'); } int N, X, Y; const int MAXN = 200111; struct Data { int a, b, h, s; bool operator<(const Data &y) const { return h < y.h; } } D[MAXN]; LL dp[MAXN]; int main() { scanf("%d%d%d", &N, &X, &Y); REP (i, N) scanf("%d%d%d%d", &D[i].a, &D[i].b, &D[i].h, &D[i].s); sort(D, D+N); REP (i, N) { const Data &d = D[i]; dp[i] = d.s; REP (j, i) if (d.h > D[j].h && abs(d.a - D[j].a) <= X && abs(d.b - D[j].b) <= Y) amax(dp[i], dp[j] + d.s); } printf("%lld\n", *max_element(dp, dp+N+1)); return 0; }