collections.Counter()

  • + 0 comments
    from collections import Counter
    
    x = input()
    
    shoeList = list(input().split())
    
    shoeListOrg = Counter(shoeList)
    
    N = int(input())
    
    price = list()
    
    for i in range(N):
        sizeAndPrice = list(input().split())
        
        for key in shoeListOrg:
            
            if key == sizeAndPrice[0]:
                if shoeListOrg[key] != 0:
                    price.append(int(sizeAndPrice[1]))
                    shoeListOrg[key] = shoeListOrg[key] - 1
            else:
                pass
    
    print(sum(price))