#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll n, x, y, cx, cy; cin >> n >> x >> y; vector> a(x + y); for(int i = 0; i < n; i++){ ll p; char c; cin >> p >> c; if(c == 'A') a[i % (x + y)].first += p; else a[i % (x + y)].second += p; } sort(a.begin(), a.end(), [&](pair lhs, pair rhs){ return lhs.first - lhs.second > rhs.first - rhs.second; }); ll ans = 0; for(int i = 0; i < x + y; i++){ ans += i < x ? a[i].first : a[i].second; } cout << ans << '\n'; }