#!/bin/env python3 import sys class City: def __init__(self, la, lo, h, p): self.la = la self.lo = lo self.h = h self.p = p def __str__(self): return "({self.la}, {self.lo}, {self.h}) - [{self.p}]".format(**locals) def match(self, prev, x, y): return abs(prev.la - self.la) <= x and \ abs(prev.lo - self.lo) <= y n,x,y = input().strip().split(' ') n,x,y = [int(n),int(x),int(y)] cities = [] for a0 in range(n): latitude,longitude,height,points = input().strip().split(' ') latitude,longitude,height,points = [int(latitude),int(longitude),int(height),int(points)] # your code goes here cities.append( City(latitude, longitude, height, points)) cities = sorted(cities, key=lambda c:c.h) currentP = currentMP = cities[0].p maxP = currentP i = 1 preC = cities[0] while i < n: city = cities[i] if city.match(preC, x, y): currentP += city.p if currentP > currentMP: currentMP = currentP else: maxP = max(maxP, currentMP) currentP = currentMP = city.p preC = city i += 1 maxP = max(maxP, currentMP) print(maxP)