from itertools import accumulate from collections import defaultdict def main(): n = int(input()) a = [0] + [int(input()) for _ in range(n - 1)] sum_a = list(accumulate(a)) d = defaultdict(int) ans = 0 for i in range(n): b, c = map(int, input().split()) for j, k in d.items(): tmp = sum_a[i] - sum_a[j] if k == 0: continue if b > k: ans += tmp * k d[j] = 0 b -= k else: ans += tmp * b d[j] -= b break d[i] += c print(ans) if __name__ == "__main__": main()