collections.Counter()

  • + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    
    from collections import Counter
    
    X = input()
    sizes = input().split(" ")
    N = input()
    
    shoes_summry = Counter(sizes).items()
    shoes_summry = dict(shoes_summry)
    
    earned = 0
    
    
    for i in range(int(N)):
        size_price = input().split(" ")
        shoe_size, price = size_price
        price = int(price)
        
        if shoe_size in shoes_summry:
            if shoes_summry[shoe_size] > 0:
                earned += price
                shoes_summry[shoe_size] -= 1  
              
    
    print(earned)