import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[] prices = new long[n - 1]; for (int i = 0; i < n - 1; i++) { prices[i] = sc.nextInt(); } long total = 0; int current = 0; for (int i = 0; i < n - 1; i++) { current -= sc.nextInt() - sc.nextInt(); total += current * prices[i]; } System.out.println(total); } }