In this HackerRank collections.Counter() problem we need to compute how much money Raghu earned.

HackerRank collections.Counter() in python problem solution

HackerRank collections.Counter() in python problem solution

#!/usr/bin/python
from collections import defaultdict
import sys
if sys.version_info[0]>=3: raw_input=input
raw_input()
d=defaultdict(int)
for e in raw_input().split(): d[int(e)]+=1
r=0
for _ in range(int(raw_input())):
	x,y=map(int,raw_input().split())
	if d[x]:
		d[x]-=1
		r+=y
print(r)

Second solution

import sys
from collections import Counter

X = min(int(sys.stdin.readline().strip()), 10**3)

sizes = Counter(map(int, sys.stdin.readline().strip().split(' ')))

N = min(int(sys.stdin.readline().strip()), 10**3)

total = 0
for _ in range(N):
    transaction = sys.stdin.readline().strip()
    size, price = map(int, transaction.split(' '))
    if sizes[size] > 0:
        sizes[size] -= 1
        total += price
        
print(total)