# Enter your code here. Read input from STDIN. Print output to STDOUT [n,x,y]=map(int,raw_input().split(" ")) l=[] la=[] lo=[] he=[] po=[] for i in range(n): [la1,lo1,he1,po1]=map(int,raw_input().split(" ")) la.append(la1) lo.append(lo1) he.append(he1) po.append(po1) LEN=len(he) for i in range(LEN): for j in range(i+1,LEN): if he[i]>he[j]: temp=he[i] he[i]=he[j] he[j]=temp temp=la[i] la[i]=la[j] la[j]=temp temp=lo[i] lo[i]=lo[j] lo[j]=temp temp=po[i] po[i]=po[j] po[j]=temp #print la,lo,he,po total=0 cou=0 for i in range(LEN-1): #print la[i],la[i+1],lo[i],lo[i+1] if abs(la[i]-la[i+1])<=x: if abs(lo[i]-lo[i+1])<=y: total+=po[i] if i==LEN-2: cou=5 if cou==5: total+=po[LEN-1] if total==0: total=max(po) print total