n = int(input())
heights = list(map(int, input().split()))
costs = list(map(int, input().split()))
columns = [(heights[i], costs[i]) for i in range(n)]
columns.sort(key=lambda x: -x[0])
total_cost = 0
max_height = 0
for height, cost in columns:
    if height > max_height:
        max_height = height
    total_cost += cost * max_height
print(total_cost)
