from collections import deque def Map(): return list(map(int,input().split())) N,X,Y = Map() Z = X + Y C = [0 for i in range(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() if Z <= N: for i in range(X): ans += C.pop() else: y = N 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)