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(); City[] cities = new City[n]; int total = 0; for (int i = 0; i < n; i++) { cities[i] = new City(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt()); if (i > 0) { if (cities[i].lat - cities[i - 1].lat <= x && cities[i].lon - cities[i - 1].lon <= y) { total += cities[i].p; System.err.println("New total = " + total); cities[i].vis = true; } } else { total += cities[i].p; } } System.out.println(total); } } class City implements Comparable { int lat; int lon; int h; int p; boolean vis; City(int lat, int lon, int h, int p) { this.lat = lat; this.lon = lon; this.h = h; this.p = p; this.vis = false; } public int compareTo(City compareCity) { int height = ((City) compareCity).h; return this.h - height; } }