import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int x = in.nextInt(); int y = in.nextInt(); int latitude[] = new int[n]; int longitude[] = new int[n]; int height[] = new int[n]; int points[] = new int[n]; for(int a0 = 0; a0 < n; a0++){ latitude[a0] = in.nextInt(); longitude[a0] = in.nextInt(); height[a0] = in.nextInt(); points[a0] = in.nextInt(); } // your code goes here int i,j,t1,t2,t3,t4,pt=0; for(i=0;iheight[j+1]) { t1=height[j]; height[j]=height[j+1]; height[j+1]=t1; t2=latitude[j]; latitude[j]=latitude[j+1]; latitude[j+1]=t2; t3=longitude[j]; longitude[j]=longitude[j+1]; longitude[j+1]=t3; t4=points[j]; points[j]=points[j+1]; points[j+1]=t4; } } } int last=0,t=0;i=1;pt=points[0]; while(last+i != n) { if(latitude[last]-latitude[last+i] <=x || latitude[last+i]-latitude[last] <=x) if(longitude[last]-longitude[last+i] <=y || longitude[last+i]-longitude[last] <=y) { pt = pt + points[last+i]; t=1; } if(t==0) i=i+1; else { last=last+i; i=1; } } System.out.println(pt); } }