N = int(input()) lsa = [int(input()) for i in range(N-1)] now = 0 ans = 0 for i in range(N-1): b,c = map(int,input().split()) now -= b now += c ans += lsa[i]*now input() print(ans)