#!/bin/python import sys n,x,y = raw_input().strip().split(' ') n,x,y = [int(n),int(x),int(y)] la=[] lo=[] h=[] p=[] for a0 in xrange(n): latitude,longitude,height,points = raw_input().strip().split(' ') latitude,longitude,height,points = [int(latitude),int(longitude),int(height),int(points)] # your code goes here la.append(latitude) lo.append(longitude) h.append(height) p.append(points) #print la,lo,h,p hd=h h.sort() lad=[] lod=[] pd=[] for j in range(n): ind=hd.index(h[j]) lad.append(la[ind]) lod.append(lo[ind]) pd.append(p[ind]) #print lad,lod,pd count=0 for l1 in range(n-1): flag=0 if abs(lad[l1+1]-lad[l1])==x and abs(lod[l1+1]-lod[l1])==y: count+=pd[l1] flag=1 if flag==1: print count+pd[n-1] else: print count