collections.Counter()

  • + 0 comments
    from collections import Counter
    if __name__=='__main__':
        X,shoe_sizes,N=int(input()),Counter(list(map(int, input().split()))),int(input())
        earnings=0
        for _ in range(N):
            size,price= map(int, input().split())
            if size in shoe_sizes.keys() and shoe_sizes[size]>0:
                earnings+=price
                shoe_sizes[size]-=1
            
        print(earnings)