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