use std::collections::BTreeMap; fn main() { let n : usize = input(); let x : Vec = input_vec(); let a : Vec = input_vec(); let mut index = (0..n).collect::>(); index.sort_by_key(|&i| x[i] + a[i]); let mut mp = BTreeMap::new(); let mut ans = vec![0; n]; for &i in index.iter().rev() { let x = x[i]; let a = a[i]; let base = *mp.get(&(x + a)).unwrap_or(&0); mp.insert(x, base + a); ans[i] = base + a; } for _ in 0..100 { for (i, (&x, &a)) in x.iter().zip(a.iter()).enumerate() { if x < a { continue } let base = *mp.get(&(x - a)).unwrap_or(&0); ans[i] = ans[i].max(base.saturating_sub(a)); mp.insert(x, ans[i]); } } println!("{}", ans.iter().map(|i| i.to_string()).collect::>().join("\n")); } #[allow(dead_code)] fn input() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } #[allow(dead_code)] fn input_t() -> (T, U) { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s = s.trim().split_whitespace().collect::>(); (s[0].parse().ok().unwrap(), s[1].parse().ok().unwrap()) } #[allow(dead_code)] fn input_t3() -> (T1, T2, T3) { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s = s.trim().split_whitespace().collect::>(); (s[0].parse().ok().unwrap(), s[1].parse().ok().unwrap(), s[2].parse().ok().unwrap()) } #[allow(dead_code)] fn input_t4() -> (T1, T2, T3, T4) { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s = s.trim().split_whitespace().collect::>(); (s[0].parse().ok().unwrap(), s[1].parse().ok().unwrap(), s[2].parse().ok().unwrap(), s[3].parse().ok().unwrap()) } #[allow(dead_code)] fn input_t5() -> (T1, T2, T3, T4, T5) { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s = s.trim().split_whitespace().collect::>(); (s[0].parse().ok().unwrap(), s[1].parse().ok().unwrap(), s[2].parse().ok().unwrap(), s[3].parse().ok().unwrap(), s[4].parse().ok().unwrap()) } #[allow(dead_code)] fn input_vec() -> Vec { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().split_whitespace().map(|s| s.parse().ok().unwrap()).collect() }