from collections import deque def Map(): return list(map(int,input().split())) N,X,Y = Map() x = 0 y = 0 XX = deque() YY = deque() ans = 0 for i in range(N): P,c = map(str,input().split()) P = int(P) cc = 1 if c == 'A': if x < X: XX.append(i) x += 1 ans += P elif y < Y: YY.append(i) y += 1 else: if XX[0] < YY[0]: XX.popleft() XX.append(i) ans += P else: YY.popleft() YY.append(i) else: if y < Y: YY.append(i) y += 1 ans += P elif x < X: XX.append(i) x += 1 else: if YY[0] < XX[0]: YY.popleft() YY.append(i) ans += P else: XX.popleft() XX.append(i) print(ans)