n = int(input()) a = [int(input()) for _ in range(n - 1)] ans = 0 num = 0 for i in range(n): b, c = map(int, input().split()) num += c - b if i == n - 1: break ans += num * a[i] print(ans)