import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static boolean visited[]; static int dp[]; static HashMap map = new HashMap(); public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int x = in.nextInt(); int y = in.nextInt(); Quad [] quads = new Quad [n]; visited = new boolean[n]; dp = 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(); quads[a0] = new Quad(latitude, longitude, height, points); quads[a0].id = a0; map.put(a0, quads[a0]); } Arrays.sort(quads); for(int a= 0; a < n; a++) { for(int b = a+1; b < n; b++) { if(Math.abs(quads[a].latitude- quads[b].latitude) <= x && Math.abs(quads[a].longitude- quads[b].longitude) <= y) { quads[a].adjList.add(quads[b].id); } } } int maxPoints = Integer.MIN_VALUE; for(int c = 0; c < n ; c++) { if(!visited[c]) { maxPoints = Math.max(maxPoints, (dp[c] = dfs(c))); } else { maxPoints = Math.max(maxPoints, dp[c]); } } System.out.println(maxPoints); } public static int dfs(int c) { visited[c] = true; int ans = map.get(c).points; for(Integer adj: map.get(c).adjList) { if(!visited[adj]) ans = Math.max(ans , map.get(c).points + dfs(adj)); else ans = Math.max(ans, map.get(c).points + dp[adj]); } return (dp[c] = ans); } public static class Quad implements Comparable { public int id; public int latitude; public int longitude; public int height; public int points; List adjList = new ArrayList(); @Override public int compareTo(Quad other){ return this.height - other.height; } public Quad(int latitude, int longitude, int height, int points) { this.latitude = latitude; this.longitude = longitude; this.height = height; this.points = points; } } }