import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
class Main13305 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int[] distance = new int[N];
for (int i = 1; i < N; i++) {
distance[i] = Integer.parseInt(st.nextToken());
}
st = new StringTokenizer(br.readLine());
int[] fee = new int[N + 1];
for (int i = 1; i <= N; i++) {
fee[i] = Integer.parseInt(st.nextToken());
}
long answer = 0;
int min = Integer.MAX_VALUE;
for (int i = 1; i < N; i++) {
min = Math.min(min, fee[i]);
answer += (long)min * distance[i];
}
System.out.println(answer);
}
}
휴지통/알고리즘 & 자료구조