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