collections.Counter()

  • + 3 comments

    without counters... coz i think there is no need to use it here

    n = input()
    boots = map(int, raw_input().split())
    orders = [map(int, raw_input().split()) for _ in range(input())]
    result = 0
    for i in orders:
        if i[0] in boots:
            result += i[1]
            boots.remove(i[0])
    print result