#include using namespace std; typedef long long ll; typedef pair pii; const int N = 100010; int n , x , y; ll dp[N]; struct city{ int lat,lg,h,point; city(){} bool operator<(const city &rhs) const{ return h < rhs.h; } }; city ct[N]; ll calc(int idx){ if(idx == n + 1) return 0; ll &ret = dp[idx]; if(ret != -1) return ret; ll cur = ct[idx].point; ret = cur; for(int i = idx + 1 ; i <= n ; i++){ if(abs(ct[idx].lat - ct[i].lat) <= x && abs(ct[idx].lg - ct[i].lg) <= y){ ret = max(ret , cur + calc(i)); } } return ret; } int main(){ //freopen("input.txt","r",stdin); memset(dp,-1,sizeof dp); scanf("%d%d%d",&n,&x,&y); for (int i = 1; i <= n; ++i){ scanf("%d%d%d%d",&ct[i].lat,&ct[i].lg,&ct[i].h,&ct[i].point); } sort(ct+1,ct+n+1); ll pt = 0; for (int i = 1; i <= n; ++i){ pt = max(pt,calc(i)); } printf("%lld\n",pt ); return 0; }