collections.Counter()

  • + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    
    X = int(input())
    strshoes = input()
    N = int(input())
    
    
    shoe_list = [int(x) for x in strshoes.split(" ")]
    total_price = 0
    
    
    for cus in range(0,N):
      A = input()
      size_price = [int(a) for a in A.split(" ")]
    
      if size_price[0] in shoe_list:
        shoe_list.remove(size_price[0])
        total_price += size_price[1]
    
    print(total_price)