n = int(input())
heights = list(map(int, input().split()))
costs = list(map(int, input().split()))

left_max_heights = [0] * n
right_max_heights = [0] * n

left_max = 0
right_max = 0

for i in range(n):
    left_max = max(left_max, heights[i])
    left_max_heights[i] = left_max

for i in range(n - 1, -1, -1):
    right_max = max(right_max, heights[i])
    right_max_heights[i] = right_max

total_cost = 0

for i in range(n):
    total_cost += min(costs[i] * min(left_max_heights[i], right_max_heights[i]), costs[i])

print(total_cost)
