n=int(input()) yen=[] cnt=0 fee=0 h=[[] for i in range(2)] for i in range(n-1): yen.append(int(input())) for i in range(n): a=list(map(int,(input().split()))) h[0].append(a[0]) h[1].append(a[1]) for i in range(n-1): cnt+=(-h[0][i]+h[1][i]) fee+=(cnt*yen[i]) print(fee)