N = int(input())
A = list(map(int,input().split()))
Q = int(input())
for _ in range(M):
    B,C = map(int, input().split())
A.sort()
ans = 0
for a in range(Q) :
    x=C if A=B else 0
    ans = sum(A)
print(ans)
        