import sys sys.setrecursionlimit(10 ** 6) INF = 1 << 60 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 -INF used.add(x) d = m[x] res = f(x+d, used) + d if x-d not in used: res = max(res, f(x-d, used) - d) # 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))