collections.Counter()

  • + 0 comments
    no_of_shoes = int(input())
    shoes = input()
    shoe_list = list(map(int, shoes.split(" ")))
    no_of_cus = int(input())
    profit = 0
    for i in range(no_of_cus):
        choice = input()
        choice_list = list(map(int, choice.split(" ")))
        if choice_list[0] in shoe_list:
            profit += choice_list[1]
            shoe_list.remove(choice_list[0])
            
    print(profit)