// #include #include using namespace std; using namespace atcoder; using ll = long long; #define rep(i, n) for (int i=0; i<(int)(n); ++(i)) #define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i)) #define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i)) #define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i)) #define all(x) (x).begin(), (x).end() const int INF = (int)(1e9); int main() { int n, x, y; cin >> n >> x >> y; vector p(n), c(n); rep(i, n) { char ci; cin >> p[i] >> ci; c[i] = ci - 'A'; } int m = x + y; vector> ab(m, vector(2)); rep(i, n) ab[i%m][c[i]] += p[i]; vector ord(m); iota(all(ord), 0); sort(all(ord), [&](int li, int ri) -> bool { return ab[li][0]-ab[li][1] > ab[ri][0]-ab[ri][1]; }); ll res = 0; rep(i, m) { if (i < x) res += ab[ord[i]][0]; else res += ab[ord[i]][1]; } cout << res << endl; return 0; }