collections.Counter()

  • + 0 comments
    from collections import Counter
    
    X = input()
    number_of_shoes = map(int, input().split())
    
    inventory = Counter(number_of_shoes)
    earnings = 0
    
    for _ in range(int(input())):
        size, price = map(int, input().split())
        if inventory[size] > 0:
            inventory[size] -= 1
            earnings += price
    print(earnings)