#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000001 int main(){ int N; int c[2]; cin>>N>>c[0]>>c[1]; vector cnt(c[0]+c[1],vector(2,0)); rep(i,N){ long long t; cin>>t; char tt; cin>>tt; cnt[i%(c[0]+c[1])][tt-'A'] += t; } long long ans = 0; vector hoge; rep(i,c[0]+c[1]){ ans += cnt[i][0]; hoge.push_back(cnt[i][1]-cnt[i][0]); } sort(hoge.rbegin(),hoge.rend()); rep(i,c[1]){ ans += hoge[i]; } cout<