N,X,Y = map(int,input().split()) n = X + Y dat = [[0] * 2 for _ in range(n)] A = [] B = [] for _ in range(N): P,c = input().split() P = int(P) if c == "A": c = 0 else: c = 1 dat[_ % n][c] += P l = [] for i in range(n): l.append((dat[i][0] - dat[i][1],i)) l.sort(reverse = True) ans = 0 for i in range(n): if i < X: u,j = l[i] ans += dat[j][0] else: u,j = l[i] ans += dat[j][1] print(ans)