#include using namespace std; using ll = long long; int main () { int N, X, Y; cin >> N >> X >> Y; std::vector A(N, vector(2, 0ll)); for (int i = 0; i < N; i ++) { ll p; char c; cin >> p >> c; int j = i % (X + Y); A[j][c == 'B'] += p; } ll ans = 0; for (auto& a : A) ans += a[0]; vector D(min(N, X + Y)); for (int i = 0; i < min(N, X + Y); i ++) { D[i] = A[i][0] - A[i][1]; } sort(D.begin(), D.end()); int fl = 0; for (int i = 0; i < N - X; i ++) { ans -= D[fl++]; } while (fl < Y && fl < D.size()) { if (D[fl] > 0) break; ans -= D[fl]; fl ++; } cout << ans << endl; }