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