N, A, B = map(int, input().split()) balls = [tuple(map(int, input().split())) for _ in range(N)] def dist(i, j): return abs(balls[i][0] - balls[j][0]) + abs(balls[i][1] - balls[j][1]) dp = [-1] * (1 << N) dp[0] = 0 for S in range(1, 1 << N): for i in range(N): if (S >> i) & 1: T = S ^ (1 << i) if T == 0: dp[S] = max(dp[S], 1) else: for j in range(N): if (T >> j) & 1: if A <= dist(i, j) or abs(balls[i][2] - balls[j][2]) >= B: dp[S] = max(dp[S], dp[T] + 1) else: U = T ^ (1 << j) if U != 0: for k in range(N): if (U >> k) & 1: if A <= dist(i, j) + dist(i, k): dp[S] = max(dp[S], dp[T] + 1) ans = dp[(1 << N) - 1] if ans == -1: ans = 1 print(ans)