collections.Counter()

  • + 0 comments
    k = int(input())
    shoes_sizes = list(map(int, (input().split())))
    cus_num = int(input())
    print(sum(
        int(x[1]) for x in (input().split() for _ in range(cus_num))
        if int(x[0]) in shoes_sizes and not shoes_sizes.remove(int(x[0]))
    ))