import sys input = sys.stdin.readline N,X,Y=map(int,input().split()) L=[input().split() for i in range(N)] mod=X+Y M=[] ANS=0 for i in range(mod): A=0 B=0 for j in range(i,N,mod): if L[j][1]=="A": A+=int(L[j][0]) else: B+=int(L[j][0]) M.append((A,B)) M.sort(key=lambda x:x[1]-x[0]) for i in range(mod): if i