#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n,x,y; cin>>n>>x>>y; int z=x+y; vector P(n); vector C(n); rep(i,n) cin>>P[i]>>C[i]; if(z==0){ cout<<0< A(z),B(z); rep(i,n){ if(C[i]=='A') A[i%z]+=P[i]; else B[i%z]+=P[i]; } ll ans=0; vector D(z); rep(i,z){ D[i]=A[i]-B[i]; ans+=B[i]; } sort(ALL(D)); reverse(ALL(D)); rep(i,x) ans+=D[i]; cout<