n = int(input()) a = [int(input()) for _ in range(n-1)] b = [list(map(int, input().split())) for _ in range(n)] c = [] d = 0 for i in b: d += i[1] - i[0] c.append(d) e = 0 for i in range(len(a)): e += a[i] * c[i] print(e)