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