#include using namespace std; using ll=long long; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N,X,Y; cin>>N>>X>>Y; vector cnt(X+Y,0ll); ll ans=0; for(int i=0;i>P>>C; if(C=='A'){ cnt[i%(X+Y)]+=P; }else{ ans+=P; cnt[i%(X+Y)]-=P; } } sort(cnt.begin(),cnt.end(),greater()); for(int i=0;i