import sys input = sys.stdin.readline n = int(input()) a = [int(input()) for _ in range(n-1)] now = [] ans = 0 for i in range(n): b, c = map(int, input().split()) for _ in range(b): ans += now.pop() for _ in range(c): now.append(0) for j in range(len(now)): now[j] += a[i] print(ans)