#include #include #include #include #include using namespace std; struct city { int x, y, h, p; city(int x = 0, int y = 0, int h = 0, int p = 0): x(x), y(y), h(h), p(p) { } bool operator < (const city& oth) { return h < oth.h; } }; const int MAX_N = 200005; int n, x, y; long long dp[MAX_N]; city c[MAX_N]; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ cin >> n >> x >> y; for (int i = 0; i < n; i++) { cin >> c[i].x >> c[i].y >> c[i].h >> c[i].p; } sort(c, c + n); for (int i = 0; i < n; i++) { dp[i] = max(0, c[i].p); for (int j = 0; j < i; j++) { if (c[i].h > c[j].h && abs(c[i].x - c[j].x) <= x && abs(c[i].y - c[j].y) <= y) { dp[i] = max(dp[i], dp[j] + c[i].p); } } } long long ans = 0; for (int i = 0; i < n; i++) { ans =max(ans, dp[i]); } cout << ans << endl; return 0; }