import sys input = sys.stdin.readline def main(): N, A, B = map(int, input().split()) X, Y, K = [0] * N, [0] * N, [0] * N for i in range(N): X[i], Y[i], K[i] = map(int, input().split()) ok = [[[False] * N for _ in range(N)] for _ in range(N)] # a -> b -> c for a in range(N): for b in range(N): for c in range(N): if a == b or a == c or b == c: continue d = abs(X[c] - X[a]) + abs(Y[c] - Y[a]) + abs(X[c] - X[b]) + abs(Y[c] - Y[b]) v = abs(K[c] - K[b]) if d >= A or v >= B: ok[a][b][c] = True dp = [[[False] * N for _ in range(N)] for _ in range(1 << N)] # a -> b for a in range(N): for b in range(N): if a == b: continue d = abs(X[b] - X[a]) + abs(Y[b] - Y[a]) v = abs(K[b] - K[a]) if d >= A or v >= B: dp[(1 << a) + (1 << b)][a][b] = True for S in range(1, 1 << N): for a in range(N): if ((S >> a) & 1) == 0: continue for b in range(N): if ((S >> b) & 1) == 0: continue if not dp[S][a][b]: continue for c in range(N): if ((S >> c) & 1) == 1: continue if not ok[a][b][c]: continue dp[S + (1 << c)][b][c] = True ans = 1 for S in range(1, 1 << N): for a in range(N): for b in range(N): if dp[S][a][b]: ans = max(ans, bin(S).count("1")) print(ans) if __name__ == "__main__": main()