n = int(input()) a = list(map(int,input().split())) now = 0 count = 0 for i in range(n-1): b,c = list(map(int,input().split())) now = now + c - b count += a[i] * now print(count)