collections.Counter()

  • + 0 comments

    from collections import Counter X=int(input()) S=list(map(int,input().strip().split()[:X])) N=int(input()) lst=[] for i in range(0,N): lst.append(list(map(int,input().strip().split()[:2]))) C=Counter(S) ttl=0 for i in range(0,N): a,b=lst[i] if a in C and C[a]>0: ttl+=b C[a]-=1 print(ttl)