N, X, Y = map(int, input().split()) diff = [0 for i in range(X + Y)] ans = 0 for i in range(N): P, c = input().split() P = int(P) c = {'A': 1, 'B': -1}[c] diff[i % (X + Y)] += P * c ans += P * (1 - c) // 2 diff = sorted(diff)[::-1] for i in range(X): ans += diff[i] print(ans)