collections.Counter()

  • + 0 comments

    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[s] -= 1 # Reduce stock count total += p

    print(total)