N = int(input()) A = [int(input()) for _ in range(N-1)] ans = 0 n = 0 for i in range(N-1): b,c = map(int,input().split()) n = n-b+c ans += A[i]*n print(ans)