collections.Counter()

  • + 0 comments
    n = int(input().strip())
    A = list( map(int, input().strip().split(" ")))
    total = 0
    for _ in range( int(input().strip()) ):
        shoe = list( map(int,  input().strip().split(" ")))
        if ( shoe[0] in A):
            total += shoe[1]
            A.remove(shoe[0])
    print(total)