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(); long sum = 0; int lastLatitude = 0, lastLongitude = 0, lastHeight = 0; int[][] arr = new int[n][]; for(int a0 = 0; a0 < n; a0++){ int latitude = in.nextInt(); int longitude = in.nextInt(); int height = in.nextInt(); int points = in.nextInt(); // your code goes here arr[a0] = new int[]{latitude,longitude,height,points}; } for (int i = 0; i < arr.length; i++) { for (int j = i; j > 0; j--) { if (arr[j - 1][2] > arr[j][2]) { int[] tmp = arr[j - 1]; arr[j - 1] = arr[j]; arr[j] = tmp; } } } for(int a0 = 0; a0 < n; a0++){ int latitude = arr[a0][0]; int longitude = arr[a0][1]; int height = arr[a0][2]; int points = arr[a0][3]; // your code goes here if (a0 == 0 || (height > lastHeight && Math.abs(latitude - lastLatitude) <= x && Math.abs(longitude - lastLongitude) <= y)) { sum += points; lastLatitude = latitude; lastLongitude = longitude; lastHeight = height; } } System.out.println(sum); } }