// _ // _/_\_ // (O_o) // ~( )~ // (~~~) // / \ #include #define left nadnlassad #define right asdaslknd #define y1 kjdajasjdsas #define nxt accepted #define prev why_would_you_call_when_you_are_high #define pb push_back #define mp make_pair #define mt make_tuple #define f first #define s second #define ll long long #define ld long double #define ull unsigned ll #define hash_t pair #define pii pair #define uint unsigned int #define puu pair #define sqr(x) ((x) * 1LL * (x)) #define vec vector #define sz(v) int(v.size()) #define all(v) v.begin(), v.end() #define endl "\n" #define bits(x) __builtin_popcountll(x) #define forn(i, s, t) for(int i = (int) s; i <= (int) t; i++) #define form(i, t, s) for(int i = (int) t; i >= (int) s; i--) using namespace std; void rf() { #define fname "sparse" #ifdef SONY freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #else //freopen(fname".in", "r", stdin); //freopen(fname".out", "w", stdout); #endif //SONY } const int nx[8] = {2, -2, -2, 2, 1, 1, -1, -1}; const int ny[8] = {1, 1, -1, -1, 2, -2, -2, 2}; const int Nx[4] = {0, 0, -1, 1}; const int Ny[4] = {1, -1, 0, 0}; const ll LINF = (ll) 5e18; const int INF = 1e9 + 7; const int N = 2e5 + 10; const int MAXN = 1e6 + 50; const double EPS = 1e-9, PI = 3.14159265359; inline int get_int() { char x = getchar(); int ret = 0; bool neg = 0; while (!('0' <= x && x <= '9')) { if (x == '-') neg = 1; x = getchar(); } while ('0' <= x && x <= '9') { ret = ret * 10 + x - '0'; x = getchar(); } if (neg) ret *= -1; return ret; } struct sh { int l1, l2, h, pts; }; int n, x, y; sh a[N]; ll dp[N]; bool cmp(sh a, sh b) { return a.h < b.h; } int main() { srand(time(0)); //ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); rf(); cin >> n >> x >> y; for (int i = 0; i < n; i++) cin >> a[i].l1 >> a[i].l2 >> a[i].h >> a[i].pts; sort(a, a + n, cmp); for (int i = 0; i < n; i++) { ll mx = 0; for (int j = 0; j < n; j++) { if (abs(a[i].l1 - a[j].l1) <= x && abs(a[i].l2 - a[j].l2) <= y) { mx = max(mx, dp[j]); } } dp[i] = mx + a[i].pts; } cout << *max_element(dp, dp + n); return 0; }