import sys input = sys.stdin.readline n=int(input()) A=[int(input()) for i in range(n-1)] X=[list(map(int,input().split())) for i in range(n)] now=X[0][1] ANS=0 for i in range(n-1): ANS+=A[i]*now now-=X[i+1][0] now+=X[i+1][1] print(ANS)