N = int(input())
distances = list(map(int, input().split()))
stations = list(map(int, input().split()))
oil = 0
dis = 0
tmp = stations[0]
dist = 0
for i in range(N):
if i == N - 1:
oil += dist * tmp
continue
now = stations[i]
if tmp > now:
oil += dist * tmp
tmp = now
dist = 0
dist += distances[i]
print(oil)