collections.Counter()

  • + 0 comments
    from collections import Counter
    total_shoes = int(input())
    shoe_sizes = [int(i) for i in input().split()]
    shoe_sizes = Counter(shoe_sizes)
    customer = int(input())
    profit = 0
    for i in range(0,customer):
        each_cus = [int(i) for i in input().split()]
        if shoe_sizes.get(each_cus[0]) is not None and shoe_sizes.get(each_cus[0]):
            shoe_sizes.update({each_cus[0] : -1})
            profit += each_cus[1]
            
    print(profit)