n,x,y = map(int,input().split()) z = x+y; dab = [[0,0,0] for _ in range(z)] for i in range(n): p,c = input().split() p = int(p) if c=="A": dab[i%z][0] -= p; dab[i%z][1] += p if c=="B": dab[i%z][0] += p; dab[i%z][2] += p dab.sort(); ans = 0 for d,a,b in dab[:x]: ans += a for d,a,b in dab[x:]: ans += b print(ans)