N, X, Y = map(int, input().split()) customer = [list(input().split()) for _ in range(N)] groups = [[0]*2 for _ in range(X+Y)] for i, (P, C) in enumerate(customer): P = int(P) if C == "A": groups[i%(X+Y)][0] += P else: groups[i%(X+Y)][1] += P sumA = 0 for i in range(X+Y): sumA += groups[i][0] groups[i] = groups[i][1]-groups[i][0] groups.sort(reverse=True) print(sumA+sum(groups[:Y]))