#include #include using namespace std; //#define DISABLE_PRINT #if defined(ENABLE_PRINT) && !defined(DISABLE_PRINT) #define P(...) fprintf(stderr, __VA_ARGS__) #define P2(fmt) fprintf(stderr, fmt) #define LP fprintf(stderr, "L: %d\n", __LINE__) #else #define P(...) ((void)0) #define P2(fmt) ((void)0) #define LP ((void)0) #endif #define rep(i, n) for(int i = 0; i < (int)(n); ++i) #define ALL(x) x.begin(),x.end() using ll = long long; using ull = unsigned long long; int main(int, const char**) { int N; cin >> N; vector> g(N); vector X(N), A(N); map posToIdx, distToIdx; rep(i, N) { cin >> X[i]; posToIdx[X[i]] = i; } rep(i, N) cin >> A[i]; rep(i, N) { auto d0 = X[i] + A[i]; if(posToIdx.find(d0) != posToIdx.end()) { g[posToIdx[d0]].push_back(i); } distToIdx[d0] = i; auto d1 = X[i] - A[i]; if(posToIdx.find(d1) != posToIdx.end()) { g[posToIdx[d1]].push_back(i); } } vector ans(N, -1); function f = [&](int x, ll d) { if(ans[x] != -1) return; ans[x] = d; for(auto nx : g[x]) { f(nx, d); } }; for(auto itr = distToIdx.rbegin(); itr != distToIdx.rend(); ++itr) { f(itr->second, itr->first); } rep(i, N) { auto a = ans[i] - X[i]; cout << a << endl; } return 0; }