#include using namespace std; void fast_io() { ios::sync_with_stdio(false); std::cin.tie(nullptr); } int main() { fast_io(); int n, x, y; cin >> n >> x >> y; vector> cnt(x + y, vector(2)); for (int i = 0; i < n; i++) { int p; char c; cin >> p >> c; cnt[i % (x + y)][c - 'A'] += p; } vector idx(x + y); iota(idx.begin(), idx.end(), 0); sort(idx.begin(), idx.end(), [&](int i, int j) { return cnt[i][0] - cnt[i][1] > cnt[j][0] - cnt[j][1]; }); long long ans = 0; for (int i = 0; i < x; i++) { ans += cnt[idx[i]][0]; } for (int i = x; i < x + y; i++) { ans += cnt[idx[i]][1]; } cout << ans << endl; }