collections.Counter()

  • + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    from collections import Counter
    X = int(input())
    shoe_sizes = list(map(int,input().split()))
    N = int(input())
    total_earned = 0
    for i in range(N):
        size,price = map(int,input().split())
        if size in shoe_sizes:
            total_earned += price
            shoe_sizes.remove(size)
    
    print(total_earned)