fn main() { let (n, d): (usize, i32) = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); ( iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap(), ) }; let mut fav = Vec::with_capacity(n); for _ in 0..n { let a: i32 = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); buf.trim_end().parse().unwrap() }; fav.push(a); } let mut sorted_fav = fav.iter().cloned().collect::>(); sorted_fav.sort(); for a in fav { let mut left = 0; let mut right = n; while left < right { let mid = (left + right) / 2; if a - sorted_fav[mid] >= d { left = mid + 1; } else { right = mid; } } println!("{}", left); } }