#include using namespace std; int main(){ int N, X, Y; cin >> N >> X >> Y; vector P(N); vector c(N); for (int i = 0; i < N; i++){ cin >> P[i] >> c[i]; } vector A(X + Y, 0); vector B(X + Y, 0); for (int i = 0; i < N; i++){ if (c[i] == 'A'){ A[i % (X + Y)] += P[i]; } if (c[i] == 'B'){ B[i % (X + Y)] += P[i]; } } vector ord(X + Y); for (int i = 0; i < X + Y; i++){ ord[i] = i; } sort(ord.begin(), ord.end(), [&](int a, int b){return A[a] - B[a] < A[b] - B[b];}); long long ans = 0; for (int i = 0; i < Y; i++){ ans += B[ord[i]]; } for (int i = Y; i < X + Y; i++){ ans += A[ord[i]]; } cout << ans << endl; }