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