#include using namespace std; //#include //using namespace atcoder; using ll = long long int; using ull = unsigned long long int; using ld = long double; constexpr ll MAX = 2000000000000000000; constexpr ld PI = 3.14159265358979; constexpr ll MOD = 998244353;//2024948111; ld dotorad(ld K){ return PI * K / 180.0; } ld radtodo(ld K){ return K * 180.0 / PI; } mt19937 mt; void randinit(){ srand((unsigned)time(NULL));mt = mt19937(rand()); } int main(){ ll N,X,Y; cin >> N >> X >> Y; vector P(N); vector C(N); for(ll i = 0; i < N; i++){ cin >> P[i] >> C[i]; } vector F(X + Y,0); ll base = 0; for(ll i = 0;i < N;i++){ if(C[i] == 'B') F[i % (X + Y)] += P[i]; else{ F[i % (X + Y)] -= P[i]; base += P[i]; } } sort(F.begin(),F.end()); for(ll y = 0;y < Y;y++){ base += F[X + Y - 1 - y]; } cout << base << endl; }