#include #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using ll = long long; #define fi first #define se second #define rep(i,n) for(ll i=0;i> N >> X >> Y; ll mod=X+Y; vector cntA(mod,0),cntB(mod,0); rep(i,N){ ll p; char c; cin >> p >> c; if(c=='A') cntA[i%mod]+=p; if(c=='B') cntB[i%mod]+=p; } vector cnt(mod); rep(i,mod) cnt[i]=cntA[i]-cntB[i]; sort(all(cnt)); reverse(all(cnt)); ll ans=0; rep(i,mod) ans+=cntB[i]; rep(i,X) ans+=cnt[i]; cout << ans << endl; return 0; }