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