import sys sys.setrecursionlimit(10 ** 6) N = int(input()) X = list(map(int, input().split())) A = list(map(int, input().split())) m = {x: a for x, a in zip(X, A)} memo = {} def f(x: int, used) -> int: if x in memo: return memo[x] if x not in m: return 0 if x in used: return 0 used.add(x) d = m[x] res = max(f(x-d, used) - d, f(x+d, used) + d) memo[x] = res return res for x in X: used = set() print(f(x, used))