N, X, Y = map(int, input().split()) Pc = [list(map(str, input().split())) for _ in range(N)] mod = X+Y m = [[0, 0] for _ in range(X+Y)] for i in range(N): p, c = Pc[i] p = int(p) if c == 'A': m[i%mod][0] += p else: m[i%mod][1] += p md = [] for i in range(mod): md.append((i, m[i][0] - m[i][1])) md.sort(key=lambda x:(-x[1])) ans = 0 for i in range(mod): idx = md[i][0] if i+1 <= X: ans += m[idx][0] else: ans += m[idx][1] print(ans)