N = int(input()) A = [int(input()) for _ in range(N-1)] B = [0]*N C = [0]*N for i in range(N): b,c = map(int, input().split()) B[i] = b C[i] = c ans = 0 pas = C[0] for i in range(1, N): ans += pas*A[i-1] pas -= B[i] pas += C[i] print(ans)