#include using namespace std; using ll = long long; using P = pair; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(ll i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a> n; map mp; vector x(n), a(n), ans(n); rep(i,n) cin >> x[i]; rep(i,n) cin >> a[i]; rep(i,n) mp[x[i]] = i; vector seen(n,false); rep(i,n){ if(seen[i]) continue; seen[i] = true; vector td; ll ma = 0; queue que; que.push(i); while(que.size()){ int now = que.front(); td.push_back(now); chmax(ma, x[now]+a[now]); que.pop(); if(mp.count(x[now]+a[now])){ int next = mp[x[now]+a[now]]; if(seen[next]){ chmax(ma, ans[next] + x[next]); chmax(ma, a[next] + x[next]); continue; } seen[next] = true; que.push(next); } if(mp.count(x[now]-a[now])){ int next = mp[x[now]-a[now]]; if(seen[next]){ chmax(ma, ans[next] + x[next]); chmax(ma, a[next] + x[next]); continue; } seen[next] = true; que.push(next); } } for(int z:td) ans[z] = ma - x[z]; } rep(i,n) cout << ans[i] << '\n'; return 0; }