import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) ############################## N = int(input()) A = [] for i in range(N-1): a = int(input()) A.append(a) B = [] C = [] for i in range(N): b, c = map(int, input().split()) B.append(b) C.append(c) t = [] for i in range(N): diff = C[i]-B[i] t.append(diff) for i in range(1, N): t[i] += t[i-1] #print(t) ans = 0 for i in range(N-1): ans += t[i]*A[i] print(ans)