n = int(input()) al = list() bcl = list() for i in range(n-1): al.append(int(input())) for i in range(n): bcl.append([int(x) for x in input().split()]) ans = 0 pas = 0 for i in range(n-1): bc = bcl[i] pas -= bc[0] pas += bc[1] ans += pas * al[i] print(ans)