#include #include #define chmin(x,y) (x) = min((x),(y)) #define chmax(x,y) (x) = max((x),(y)) #define ld long double using namespace std; using namespace atcoder; using ll = long long; const ll mod = 998244353; using mint = modint998244353; using Graph = vector>>; const vector dx = {1,0,-1,0}, dy = {0,1,0,-1}; int main(){ int N,X,Y; cin >> N >> X >> Y; int M = X + Y; vector A(M),B(M); for(int i = 0; i < N; i++){ int p; char c; cin >> p >> c; if(c == 'A') A[i%M] += p; else B[i%M] += p; } ll ans = 0; priority_queue pq; for(int i = 0; i < M; i++){ ans += A[i]; pq.push(B[i]-A[i]); } for(int i = 0; i < Y; i++){ ans += pq.top(); pq.pop(); } cout << ans << endl; }