n, x, y = [int(z) for z in input().split()] pc = [[z for z in input().split()] for _ in range(n)] rm = x + y need = [[0, 0] for _ in range(rm)] for i in range(n): pi, ci = pc[i] if ci == "A": need[i%rm][0] += int(pi) else: need[i%rm][1] += int(pi) need.sort(key=lambda a: a[1] - a[0]) ans = 0 for i in range(x): ans += need[i][0] for i in range(y): ans += need[~i][1] print(ans)