n = int(input()) cost = [0] + [int(input()) for _ in [0]*(n-1)] result, pas = 0, 0 for i in range(1, n): b, c = map(int, input().split()) pas += c - b result += cost[i]*pas print(result)