import sys, time, random from collections import deque, Counter, defaultdict input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 61 - 1 mod = 998244353 n, x, y = mi() a = [0] * (x + y) b = [0] * (x + y) for i in range(n): p, c = input().split() p = int(p) if c == 'A': a[i % (x + y)] += p else: b[i % (x + y)] += p c = [a[i] - b[i] for i in range(x + y)] d = list(range(x + y)) d.sort(key = lambda x: c[x], reverse=True) ans = 0 for i in range(x + y): if i < x: ans += max(0, a[d[i]]) else: ans += max(0, b[d[i]]) print(ans)