def Map(): return list(map(int,input().split())) N,X,Y = Map() Z = X + Y C = [0 for i in range(min(Z,N))] ans = 0 for i in range(N): j = i % Z P,c = map(str,input().split()) P = int(P) if c == 'A': C[j] += P else: C[j] -= P ans += P C.sort() y = len(C) x = 0 while y > Y: ans += C.pop() y -= 1 x += 1 while x < X and len(C): if C[-1] > 0: ans += C.pop() y -= 1 x += 1 else: break print(ans)