#define int long long #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
usingnamespacestd;
signedmain(){ fastio int a,b,c; cin >> a >> b >> c; int m; cin >> m; vector<pair<int,int>> v; //cost, type for(int i = 0;i < m;i++){ int a; string b; cin >> a >> b; v.push_back({a,b[0]=='P'}); } sort(v.begin(),v.end()); int ans = 0, num = 0; for(auto x : v){ if(x.second==0){ if(a) a--, num++, ans += x.first; elseif(c) c--, num++, ans += x.first; }else{ if(b) b--, num++, ans += x.first; elseif(c) c--, num++, ans += x.first; } } cout << num << " " << ans << "\n"; }
#define int long long #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
usingnamespacestd;
signedmain(){ fastio string a,b; cin >> a >> b; int n = a.size(), m = b.size(); int pref[m] = {}, suff[m] = {}; //Two pointers to find the maximum pos that the pref or suff of b is subsequence of a fill(pref,pref+m,n); fill(suff,suff+m,-1); int i = 0, j = 0; while(i < n&&j < m){ if(a[i]!=b[j]) i++; elseif(a[i]==b[j]){ pref[j] = i; i++, j++; } } i = n-1, j = m-1; while(~i&&~j){ if(a[i]!=b[j]) i--; elseif(a[i]==b[j]){ suff[j] = i; i--,j--; } } string ans=""; ans = b.substr(upper_bound(suff,suff+m,-1)-suff); for(int i = 0;i < m;i++){ if(pref[i]==n) break; int num = upper_bound(suff,suff+m,pref[i])-suff; if(num <= i) continue; string aa = b.substr(0,i+1), bb = b.substr(num); string cc = aa+bb; if(cc.size() > ans.size()) ans = cc; if(i==num-1) break; } if(ans.size()==0) cout << '-' << "\n"; elsecout << ans << "\n"; }