collections.Counter()

  • + 0 comments
    from collections import Counter
    X = int(input())
    myList = list(map(int, input().split()))
    shoes = dict(Counter(myList))
    N = int(input())
    earnings = 0
    for i in range(N):
        size, price = map(int,input().split())
        try:
            if shoes[size] > 0:
                shoes[size] -= 1
                earnings += price
        except KeyError:
            pass
    print(earnings)