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