N,A,B=map(int,input().split()) XYK=[list(map(int,input().split())) for _ in range(N)] visit = [0]*N def dfs(route:list): ret = len(route) for i in range(N): if visit[i]:continue x,y,k=XYK[i] i0,i1 = route[-2:] x1,y1,k1=XYK[i1] flg=0 if abs(k-k1)>=B: flg=1 else: x0,y0,_=XYK[i0] if A<=abs(x0-x1)+abs(y0-y1)+abs(y1-y)+abs(x1-x): flg=1 if flg: route.append(i) visit[i]=1 ret2 = dfs(route) visit[i]=0 route.pop() ret = max(ret, ret2) if ret==N: print(N) exit() return ret def solve(): ret = 1 route = [] for i in range(N): route.append(i) x1,y1,k1 = XYK[i] visit[i]=1 for j in range(N): if i==j:continue x2,y2,k2 = XYK[j] if A<=abs(x1-x2)+abs(y1-y2) or B<=abs(k1-k2): if ret==1:ret=2 route.append(j) visit[j]=1 ret2 = dfs(route) ret = max(ret, ret2) route.pop() visit[j]=0 visit[i]=0 route.pop() return ret print(solve())