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(); Integer a[][]=new Integer[n][4]; for(int i = 0; i < n; i++){ a[i][0] = in.nextInt(); a[i][1] = in.nextInt(); a[i][2] = in.nextInt(); a[i][3] = in.nextInt(); } final Comparator arrayComparator = new Comparator() { @Override public int compare(Integer[] o1, Integer[] o2) { return o1[2].compareTo(o2[2]); } }; Arrays.sort(a, arrayComparator); int count=a[0][3]; for(int i = 1; i < n; i++){ if(Math.abs(a[i][0]-a[i-1][0]) <= x && Math.abs(a[i][1]-a[i-1][1]) <= y ) { // System.out.println(a[i][3]); count=count+a[i][3]; // System.out.println(count); } // System.out.println(Math.abs(a[i][0]-a[i-1][0])+"hi"+Math.abs(a[i][1]-a[i-1][1])); } System.out.println(count); } }