use std::collections::{BTreeSet, HashMap, HashSet, 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 = HashMap::new(); for (i, &v) in pointset.iter().enumerate() { mapping.insert(v, i); revmap.insert(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 mut result = vec![0usize; pointset.len()]; let orders = (0..n).collect::>(); let orders = orders.iter().flat_map(|&v| vec![*mapping.get(&(x[v] - a[v])).unwrap(), *mapping.get(&(x[v] + a[v])).unwrap()]).collect::>(); let orders = orders.into_iter().rev().collect::>(); for &i in orders.iter() { if result[i] > 0 { continue; } let mut deque = VecDeque::new(); deque.push_back(i); result[i] = i; while let Some(u) = deque.pop_front() { for &v in paths[u].iter() { if result[v] > 0 { continue; } result[v] = i; deque.push_back(v); } } } for i in 0..n { let src = x[i]; let i = *mapping.get(&src).unwrap(); println!("{}", *revmap.get(&result[i]).unwrap() - src); } }