
풀이 소요시간 : 15분 ⏰
n = int(input())
dist = [0] + list(map(int, input().split()))
cost = list(map(int, input().split()))
current_cost = 987654321
result = 0
for i in range(n-1):
if cost[i] < current_cost:
current_cost = cost[i]
result += (current_cost * dist[i+1])
print(result)
import sys
import heapq
n, m, k = map(int, sys.stdin.readline().split())
# 선호도 순서로 정렬하여 입력
beers = [list(map(int, input().split())) for _ in range(k)]
beers = sorted(beers,key=lambda x: (x[1],x[0]))
preference = 0
pq = []
for i in beers:
preference += i[0]
heapq.heappush(pq, i[0])
if len(pq) == n:
if preference >= m:
answer = i[1]
break
else:
preference -= heapq.heappop(pq)
else:
print(-1)
exit()
print(answer)
n = int(input())
m = int(input())
lst = list(map(int, input().split()))
lst.sort()
dist = [lst[i] - lst[i-1] for i in range(1, n)]
print(sum(sorted(dist)[:len(lst) - m]))