import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int[]a = new int[n]; int[]b = new int[n]; int[]c = new int[n]; for(int i = 0; i < n - 1; i++) { a[i] = scan.nextInt(); } for(int i = 0; i < n; i++) { b[i] = scan.nextInt(); c[i] = scan.nextInt(); } scan.close(); int sum = 0; int B = 0; int C = 0; for(int i = 0; i < n; i++) { B += b[i]; C += c[i]; sum += a[i] * (C - B); } System.out.println(sum); } }