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 points = x.iter().copied().collect::>(); for i in 0..n { points.insert(x[i] - a[i]); points.insert(x[i] + a[i]); } let mapping = points.iter().enumerate().map(|(i, &v)| (v, i)).collect::>(); let revmap = points.iter().copied().collect::>(); let n = points.len(); let mut paths = vec![vec![]; n]; for i in 0..x.len() { let lidx = *mapping.get(&(x[i] - a[i])).unwrap(); let cidx = *mapping.get(&x[i]).unwrap(); let ridx = *mapping.get(&(x[i] + a[i])).unwrap(); paths[ridx].push(cidx); paths[lidx].push(cidx); } let mut result = vec![0usize; n]; for i in (0..n).rev() { if paths[i].is_empty() || result[i] > 0 { continue; } let mut deque = VecDeque::new(); deque.push_back(i); while let Some(x) = deque.pop_front() { for &v in paths[x].iter() { if result[v] > 0 { continue; } result[v] = i; deque.push_back(v); } } } for i in 0..x.len() { let idx = *mapping.get(&x[i]).unwrap(); let rpos = revmap[result[idx]]; println!("{}", rpos - x[i]); } }