use std::collections::{BTreeSet, HashMap, VecDeque}; fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut x = String::new(); std::io::stdin().read_line(&mut x).ok(); let x: Vec = x.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let a: Vec = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut pointset = BTreeSet::new(); for i in 0..n { pointset.insert(x[i]); pointset.insert(x[i]-a[i]); pointset.insert(x[i]+a[i]); } let mut mapping = HashMap::new(); let mut revmap = vec![0isize; pointset.len()]; for (i, &v) in pointset.iter().enumerate() { mapping.insert(v, i); revmap[i] = v; } let mut paths = vec![vec![]; pointset.len()]; for i in 0..n { let src = *mapping.get(&x[i]).unwrap(); let left = *mapping.get(&(x[i]-a[i])).unwrap(); let right = *mapping.get(&(x[i]+a[i])).unwrap(); paths[left].push(src); paths[right].push(src); } let goals = (0..n).flat_map(|i| vec![x[i]-a[i], x[i]+a[i]]).map(|pos| *mapping.get(&pos).unwrap()).collect::>(); let mut res = vec![0usize; pointset.len()]; for &src in goals.iter().rev() { let mut deque = VecDeque::new(); deque.push_back(src); while let Some(u) = deque.pop_front() { for &v in paths[u].iter() { if res[v] >= src { continue; } res[v] = src; deque.push_back(v); } } } for i in 0..n { let src = x[i]; let idx = *mapping.get(&src).unwrap(); println!("{}", revmap[res[idx]] - src); } }