collections.Counter()

  • + 0 comments

    Completed using the methods in the documentation:

    import collections
    
    X = int(input())
    c = collections.Counter(map(int, input().split()))
    N = int(input())
    total = 0
    for i in range(N):
        s,p = map(int, input().split())
        if c[s]:
            c.subtract([s])
            c += collections.Counter() # This removes any 0 counts, as mentioned in documentation
            total += p
    print(total)