import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class App { public static void main(String args[]) { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); try { String[] initial = bufferedReader.readLine().split(" "); if (initial.length == 3) { int n = Integer.valueOf(initial[0]); City[] cities = new City[n]; int x = Integer.valueOf(initial[1]); int y = Integer.valueOf(initial[2]); for (int i = 0; i < n; i++) { String[] temp = bufferedReader.readLine().split(" "); if (temp.length == 4) { cities[i] = new City(Integer.valueOf(temp[0]), Integer.valueOf(temp[1]), Integer.valueOf(temp[2]), Integer.valueOf(temp[3])); } } Arrays.sort(cities); int totalPoint = 0; for (int i = 0; i < cities.length; i++) { int j = i + 1; if (j <= cities.length - 1) { if ((cities[i].getLatitude() - cities[j].getLatitude() <= x) && (cities[i].getLongitude() - cities[j].getLongitude() <= y)) { totalPoint += cities[i].getPoint(); } } } if ((cities[cities.length - 1].getLatitude() - cities[cities.length - 2].getLatitude() <= x) && (cities[cities.length - 1].getLongitude() - cities[cities.length - 2].getLongitude() <= y)) { totalPoint += cities[cities.length - 1].getPoint(); } System.out.println(totalPoint); } } catch (IOException e) { e.printStackTrace(); } } } class City implements Comparable { int latitude; int longitude; int height; int point; City(int latitude, int longitude, int height, int point) { this.latitude = latitude; this.longitude = longitude; this.height = height; this.point = point; } int getLatitude() { return latitude; } int getLongitude() { return longitude; } private int getHeight() { return height; } int getPoint() { return point; } public void setPoint(int point) { this.point = point; } @Override public int compareTo(City o) { int compareHeight = o.getHeight(); return this.height - compareHeight; } @Override public String toString() { return "City{" + "latitude=" + latitude + ", longitude=" + longitude + ", height=" + height + ", point=" + point + '}'; } }