pub mod scanner { pub struct Scanner { buf: Vec, } impl Scanner { pub fn new() -> Self { Self { buf: vec![] } } pub fn new_from(source: &str) -> Self { let source = String::from(source); let buf = Self::split(source); Self { buf } } pub fn next(&mut self) -> T { loop { if let Some(x) = self.buf.pop() { return x.parse().ok().expect(""); } let mut source = String::new(); std::io::stdin().read_line(&mut source).expect(""); self.buf = Self::split(source); } } fn split(source: String) -> Vec { source .split_whitespace() .rev() .map(String::from) .collect::>() } } } use crate::scanner::Scanner; use std::io::Write; macro_rules! mdvec { ($elem:expr; $n:expr) => ( vec![$elem; $n] ); ($elem:expr; $n:expr $(; $ns:expr)+) => ( vec![mdvec![$elem $(; $ns)*]; $n] ); } fn main() { let mut scanner = Scanner::new(); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); let t: usize = 1; for _ in 0..t { solve(&mut scanner, &mut out); } } fn solve(scanner: &mut Scanner, out: &mut std::io::BufWriter) { let n: usize = scanner.next(); let a: isize = scanner.next(); let b: isize = scanner.next(); let xyk = (0..n) .map(|_| { ( scanner.next::(), scanner.next::(), scanner.next::(), ) }) .collect::>(); let dist = |i: usize, j: usize| -> isize { let (xi, yi, _) = xyk[i]; let (xj, yj, _) = xyk[j]; (xi - xj).abs() + (yi - yj).abs() }; let ok = |i1: usize, i2: usize, i3: usize| -> bool { let (_, _, k2) = xyk[i2]; let (_, _, k3) = xyk[i3]; let mut res = false; res |= b <= (k2 - k3).abs(); res |= a <= dist(i3, i2) + dist(i3, i1); res }; let mut dp = mdvec!(false; 1 << n; n; n); for i in 0..n { for j in 0..n { if i == j || dist(i, j) < a { continue; } dp[(1 << i) | (1 << j)][i][j] = a <= dist(i, j) || b <= (xyk[i].2 - xyk[j].2).abs(); } } let mut ans = 1; for bits in 0..(1 << n) { for i in 0..n { if ((bits >> i) & 1) == 0 { continue; } for j in 0..n { if i == j || ((bits >> j) & 1) == 0 { continue; } for k in 0..n { if ((bits >> k) & 1) == 1 { continue; } if ok(i, j, k) { let next = bits | (1 << k); dp[next][j][k] = true; ans = ans.max(next.count_ones()); } } } } } writeln!(out, "{}", ans).unwrap(); }