// 嘘解法 // 答えが 1 になるケースで 0 と答えてしまう実装 #include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int N, A, B; cin >> N >> A >> B; vector X(N), Y(N), K(N); for (int i = 0; i < N; i++) { cin >> X[i] >> Y[i] >> K[i]; } vector>> ok(N, vector>(N, vector(N))); // a -> b -> c for (int a = 0; a < N; a++) { for (int b = 0; b < N; b++) { for (int c = 0; c < N; c++) { if (a == b || a == c || b == c) { continue; } int d = abs(X[c] - X[a]) + abs(Y[c] - Y[a]) + abs(X[c] - X[b]) + abs(Y[c] - Y[b]); int v = abs(K[c] - K[b]); if (d >= A || v >= B) { ok[a][b][c] = true; } } } } vector>> dp(1 << N, vector>(N, vector(N))); // a -> b for (int a = 0; a < N; a++) { for (int b = 0; b < N; b++) { if (a == b) { continue; } int d = abs(X[b] - X[a]) + abs(Y[b] - Y[a]); int v = abs(K[b] - K[a]); if (d >= A || v >= B) { dp[(1 << a) + (1 << b)][a][b] = true; } } } for (int S = 1; S < (1 << N); S++) { for (int a = 0; a < N; a++) { if (((S >> a) & 1) == 0) { continue; } for (int b = 0; b < N; b++) { if (((S >> b) & 1) == 0) { continue; } if (not dp[S][a][b]) { continue; } for (int c = 0; c < N; c++) { if (((S >> c) & 1) == 1) { continue; } if (not ok[a][b][c]) { continue; } dp[S + (1 << c)][b][c] = true; } } } } int ans = 0; for (int S = 1; S < (1 << N); S++) { for (int a = 0; a < N; a++) { for (int b = 0; b < N; b++) { if (dp[S][a][b]) { int pcnt = __builtin_popcount(S); ans = max(ans, pcnt); } } } } cout << ans << '\n'; return 0; }