#include using namespace std; using ll = long long; using P = pair; #define rep(i, a, b) for(ll i = a; i < b; ++i) #define rrep(i, a, b) for(ll i = a; i >= b; --i) constexpr ll inf = 4e18; struct SetupIO { SetupIO() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(30); } } setup_io; int main(void) { ll n, x, y; cin >> n >> x >> y; vector p(n); vector c(n); rep(i, 0, n) { cin >> p[i] >> c[i]; } ll z = x + y; vector a(z), b(z); rep(i, 0, n) { if(c[i] == 'A') { a[i % z] += p[i]; } else { b[i % z] += p[i]; } } vector idx(z); rep(i, 0, z) idx[i] = i; auto comp = [&](ll x, ll y) -> bool { return (a[x] - b[x]) < (a[y] - b[y]); }; sort(idx.begin(), idx.end(), comp); ll ans = 0; rep(i, 0, y) { ans += b[idx[i]]; } rep(i, y, x + y) { ans += a[idx[i]]; } cout << ans << '\n'; }