n = int(input())
heights = list(map(int, input().split()))
costs = list(map(int, input().split()))
max = 1
min_cost = 1
for i in range(n):
if heights[i] >= max:
min_cost += costs[i]
current_max_height = heights[i]
max = 0
for i in range(n - 1, -1, -1):
if heights[i] >= max:
min_cost += costs[i]
max = heights[i]
print(min_cost)