collections.Counter()

  • + 0 comments
    from collections import Counter
    
    earned = 0
    
    X = int(input())
    available = list(map(int, input().split()))
    N = int(input())
    
    for customers in range(N):
        shoe_size, price = map(int, input().split())
    
    if shoe_size in available:
        if Counter(available).values() != 0:
            available.remove(shoe_size)
            earned += price
        else:
            continue
    

    print(earned)