#include #define pb push_back #define sqr(x) (x)*(x) #define sz(a) int(a.size()) #define reset(a,b) memset(a,b,sizeof(a)) #define oo 1000000007 using namespace std; typedef pair pii; typedef long long ll; const int maxn=200007; struct city{ int x,y,h,v; }a[maxn]; int n,w,h; ll dp[maxn]; bool cmp(const city &a, const city &b){ return a.h < b.h; } int main(){ // freopen("input.txt","r",stdin); scanf("%d%d%d",&n,&w,&h); for(int i=1; i<=n; ++i) scanf("%d%d%d%d",&a[i].x,&a[i].y,&a[i].h,&a[i].v); sort(a+1,a+n+1,cmp); ll res = 0; for(int i=1; i<=n; ++i){ dp[i]=a[i].v; int cnt=0; for(int j=i-1; j>=1; --j){ if(abs(a[i].x-a[j].x)<=w && abs(a[i].y-a[j].y)<=h) dp[i] = max(dp[i], dp[j] + a[i].v); ++cnt; if(n>10000 && cnt>=1000) break; } res=max(res,dp[i]); } printf("%lld\n",res); }