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