#include<bits/stdc++.h>
#include<string.h>
using namespace std;
 long long a,b,c,i=0,j=0,k,l,sum1=0,sum2=0,sum3=0,m,n=0,M,x;
long long USB[60000],PS[60000],BOTH[60000];
int main()
{
   long long int count=0;

    cin>>a>>b>>c>>M;
    while(M--)
    {

        char arr[5];
        cin>>x;
        cin>>arr;
        if(strcmp(arr,"USB")==0)
        {
            USB[i]=x;
            i++;
        }
        else if(strcmp(arr,"PS/2")==0)
        {
            PS[j]=x;
            j++;
        }

    }

    if(i!=0 && i<=a)
    {
        sort(USB,USB+i);
        for(k=0;k<i;k++)
        {
            sum1+=USB[k];
            count++;
        }

    }
    if(i>a)
    {
        sort(USB,USB+i);
        for(k=0;k<a;k++)
        {
            sum1+=USB[k];
            count++;

        }

          for(m=a;m<i;m++)
          {
              BOTH[n]=USB[m];

              n++;
          }

    }
    if(j!=0 && j<=b)
    {
        sort(PS,PS+j);
        for(l=0;l<j;l++)
        {
            sum2+=PS[l];
            count++;
        }

    }
    if(j>b)
    {
        sort(PS,PS+j);
        for(l=0; l<b; l++)
        {
            sum2+=PS[l];
            count++;

        }

         for(m=b;m<j;m++)
          {
              BOTH[n]=PS[m];
              n++;
          }

    }
    if(n!=0 && n<=c)
    {
    sort(BOTH,BOTH+n);
    for(l=0;l<n;l++)
    {

        sum3+=BOTH[l];
        count++;
    }
    }
    if(n>c)
    {
        sort(BOTH,BOTH+n);
        for(l=0;l<c;l++)
        {
            sum3+=BOTH[l];
            count++;
        }
    }

    cout<<count<<" "<<sum1+sum2+sum3<<endl;

}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
 long long a,b,c,i=0,j=0,k,l,sum1=0,sum2=0,sum3=0,m,n=0,M,x;
long long USB[50000];
long long PS[50000];
long long BOTH[50000];
int main()
{
   long long int count=0;

    cin>>a>>b>>c>>M;
    while(M--)
    {

        char arr[5];
        cin>>x;
        cin>>arr;
        if(strcmp(arr,"USB")==0)
        {
            USB[i]=x;
            i++;
        }
        else if(strcmp(arr,"PS/2")==0)
        {
            PS[j]=x;
            j++;
        }

    }

    if(i!=0 && i<=a)
    {
        sort(USB,USB+i);
        for(k=0;k<i;k++)
        {
            sum1+=USB[k];
            count++;
        }

    }
    if(i>a)
    {
        sort(USB,USB+i);
        for(k=0;k<a;k++)
        {
            sum1+=USB[k];
            count++;

        }

          for(m=a;m<i;m++)
          {
              BOTH[n]=USB[m];

              n++;
          }

    }
    if(j!=0 && j<=b)
    {
        sort(PS,PS+j);
        for(l=0;l<j;l++)
        {
            sum2+=PS[l];
            count++;
        }

    }
    if(j>b)
    {
        sort(PS,PS+j);
        for(l=0; l<b; l++)
        {
            sum2+=PS[l];
            count++;

        }

         for(m=b;m<j;m++)
          {
              BOTH[n]=PS[m];
              n++;
          }

    }
    if(n!=0 && n<=c)
    {
    sort(BOTH,BOTH+n);
    for(l=0;l<n;l++)
    {

        sum3+=BOTH[l];
        count++;
    }
    }
    if(n>c)
    {
        sort(BOTH,BOTH+n);
        for(l=0;l<c;l++)
        {
            sum3+=BOTH[l];
            count++;
        }
    }

    cout<<count<<" "<<sum1+sum2+sum3<<endl;

}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
unsigned long long int USB[50000],PS[50000],BOTH[50000];
int main()
{
    unsigned long long int a,b,c,i=0,j=0,k,l,sum1=0,sum2=0,sum3=0,m,n=0,count=0,M;

    cin>>a>>b>>c>>M;
    while(M--)
    {
        unsigned long long int x;
        char arr[5];
        cin>>x;
        cin>>arr;
        if(strcmp(arr,"USB")==0)
        {
            USB[i]=x;
            i++;
        }
        else if(strcmp(arr,"PS/2")==0)
        {
            PS[j]=x;
            j++;
        }

    }

    if(i!=0 && i<=a)
    {
        sort(USB,USB+i);
        for(k=0;k<i;k++)
        {
            sum1+=USB[k];
            count++;
        }

    }
    if(i>a)
    {
        sort(USB,USB+i);
        for(k=0;k<a;k++)
        {
            sum1+=USB[k];
            count++;

        }

          for(m=a;m<i;m++)
          {
              BOTH[n]=USB[m];

              n++;
          }

    }
    if(j!=0 && j<=b)
    {
        sort(PS,PS+j);
        for(l=0;l<j;l++)
        {
            sum2+=PS[l];
            count++;
        }

    }
    if(j>b)
    {
        sort(PS,PS+j);
        for(l=0; l<b; l++)
        {
            sum2+=PS[l];
            count++;

        }

         for(m=b;m<j;m++)
          {
              BOTH[n]=PS[m];
              n++;
          }

    }
    if(n!=0 && n<=c)
    {
    sort(BOTH,BOTH+n);
    for(l=0;l<n;l++)
    {

        sum3+=BOTH[l];
        count++;
    }
    }
    if(n>c)
    {
        sort(BOTH,BOTH+n);
        for(l=0;l<c;l++)
        {
            sum3+=BOTH[l];
            count++;
        }
    }

    cout<<count<<" "<<sum1+sum2+sum3<<endl;

}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{
    int a,b,c,i=0,j=0,k,l,sum1=0,sum2=0,sum3=0,m,n=0,count=0;
    int USB[3000],PS[3000],BOTH[3000];
    scanf("%d%d%d%d",&a,&b,&c,&m);
    while(m--)
    {
        int x;
        char arr[5];
        cin>>x;
        cin>>arr;
        if(strcmp(arr,"USB")==0)
        {
            USB[i]=x;
            i++;
        }
        else if(strcmp(arr,"PS/2")==0)
        {
            PS[j]=x;
            j++;
        }

    }

    if(i!=0 && i<=a)
    {
        sort(USB,USB+i);
        for(k=0; k<i; k++)
        {
            sum1+=USB[k];
            count++;
        }

    }
    if(i>a)
    {
        sort(USB,USB+i);
        for(k=0; k<a; k++)
        {
            sum1+=USB[k];
            count++;

        }

          for(m=a;m<i;m++)
          {
              BOTH[n]=USB[m];

              n++;
          }

    }
    if(j!=0 && j<=b)
    {
        sort(PS,PS+j);
        for(l=0; l<j; l++)
        {
            sum2+=PS[l];
            count++;
        }

    }
    if(j>b)
    {
        sort(PS,PS+j);
        for(l=0; l<b; l++)
        {
            sum2+=PS[l];
            count++;

        }

         for(m=b;m<j;m++)
          {
              BOTH[n]=PS[m];
              n++;
          }

    }
    sort(BOTH,BOTH+n);
    for(l=0;l<c;l++)
    {

        sum3+=BOTH[l];
        count++;
    }
    sum1=sum1+sum2+sum3;
    printf("%d %d\n",count,sum1);

}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{
    unsigned long long int a,b,c,i=0,j=0,k,l,sum1=0,sum2=0,sum3=0,m,n=0,count=0,M;
    unsigned long long int USB[3000],PS[3000],BOTH[3000];
    cin>>a>>b>>c>>M;
    while(M--)
    {
        unsigned long long int x;
        char arr[5];
        cin>>x;
        cin>>arr;
        if(strcmp(arr,"USB")==0)
        {
            USB[i]=x;
            i++;
        }
        else if(strcmp(arr,"PS/2")==0)
        {
            PS[j]=x;
            j++;
        }

    }

    if(i!=0 && i<=a)
    {
        sort(USB,USB+i);
        for(k=0;k<i;k++)
        {
            sum1+=USB[k];
            count++;
        }

    }
    if(i>a)
    {
        sort(USB,USB+i);
        for(k=0;k<a;k++)
        {
            sum1+=USB[k];
            count++;

        }

          for(m=a;m<i;m++)
          {
              BOTH[n]=USB[m];

              n++;
          }

    }
    if(j!=0 && j<=b)
    {
        sort(PS,PS+j);
        for(l=0;l<j;l++)
        {
            sum2+=PS[l];
            count++;
        }

    }
    if(j>b)
    {
        sort(PS,PS+j);
        for(l=0; l<b; l++)
        {
            sum2+=PS[l];
            count++;

        }

         for(m=b;m<j;m++)
          {
              BOTH[n]=PS[m];
              n++;
          }

    }
    if(n!=0 && n<=c)
    {
    sort(BOTH,BOTH+n);
    for(l=0;l<n;l++)
    {

        sum3+=BOTH[l];
        count++;
    }
    }
    if(n>c)
    {
        sort(BOTH,BOTH+n);
        for(l=0;l<c;l++)
        {
            sum3+=BOTH[l];
            count++;
        }
    }

    cout<<count<<" "<<sum1+sum2+sum3<<endl;

}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
 unsigned long long int a,b,c,i=0,j=0,k,l,sum1=0,sum2=0,sum3=0,m,n=0,M,x;
 unsigned long long int USB[30000],PS[30000],BOTH[30000];
int main()
{
   long long int count=0;

    cin>>a>>b>>c>>M;
    while(M--)
    {

        char arr[5];
        cin>>x;
        cin>>arr;
        if(strcmp(arr,"USB")==0)
        {
            USB[i]=x;
            i++;
        }
        else if(strcmp(arr,"PS/2")==0)
        {
            PS[j]=x;
            j++;
        }

    }

    if(i!=0 && i<=a)
    {
        sort(USB,USB+i);
        for(k=0;k<i;k++)
        {
            sum1+=USB[k];
            count++;
        }

    }
    if(i>a)
    {
        sort(USB,USB+i);
        for(k=0;k<a;k++)
        {
            sum1+=USB[k];
            count++;

        }

          for(m=a;m<i;m++)
          {
              BOTH[n]=USB[m];

              n++;
          }

    }
    if(j!=0 && j<=b)
    {
        sort(PS,PS+j);
        for(l=0;l<j;l++)
        {
            sum2+=PS[l];
            count++;
        }

    }
    if(j>b)
    {
        sort(PS,PS+j);
        for(l=0; l<b; l++)
        {
            sum2+=PS[l];
            count++;

        }

         for(m=b;m<j;m++)
          {
              BOTH[n]=PS[m];
              n++;
          }

    }
    if(n!=0 && n<=c)
    {
    sort(BOTH,BOTH+n);
    for(l=0;l<n;l++)
    {

        sum3+=BOTH[l];
        count++;
    }
    }
    if(n>c)
    {
        sort(BOTH,BOTH+n);
        for(l=0;l<c;l++)
        {
            sum3+=BOTH[l];
            count++;
        }
    }

    cout<<count<<" "<<sum1+sum2+sum3<<endl;

}


#include <bits/stdc++.h>

using namespace std;
#define l long long

l a,b,c,pr,val,m,t;
string s;
long long sum;
vector<l>v1,v2,v3;
pair<l,string>p[300300];

l minn(l a,l b)
{
    if(a>b)return b;
    else return a;
}

int main() {
    cin>>a>>b>>c;
    cin>>m;
    for(int i = 0;i<m;i++)
    {
        cin>>val>>s;
        p[i]=make_pair(val,s);
    }
    sort(p,p+m);
    for(int i = 0;i<m;i++)
    {
        if((p[i].second=="USB"))
        {
            if(a)a--,t++,pr+=p[i].first;
            else if(c)c--,pr+=p[i].first,t++;
        }
        else
        {
            if(b)b--,t++,pr+=p[i].first;
            else if(c)c--,t++,pr+=p[i].first;;
        }
    }
    cout<<t<<" "<<pr;

}


#include <bits/stdc++.h>

using namespace std;
#define l int

l a,b,c,pr,val,m,t;
string s;
long long sum;
vector<l>v1,v2,v3;

int main() {
    cin>>a>>b>>c;
    cin>>m;
    while(m--)
    {
        cin>>val>>s;
        if(s=="USB")v1.push_back(val);
        else v2.push_back(val);
    }
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    int vs=v1.size();
    for(int i = 0;i<min(a,vs);i++)
    {
        pr+=v1[i];
        t++;
    }
    vs=v2.size();
    for(int i = 0;i<min(vs,b);i++)
    {
        pr+=v2[i];
        t++;
    }
    if(v1.size()>a&&v2.size()>b)
    {
        merge(v1.begin()+a,v1.end(),v2.begin()+b,v2.end(),v3.begin());
        vs=v3.size();
        for(int i = 0;i<min(c,vs);i++)
        {
            pr+=v3[i];
            t++;
        }
    }
    else
    {
        if(v1.size()>a)
        {
            vs=v1.size();
        for(int i = a;i<min(c+a,vs);i++)
        {
            pr+=v1[i];
            t++;
        }
        }
        else if(v2.size()>b)
        {
            vs=v2.size();
        for(int i = b;i<min(c+b,vs);i++)
        {
            pr+=v2[i];
            t++;
        }
        }
    }
    cout<<t<<" "<<pr;
}


#include <bits/stdc++.h>

using namespace std;
#define l long long

l a,b,c,pr,val,m,t;
string s;
long long sum;
vector<l>v1,v2,v3;

l minn(l a,l b)
{
    if(a>b)return b;
    else return a;
}

int main() {
    cin>>a>>b>>c;
    cin>>m;
    while(m--)
    {
        cin>>val>>s;
        if(s=="USB")v1.push_back(val);
        else v2.push_back(val);
    }
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    int vs=v1.size();
    for(int i = 0;i<minn(a,vs);i++)
    {
        pr+=v1[i];
        t++;
    }
    vs=v2.size();
    for(int i = 0;i<minn(vs,b);i++)
    {
        pr+=v2[i];
        t++;
    }
    if(v1.size()>a&&v2.size()>b)
    {
        merge(v1.begin()+a,v1.end(),v2.begin()+b,v2.end(),v3.begin());
        vs=v3.size();
        for(int i = 0;i<minn(c,vs);i++)
        {
            pr+=v3[i];
            t++;
        }
    }
    else
    {
        if(v1.size()>a)
        {
            vs=v1.size();
        for(int i = a;i<minn(c+a,vs);i++)
        {
            pr+=v1[i];
            t++;
        }
        }
        else if(v2.size()>b)
        {
            vs=v2.size();
        for(int i = b;i<minn(c+b,vs);i++)
        {
            pr+=v2[i];
            t++;
        }
        }
    }
    cout<<t<<" "<<pr;
}


#include <iostream>
#include <algorithm>

using namespace std;

const int M = 3e5 + 5;
int a , b , c , m , ans;
long long cost;
char s[5];
pair<int , bool> val[M];

int main() {
	scanf("%d%d%d",&a,&b,&c);
	scanf("%d",&m);
	for(int i = 0 ; i < m ; ++i) {
		scanf("%d %s",&val[i].first,s);
		val[i].second = (s[0] == 'U');
	}
	sort(val , val + m);
	for(int i = 0 ; i < m ; ++i) {
		if(a && val[i].second) --a;
		else if(b && !val[i].second) --b;
		else if(c) --c;
		else continue;
		++ans;
		cost += (long long) val[i].first;
	}
	printf("%d %lld\n",ans,cost);
	return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

vector< pair<int , bool> > v;
char s[10];
unsigned int a , b , c , n , ans;
unsigned long long cost;

int main() {
  scanf("%d%d%d%d",&a,&b,&c,&n);
  v.resize(n);
  for(int i = 0 ; i < n ; ++i) {
    scanf("%d %s",v[i].first,s);
    v[i].second = s[0] == 'U' ? 1 : 0;
  }
  sort(v.begin() , v.end());
  for(int i = 0 ; i < n ; ++i) {
    if(a && v[i].second) --a;
    else if(b && !v[i].second) --b;
    else if(c) --c;
    else continue;
    ++ans;
    cost += v[i].first;
  }
  printf("%u %llu\n",ans,cost);
  return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

vector< pair<int , bool> > v;
char s[10];
unsigned int a , b , c , n , ans;
unsigned long long cost;

int main() {
  scanf("%d%d%d%d",&a,&b,&c,&n);
  v.resize(n);
  for(int i = 0 ; i < n ; ++i) {
    scanf("%d%s",v[i].first,s);
    v[i].second = s[0] == 'U' ? 1 : 0;
  }
  sort(v.begin() , v.end());
  for(int i = 0 ; i < n ; ++i) {
    if(a && v[i].second) --a;
    else if(b && !v[i].second) --b;
    else if(c) --c;
    else continue;
    ++ans;
    cost += v[i].first;
  }
  printf("%u %llu\n",ans,cost);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
	int a, b, c, i, m,j , k,n;
	cin>>a>>b>>c;
	cin>>m;
	vector<pair<int,string>>v;
	for(i=0;i<m;i++){
		string s; int pr;
		cin>>pr>>s;
		v.push_back(make_pair(pr,s));
	}
	int amount=0, no=0;
	sort(v.begin(),v.end());
	n=v.size();
	for(i=0;i<n;i++){
		if(v[i].second=="USB"){
			if(a!=0){
				amount+=v[i].first;
				no++;
				a--;
			}
			else if(c!=0){
				amount+=v[i].first;
				no++;
				c--;
			}
		}
		else if(v[i].second=="PS/2"){
			if(b!=0){
				amount+=v[i].first;
				no++;
				b--;
			}
			else if(c!=0){
				amount+=v[i].first;
				no++;
				c--;
			}
		}
	}
	cout<<no<<" "<<amount;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
	int a, b, c, i, m;
	cin>>a>>b>>c;
	cin>>m;
	vector<int>p,u;
	for(i=0;i<m;i++){
		string s; int pr;
		cin>>pr>>s;
		if(s=="USB"){
			u.push_back(pr);
		}
		else{
			p.push_back(pr);
		}
	}
	int amount, no=0;
	sort(u.begin(),u.end());
	sort(p.begin(),p.end());
	for(i=0;i<min(u.size(),p.size());i++){
		if(u[i]>=p[i]){
			if(b!=0){
				amount+=p[i];
				no++;
				b--;
			}
			else if(c!=0){
				amount+=p[i];
				no++;
				c--;
			}
		}
		else if(u[i]<p[i] && (a!=0 || c!=0)){
			if(a!=0){
				amount+=p[i];
				no++;
				a--;
			}
			else if(c!=0){
				amount+=u[i];
				no++;
				c--;
			}
		}
	}
	cout<<no<<amount;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
	ll int a, b, c, i, m,j , k,n;
	cin>>a>>b>>c;
	cin>>m;
	vector<pair<ll int,string>>v;
	for(i=0;i<m;i++){
		string s; ll int pr;
		cin>>pr>>s;
		v.push_back(make_pair(pr,s));
	}
	int amount=0, no=0;
	sort(v.begin(),v.end());
	n=v.size();
	for(i=0;i<n;i++){
		if(v[i].second=="USB"){
			if(a!=0){
				amount+=v[i].first;
				no++;
				a--;
			}
			else if(c!=0){
				amount+=v[i].first;
				no++;
				c--;
			}
		}
		else if(v[i].second=="PS/2"){
			if(b!=0){
				amount+=v[i].first;
				no++;
				b--;
			}
			else if(c!=0){
				amount+=v[i].first;
				no++;
				c--;
			}
		}
	}
	cout<<no<<" "<<amount;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
	ll int a, b, c, i, m,j , k,n, pr;
	cin>>a>>b>>c;
	cin>>m;
	string s;
	vector<pair<ll int,string>>v;
	for(i=0;i<m;i++){
		cin>>pr>>s;
		v.push_back(make_pair(pr,s));
	}
	ll int amount=0, no=0;
	sort(v.begin(),v.end());
	n=v.size();
	for(i=0;i<n;i++){
		if(v[i].second=="USB"){
			if(a!=0){
				amount+=v[i].first;
				no++;
				a--;
			}
			else if(c!=0){
				amount+=v[i].first;
				no++;
				c--;
			}
		}
		else if(v[i].second=="PS/2"){
			if(b!=0){
				amount+=v[i].first;
				no++;
				b--;
			}
			else if(c!=0){
				amount+=v[i].first;
				no++;
				c--;
			}
		}
	}
	cout<<no<<" "<<amount;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
	int a, b, c, i, m,j , k,n;
	cin>>a>>b>>c;
	cin>>m;
	vector<pair<ll int,string>>v;
	for(i=0;i<m;i++){
		string s; int pr;
		cin>>pr>>s;
		v.push_back(make_pair(pr,s));
	}
	int amount=0, no=0;
	sort(v.begin(),v.end());
	n=v.size();
	for(i=0;i<n;i++){
		if(v[i].second=="USB"){
			if(a!=0){
				amount+=v[i].first;
				no++;
				a--;
			}
			else if(c!=0){
				amount+=v[i].first;
				no++;
				c--;
			}
		}
		else if(v[i].second=="PS/2"){
			if(b!=0){
				amount+=v[i].first;
				no++;
				b--;
			}
			else if(c!=0){
				amount+=v[i].first;
				no++;
				c--;
			}
		}
	}
	cout<<no<<" "<<amount;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
	int a, b, c, i, m,j , k,n;
	cin>>a>>b>>c;
	cin>>m;
	vector<int>v;
	for(i=0;i<m;i++){
		string s; int pr;
		cin>>pr>>s;
		v.push_back(make_pair(pr,s));
	}
	int amount=0, no=0;
	sort(v.begin(),v.end());
	n=v.size();
	for(i=0;i<n;i++){
		if(v[i].second=="USB"){
			if(a!=0){
				amount+=v[i].first;
				no++;
				a--;
			}
			else if(c!=0){
				amount+=v[i].first;
				no++;
				c--;
			}
		}
		else if(v[i].second=="PS/2"){
			if(b!=0){
				amount+=v[i].first;
				no++;
				b--;
			}
			else if(c!=0){
				amount+=v[i].first;
				no++;
				c--;
			}
		}
	}
	cout<<no<<" "<<amount;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
	ll int a, b, c, i, m,j , k,n, pr;
	cin>>a>>b>>c;
	cin>>m;
	string s;
	vector<pair<ll int,string>>v;
	for(i=0;i<m;i++){
		cin>>pr>>s;
		v.push_back(make_pair(pr,s));
	}
	int amount=0, no=0;
	sort(v.begin(),v.end());
	n=v.size();
	for(i=0;i<n;i++){
		if(v[i].second=="USB"){
			if(a!=0){
				amount+=v[i].first;
				no++;
				a--;
			}
			else if(c!=0){
				amount+=v[i].first;
				no++;
				c--;
			}
		}
		else if(v[i].second=="PS/2"){
			if(b!=0){
				amount+=v[i].first;
				no++;
				b--;
			}
			else if(c!=0){
				amount+=v[i].first;
				no++;
				c--;
			}
		}
	}
	cout<<no<<" "<<amount;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int a, b, c, m;
    cin >> a >> b >> c >> m;
    vector<pair<int, string>> v(m);
    for (int i = 0; i < m; i++)
    {
        cin >> v[i].first >> v[i].second;
    }

    int ans = 0, cost = 0;
    for (int i = 0; i < m; i++)
    {
        if (a && v[i].second == "USB") a--;
        else if (b && v[i].second == "PS/2") b--;
        else if (c) c--;
        else continue;
        ans++;
        cost += v[i].first;
    }
    cout << ans << ' ' << cost << "\n";
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    long long a, b, c, m;
    cin >> a >> b >> c >> m;
    vector<pair<long long, string>> v(m);
    for (int i = 0; i < m; i++)
    {
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(), v.end());

    long long ans = 0, cost = 0;
    for (int i = 0; i < m; i++)
    {
        if (a && v[i].second == "USB") a--;
        else if (b && v[i].second == "PS/2") b--;
        else if (c) c--;
        else continue;
        ans++;
        cost += v[i].first;
    }
    cout << ans << ' ' << cost << "\n";
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int a, b, c, m;
    cin >> a >> b >> c >> m;
    vector<pair<int, string>> v(m);
    for (int i = 0; i < m; i++)
    {
        cin >> v[i].first >> v[i].second;
    }

    long long ans = 0, cost = 0;
    for (int i = 0; i < m; i++)
    {
        if (a && v[i].second == "USB") a--;
        else if (b && v[i].second == "PS/2") b--;
        else if (c) c--;
        else continue;
        ans++;
        cost += v[i].first;
    }
    cout << ans << ' ' << cost << "\n";
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int a, b, c, m;
    cin >> a >> b >> c >> m;
    vector<int> x, y; //usb and ps/2

    for (int i = 0; i < m; i++)
    {
        int aa;
        string s;
        cin >> aa >> s;

        if (s == "USB")
            x.push_back(aa);
        else
            y.push_back(aa);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    int ans = 0, cost = 0;
    int amt = min((int)x.size(), a);
    ans += amt;
    for (int i = 0; i < amt; i++)
    {
        cost += *x.begin();
        x.erase(x.begin());
    }

    amt = min((int)y.size(), b);
    ans += amt;
    for (int i = 0; i < amt; i++)
    {
        cost += *y.begin();
        y.erase(y.begin());
    }

	move(x.begin(), x.end(), y.begin());
    sort(y.begin(), y.end());
    amt = min((int) y.size(), c);
    ans += amt;
    for (int i = 0; i < amt; i++)
    {
        cost += y[i];
    }

    cout << ans << ' ' << cost << "\n";
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    long long a, b, c, m;
    cin >> a >> b >> c >> m;
    vector<pair<long long, string>> v(m);
    for (int i = 0; i < m; i++)
    {
        cin >> v[i].first >> v[i].second;
    }

    long long ans = 0, cost = 0;
    for (int i = 0; i < m; i++)
    {
        if (a && v[i].second == "USB") a--;
        else if (b && v[i].second == "PS/2") b--;
        else if (c) c--;
        else continue;
        ans++;
        cost += v[i].first;
    }
    cout << ans << ' ' << cost << "\n";
}


#include <bits/stdc++.h>
using namespace std;

#define ec '\n'
#define pb push_back

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b, c, n;
  cin >> a >> b >> c >> n;
  list<int> usb, ps2;
  for (int i = 0; i < n; i++) {
    int m; string s;
    cin >> m >> s;
    if (s[0] == 'U') usb.pb(m); else ps2.pb(m);
  }
  usb.sort(); ps2.sort();
  int cnt = 0;
  long long res = 0;
  while (c) {
    if (usb.empty() && ps2.empty()) break;
    int x, y;
    x = y = 1e9 + 10;
    if (!usb.empty()) x = usb.front();
    if (!ps2.empty()) y = ps2.front();
    if (x < y) {
      res += x;
      usb.pop_front();
    } else if (x > y) {
      res += y;
      ps2.pop_front();
    } else {
      if (a > b) {
        res += y;
        ps2.pop_front();
      } else {
        res += x;
        usb.pop_front();
      }
    }
    c--; cnt++;
  }
  while (a) {
    if (usb.empty()) break;
    res += usb.front();
    usb.pop_front();
    a--; cnt++;
  }
  while (b) {
    if (ps2.empty()) break;
    res += ps2.front();
    ps2.pop_front();
    b--; cnt++;
  }
  cout << cnt << ' ' << res;
}


#include <bits/stdc++.h>
using namespace std;

#define ec '\n'
#define pb push_back

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b, c, n;
  cin >> a >> b >> c >> n;
  vector<int> usb, ps2;
  for (int i = 0; i < n; i++) {
    int m; string s;
    cin >> m >> s;
    if (s[0] == 'U') usb.pb(m); else ps2.pb(m);
  }
  sort(begin(usb), end(usb), greater<int>());
  sort(begin(ps2), end(ps2), greater<int>());
  while (c) {
    n = a - usb.size(); int m = b - ps2.size();
    if (n < m) a++;
    else if (m < n) b++;
    c--;
  }
  int cnt = 0;
  long long res = 0;
  while (a) {
    if (usb.empty()) break;
    res += usb.back();
    usb.pop_back();
    a--; cnt++;
  }
  while (b) {
    if (ps2.empty()) break;
    res += ps2.back();
    ps2.pop_back();
    b--; cnt++;
  }
  cout << cnt << ' ' << res;
}


#include <bits/stdc++.h>
using namespace std;

#define ec '\n'
#define pb push_back

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b, c, n;
  cin >> a >> b >> c >> n;
  vector<int> usb, ps2;
  for (int i = 0; i < n; i++) {
    int m; string s;
    cin >> m >> s;
    if (s[0] == 'U') usb.pb(m); else ps2.pb(m);
  }
  sort(begin(usb), end(usb), greater<int>());
  sort(begin(ps2), end(ps2), greater<int>());
  int cnt = 0;
  long long res = 0;
  while (a) {
    if (usb.empty()) break;
    res += usb.back();
    cnt++; a--;
    usb.pop_back();
  }
  while (b) {
    if (ps2.empty()) break;
    res += ps2.back();
    cnt++; b--;
    ps2.pop_back();
  }
  while (c) {
    if (usb.empty() && ps2.empty()) break;
    int x, y; x = y = 1e9 + 10;
    if (!usb.empty()) x = usb.back();
    if (!ps2.empty()) y = ps2.back();
    if (x < y) {
      usb.pop_back();
      res += x;
      c--; cnt++;
    } else if (x > y) {
      ps2.pop_back();
      res += y;
      c--; cnt++;
    } else {
      if (usb.size() > ps2.size()) {
        c--; cnt++;
        usb.pop_back();
        res += x;
      } else {
        c--; cnt++;
        ps2.pop_back();
        res += y;
      }
    }
  }
  cout << cnt << ' ' << res;
}


#include <bits/stdc++.h>
using namespace std;

#define ec '\n'
#define pb push_back

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> a = {1};
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      a.pb(i);
      if (n / i != i) a.pb(n / i * 1LL);
    }
  }
  sort(begin(a), end(a));
  if (a[0] != n) a.pb(n);
  cout << (k > a.size() ? -1 : a[k - 1]);
}


#include <bits/stdc++.h>
using namespace std;

#define ec '\n'
#define pb push_back

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b, c, n;
  cin >> a >> b >> c >> n;
  vector<int> usb, ps2;
  for (int i = 0; i < n; i++) {
    int m; string s;
    cin >> m >> s;
    if (s[0] == 'U') usb.pb(m); else ps2.pb(m);
  }
  sort(begin(usb), end(usb), greater<int>());
  sort(begin(ps2), end(ps2), greater<int>());
  while (c) {
    n = a - usb.size(); int m = b - ps2.size();
    if (n < m) a++;
    else b++;
    c--;
  }
  int cnt = 0;
  long long res = 0;
  while (a) {
    if (usb.empty()) break;
    res += usb.back();
    usb.pop_back();
    a--; cnt++;
  }
  while (b) {
    if (ps2.empty()) break;
    res += ps2.back();
    ps2.pop_back();
    b--; cnt++;
  }
  cout << cnt << ' ' << res;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main() { IOS;
    ll usb,psb,both,m,i,pr,l,cnt=0,cost=0,n;
    string s; cin>>usb>>psb>>both>>m;
    vector<ll>a,b,c;
    for(i=0;i<m;i++)
    {
        cin>>pr>>s; c.pb(pr);
        if (s=="USB") { a.pb(pr);} else { b.pb(pr);}
    }
    sort(a.begin(),a.end()); sort(b.begin(),b.end()); sort(c.begin(),c.end());
    n=c.size(); l=a.size();
    l=min(l,usb); cnt=l;
    for(i=0;i<l;i++) { cost+=a[i];}
    l=b.size();
    l=min(l,psb); cnt+=l;
    for(i=0;i<l;i++) { cost+=b[i];}
    n-=cnt; l=c.size()-1;
    l=min(n+both,l);
    for(i=n;i<l;i++) { cnt++; cost+=c[i];}
    cout<<cnt<<" "<<cost;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main() { IOS;
    ll a,b,c,m,cnt=0,cost=0,i,l; cin>>a>>b>>c>>m;
    pair<ll,string>s[m];
    for(i=0;i<m;i++) {cin>>s[i].first>>s[i].second;}
    sort(s,s+m);
    for(i=0;i<m;i++)
    {
        if (a>0&&s[i].second=="USB") {a--;}
        else if (b>0&&s[i].second=="PS/2") {b--;}
        else if (c>0) {c--;}
        else { continue;}
        cnt++; cost+=s[i].first;
    }
    cout<<cnt<<" "<<cost;
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int maxn = 1e5+10;
const int mod = 1e9+7;

using namespace std;

void solve(){
    int a,b,c,x=0,y=0;
    cin>>a>>b>>c;
    map<string,vector<int>> list;
    int n,qtd=0;ll price=0;
    cin>>n;
    for(int i=0;i<n;++i){
        string type; int value;
        cin>>value>>type;
        x+=(type=="USB");y+=(type=="PS/2");
        list[type].pb(value);
    }
    if(x>=a && y>=b && (x-a)+(y-b)>=c){
        ll tot=0;
        for(auto x:list["USB"]) tot+=x;
        for(auto x:list["PS/2"]) tot+=x;
        cout<<a+b+c<<" "<<tot<<endl;
    }
    else{
        int i=0,j=0; ll tot=0;
        sort(all(list["USB"]));
        sort(all(list["PS/2"]));
        while(a-- && i<list["USB"].size()) tot+=list["USB"][i++];
        while(b-- && i<list["PS/2"].size()) tot+=list["PS/2"][j++];
        while(c--){
            if(i<list["USB"].size() && j<list["PS/2"].size()){
                if(list["USB"][i] <= list["PS/2"][j]){
                    tot+=list["USB"][i++];
                }
                else{
                    tot+=list["PS/2"][j++];
                }
            }
            else if(i<list["USB"].size())
                tot+=list["USB"][i++];
            else if(j<list["PS/2"].size())
                tot+=list["PS/2"][j++];
        }
        cout<<i+j<<" "<<tot<<endl;
    }
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int maxn = 1e5+10;
const int mod = 1e9+7;

using namespace std;

void solve(){
    int a,b,c,x=0,y=0;
    cin>>a>>b>>c;
    map<string,vector<int>> list;
    int n,qtd=0;ll price=0;
    cin>>n;
    for(int i=0;i<n;++i){
        string type; int value;
        cin>>value>>type;
        x+=(type=="USB");y+=(type=="PS/2");
        list[type].pb(value);
    }
    if(x>=a && y>=b && (x-a)+(y-b)>=c){
        ll tot=0;
        for(auto x:list["USB"]) tot+=x;
        for(auto x:list["PS/2"]) tot+=x;
        cout<<a+b+c<<" "<<tot<<endl;
    }
    else{
        int i=0,j=0; ll tot=0;
        //cout<<list["USB"].size()<<" "<<list["PS/2"].size()<<endl;
        while(a-- && i<list["USB"].size()) tot+=list["USB"][i++];
        while(b-- && i<list["PS/2"].size()) tot+=list["PS/2"][j++];
        while(c--){
            if(i<list["USB"].size() && j<list["PS/2"].size()){
                if(list["USB"][i] <= list["PS/2"][j]){
                    tot+=list["USB"][i++];
                }
                else{
                    tot+=list["PS/2"][j++];
                }
            }
            else if(i<list["USB"].size())
                tot+=list["USB"][i++];
            else if(j<list["PS/2"].size())
                tot+=list["PS/2"][j++];
        }
        cout<<i+j<<" "<<tot<<endl;
    }
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int maxn = 1e5+10;
const int mod = 1e9+7;

using namespace std;

void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    map<string,vector<int>> list;
    int n;
    cin>>n;
    for(int i=0;i<n;++i){
        string type; int value;
        cin>>value>>type;
        list[type].pb(value);
    }
    int i=0,j=0; ll tot=0;
    sort(all(list["USB"]));
    sort(all(list["PS/2"]));
    while(a-- && i<list["USB"].size()) tot+=list["USB"][i++];
    while(b-- && j<list["PS/2"].size()) tot+=list["PS/2"][j++];
    while(c--){
        if(i<list["USB"].size() && j<list["PS/2"].size()){
            if(list["USB"][i] <= list["PS/2"][j]){
                tot+=list["USB"][i++];
            }
            else{
                tot+=list["PS/2"][j++];
            }
        }
        else if(i<list["USB"].size())
            tot+=list["USB"][i++];
        else if(j<list["PS/2"].size())
            tot+=list["PS/2"][j++];
    }
    cout<<i+j<<" "<<tot<<endl;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio (false);
    cin.tie (0);

    //cout << "!@#!@#!@#!@#!@$%%%FFFFFFFF" << endl;

    int a, b, both;
    cin >> a >> b >> both;

    int m;
    cin >> m;
    //cout << "abadfasdfasdf!!@#" << endl;
    vector <int> usb, ps2;
    for (int i = 0; i < m; ++i) {
        int cost;
        cin >> cost;

        string typeM;
        cin >> typeM;

        if (typeM[0] == 'U') {
            usb.push_back (cost);
        }   else {
            ps2.push_back (cost);
        }
    }

    //cout << "!!!!!@#@$" << endl;

    sort (usb.begin(), usb.end());
    sort (ps2.begin(), ps2.end());

    int nMouse = 0, cost = 0;

    int iUsb;
    for (iUsb = 0; iUsb < usb.size() && a > 0; ++iUsb, --a, ++nMouse) {
        cost += usb[iUsb];
    }

    int iPs2;
    for (iPs2 = 0; iPs2 < ps2.size() && b > 0; ++iPs2, --b, ++nMouse) {
        cost += ps2[iPs2];
    }

   // cout << cost << " !!!" << endl;

    int *pUsb = &usb[iUsb];
    int *pPs2 = &ps2[iPs2];
    while (both-- > 0) {
        int UsbCost = (int)1e6;
        if (pUsb < &usb[usb.size()]) {
            UsbCost = *pUsb;
        }

        int Ps2Cost = (int)1e6;
        if (pPs2 < &ps2[ps2.size()]) {
            Ps2Cost = *pPs2;
        }

        //cout << Ps2Cost << ' ' << UsbCost << endl;

        if (Ps2Cost == (int)1e6 && UsbCost == (int)1e6) {
            break;
        }

        if (Ps2Cost < UsbCost) {
            ++pPs2;
            cost += Ps2Cost;
        }   else {
            ++pUsb;
            cost += UsbCost;
        }

        ++nMouse;
    }

    cout << nMouse << ' ' << cost << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio (false);
    cin.tie (0);

    //cout << "!@#!@#!@#!@#!@$%%%FFFFFFFF" << endl;

    int a, b, both;
    cin >> a >> b >> both;

    int m;
    cin >> m;
    //cout << "abadfasdfasdf!!@#" << endl;
    vector <int> usb, ps2;
    for (int i = 0; i < m; ++i) {
        int cost;
        cin >> cost;

        string typeM;
        cin >> typeM;

        if (typeM[0] == 'U') {
            usb.push_back (cost);
        }   else {
            ps2.push_back (cost);
        }
    }

    //cout << "!!!!!@#@$" << endl;

    sort (usb.begin(), usb.end());
    sort (ps2.begin(), ps2.end());

    int nMouse = 0, cost = 0;

    int iUsb;
    for (iUsb = 0; iUsb < usb.size() && a > 0; ++iUsb, --a, ++nMouse) {
        cost += usb[iUsb];
    }

    int iPs2;
    for (iPs2 = 0; iPs2 < ps2.size() && b > 0; ++iPs2, --b, ++nMouse) {
        cost += ps2[iPs2];
    }

   // cout << cost << " !!!" << endl;

    int *pUsb = &usb[iUsb];
    int *pPs2 = &ps2[iPs2];
    while (both-- > 0) {
        int UsbCost = 1e6;
        if (pUsb != &usb[usb.size() + 1]) {
            UsbCost = *pUsb;
        }

        int Ps2Cost = 1e6;
        if (pPs2 != &ps2[ps2.size() + 1]) {
            Ps2Cost = *pPs2;
        }

        if (Ps2Cost == 1e6 && UsbCost == 1e6) {
            break;
        }

        if (Ps2Cost < UsbCost) {
            ++pPs2;
            cost += Ps2Cost;
        }   else {
            ++pUsb;
            cost += UsbCost;
        }

        ++nMouse;
    }

    cout << nMouse << ' ' << cost << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio (false);
    cin.tie (0);

    //cout << "!@#!@#!@#!@#!@$%%%FFFFFFFF" << endl;

    int a, b, both;
    cin >> a >> b >> both;

    int m;
    cin >> m;
    //cout << "abadfasdfasdf!!@#" << endl;
    vector <int> usb, ps2;
    for (int i = 0; i < m; ++i) {
        int cost;
        cin >> cost;

        string typeM;
        cin >> typeM;

        if (typeM[0] == 'U') {
            usb.push_back (cost);
        }   else {
            ps2.push_back (cost);
        }
    }

    //cout << "!!!!!@#@$" << endl;

    sort (usb.begin(), usb.end());
    sort (ps2.begin(), ps2.end());

    long long nMouse = 0, cost = 0;

    int iUsb;
    for (iUsb = 0; iUsb < usb.size() && a > 0; ++iUsb, --a, ++nMouse) {
        cost += usb[iUsb];
    }

    int iPs2;
    for (iPs2 = 0; iPs2 < ps2.size() && b > 0; ++iPs2, --b, ++nMouse) {
        cost += ps2[iPs2];
    }

   // cout << cost << " !!!" << endl;

    int *pUsb = &usb[iUsb];
    int *pPs2 = &ps2[iPs2];
    while (both-- > 0) {
        long long UsbCost = (long long)1e12;
        if (pUsb < &usb[usb.size()]) {
            UsbCost = *pUsb;
        }

        long long Ps2Cost = (long long)1e12;
        if (pPs2 < &ps2[ps2.size()]) {
            Ps2Cost = *pPs2;
        }

        //cout << Ps2Cost << ' ' << UsbCost << endl;

        if (Ps2Cost == (long long)1e12 && UsbCost == (long long)1e12) {
            break;
        }

        if (Ps2Cost < UsbCost) {
            ++pPs2;
            cost += Ps2Cost;
        }   else {
            ++pUsb;
            cost += UsbCost;
        }

        ++nMouse;
    }

    cout << nMouse << ' ' << cost << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio (false);
    cin.tie (0);

    //cout << "!@#!@#!@#!@#!@$%%%FFFFFFFF" << endl;

    int a, b, both;
    cin >> a >> b >> both;

    int m;
    cin >> m;
    //cout << "abadfasdfasdf!!@#" << endl;
    vector <int> usb, ps2;
    for (int i = 0; i < m; ++i) {
        int cost;
        cin >> cost;

        string typeM;
        cin >> typeM;

        if (typeM[0] == 'U') {
            usb.push_back (cost);
        }   else {
            ps2.push_back (cost);
        }
    }

    //cout << "!!!!!@#@$" << endl;

    sort (usb.begin(), usb.end());
    sort (ps2.begin(), ps2.end());

    long long nMouse = 0, cost = 0;

    int iUsb;
    for (iUsb = 0; iUsb < usb.size() && a > 0; ++iUsb, --a, ++nMouse) {
        cost += usb[iUsb];
    }

    int iPs2;
    for (iPs2 = 0; iPs2 < ps2.size() && b > 0; ++iPs2, --b, ++nMouse) {
        cost += ps2[iPs2];
    }

   // cout << cost << " !!!" << endl;

    int *pUsb = &usb[iUsb];
    int *pPs2 = &ps2[iPs2];
    while (both-- > 0) {
        int UsbCost = (int)1e6;
        if (pUsb < &usb[usb.size()]) {
            UsbCost = *pUsb;
        }

        int Ps2Cost = (int)1e6;
        if (pPs2 < &ps2[ps2.size()]) {
            Ps2Cost = *pPs2;
        }

        //cout << Ps2Cost << ' ' << UsbCost << endl;

        if (Ps2Cost == (int)1e6 && UsbCost == (int)1e6) {
            break;
        }

        if (Ps2Cost < UsbCost) {
            ++pPs2;
            cost += Ps2Cost;
        }   else {
            ++pUsb;
            cost += UsbCost;
        }

        ++nMouse;
    }

    cout << nMouse << ' ' << cost << endl;

    return 0;
}


//
//  main.cpp
//  762B
//
//  Created by Parsa Alimohammadi on 8/13/1399 AP.
//  Copyright © 1399 Parsa Alimohammadi. All rights reserved.
//

#define ll long long
#define ldu long double
#define pb push_back
#define po pop_back()
#define du double
// --------------------------------------------------------------
/*
 #define paii pair<int , int>
 #define pasi pair<string,int>
 #define F first
 #define S second
 */
// --------------------------------------------------------------
#define input_txt freopen("input.txt" , "r" , stdin);
#define output_txt freopen("output.txt" , "w" , stdout);
#define Shield  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug cout << "REAlY!! ";
#define ashar(xx,ddd) cout << fixed << setprecision(xx) << ddd << endl;

#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e5 * 1 + 5, inf = 1e9+5;
int a,b,c,m,input;
deque<int> usb,ps;
ll sum ,cnt;

int main()
{
    Shield
    cin >> a >>  b >> c >> m;
    for (string s; m>0; m--) {
        cin >> input >> s;
        if (s == "USB")
            usb.pb(input);
        else
            ps.pb(input);
    }
    sort(usb.begin(), usb.end());
    sort(ps.begin(), ps.end());
    for (; !usb.empty() && a; a--)
    {
        sum += usb.front();
        usb.pop_front();
        cnt++;
    }
    for (; !ps.empty() && b; b--)
    {
        sum += ps.front();
        ps.pop_front();
        cnt++;

    }

    for (; c && (!ps.empty() || !usb.empty()); c--) {
        if (usb.empty() || usb.front() > ps.front()) {
            sum += ps.front();
            ps.pop_front();
        }

        else
        {
            sum += usb.front();
            usb.pop_front();
        }
        cnt ++;

    }

    cout << cnt << " " << sum;
    return 0;
}


//
//  main.cpp
//  762B
//
//  Created by Parsa Alimohammadi on 8/13/1399 AP.
//  Copyright © 1399 Parsa Alimohammadi. All rights reserved.
//

#define ll long long
#define ldu long double
#define pb push_back
#define po pop_back()
#define du double
// --------------------------------------------------------------
/*
 #define paii pair<int , int>
 #define pasi pair<string,int>
 #define F first
 #define S second
 */
// --------------------------------------------------------------
#define input_txt freopen("input.txt" , "r" , stdin);
#define output_txt freopen("output.txt" , "w" , stdout);
#define Shield  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug cout << "REAlY!! ";
#define ashar(xx,ddd) cout << fixed << setprecision(xx) << ddd << endl;

#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e5 * 1 + 5, inf = 1e9+5;
int a,b,c,m,input;
deque<int> usb,ps;
ll sum ,cnt;

int main()
{
    Shield
    cin >> a >>  b >> c >> m;
    for (string s; m>0; m--) {
        cin >> input >> s;
        if (s == "USB")
            usb.pb(input);
        else
            ps.pb(input);
    }
    sort(usb.begin(), usb.end());
    sort(ps.begin(), ps.end());
    for (; !usb.empty() && a; a--)
    {
        sum += usb.front();
        usb.pop_front();
        cnt++;
    }
    for (; !ps.empty() && b; b--)
    {
        sum += ps.front();
        ps.pop_front();
        cnt++;

    }

    for (; c && (!ps.empty() || !usb.empty()); c--) {
        if (!ps.empty() && (usb.empty() || usb.front() >= ps.front())) {
            sum += ps.front();
            ps.pop_front();
        }

        else
        {
            sum += usb.front();
            usb.pop_front();
        }
        cnt ++;

    }

    cout << cnt << " " << sum;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll a, b, c, m, cnt = 0, sum = 0; cin >> a >> b >> c >> m;
    vector<ll> p, u;
    while(m--){
        ll q; string k;
        cin >> q >> k;
        if(k == "USB") u.push_back(q);
        else p.push_back(q);
    }
    sort(u.begin(), u.end());
    sort(p.begin(), p.end());
    vector<ll> unite;
    vector<ll> uc = u, pc = p;
    for(int i = 1; i < u.size(); i++) u[i] += u[i-1];
    for(int i = 1; i < p.size(); i++) p[i] += p[i-1];
    ll p1 = -1, p2 = -1;
    if(u.size() >= a) {
        cnt +=a;
        sum += u[a-1];
        p1 = a;
    }
    else {
        sum += u[u.size()-1];
        cnt += u.size();
    }
    if(p.size() >= b) {
        cnt +=b;
        sum += p[b-1];
        p2 = b;
    }
    else {
        sum += p[p.size()-1];
        cnt += p.size();
    }
    if(p1 != -1) for(int i = a; i < uc.size(); i++) unite.push_back(uc[i]);
    if(p2 != -1) for(int i = b; i < pc.size(); i++) unite.push_back(pc[i]);
    sort(unite.begin(), unite.end());
    if(unite.size()){
        if(c <= unite.size()){
            cnt += c;
            for(int i = 0; i < c; i++) sum += unite[i];
        }
        else{
            cnt += unite.size();
            for(int i = 0; i < unite.size(); i++) sum += unite[i];
        }
    }

    cout << cnt << " " << sum << "\n";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll a, b, c, m, cnt = 0, sum = 0; cin >> a >> b >> c >> m;
    vector<ll> p, u;
    if(m == 0){
        return cout << 0 << " " << 0 << "\n", 0;
    }
    for(int i = 0; i < m; i++){
        ll q; string k;
        cin >> q >> k;
        if(k == "USB") u.push_back(q);
        else p.push_back(q);
    }
    sort(u.begin(), u.end());
    sort(p.begin(), p.end());
    vector<ll> unite;
    vector<ll> uc = u, pc = p;
    for(int i = 1; i < u.size(); i++) u[i] += u[i-1];
    for(int i = 1; i < p.size(); i++) p[i] += p[i-1];
    ll p1 = -1, p2 = -1;
    ll q;
    if(a && m && u.size()){
        if(u.size() >= a) {
            cnt += min(a, m);
            q = min(a, m);
            sum += u[q-1];
            p1 = q;
            m -= min(a, m);
        }
        else  {
            q = min(m, (ll)u.size());
            sum += u[q-1];
            cnt += q;
            m -= min((ll)u.size(), m);
        }
    }
    if(b && m && p.size()) {
        if(p.size() >= b){
            q = min(m, b);
            cnt += q;
            sum += p[q - 1];
            p2 = q;
            m -= min(m, b);
        }
        else {
            q = min(m, (ll)p.size());
            sum += p[q-1];
            cnt += q;
            m -= min((ll)p.size(), m);
        }
    }
    if(m && c){
        if(a == 0 ) p1 = 0;
        if(b == 0) p2 = 0;
        if(p1 != -1) for(int i = a; i < uc.size(); i++) unite.push_back(uc[i]);
        if(p2 != -1) for(int i = b; i < pc.size(); i++) unite.push_back(pc[i]);
        sort(unite.begin(), unite.end());
        for(int i = 1; i < unite.size(); i++) unite[i] += unite[i-1];
        if(unite.size() && c){
            if(c <= unite.size()){
                q = min(m, c);
                cnt += q;
                sum += unite[q-1];
            }
            else{
                q = min((ll)unite.size(), m);
                cnt += q;
                sum += unite[q-1];
            }
        }
    }

    cout << cnt << " " << sum << "\n";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll a, b, c, m, cnt = 0, sum = 0; cin >> a >> b >> c >> m;
    vector<ll> p, u;
    if(m == 0){
        return cout << 0 << " " << 0 << "\n", 0;
    }
    while(m--){
        ll q; string k;
        cin >> q >> k;
        if(k == "USB") u.push_back(q);
        else p.push_back(q);
    }
    sort(u.begin(), u.end());
    sort(p.begin(), p.end());
    vector<ll> unite;
    vector<ll> uc = u, pc = p;
    for(int i = 1; i < u.size(); i++) u[i] += u[i-1];
    for(int i = 1; i < p.size(); i++) p[i] += p[i-1];
    ll p1 = -1, p2 = -1;
    if(u.size() >= a && a) {
        cnt +=a;
        sum += u[a-1];
        p1 = a;
    }
    else if(a) {
        sum += u[u.size()-1];
        cnt += u.size();
    }
    if(p.size() >= b && b) {
        cnt +=b;
        sum += p[b-1];
        p2 = b;
    }
    else if(b) {
        sum += p[p.size()-1];
        cnt += p.size();
    }
    if(a == 0 ) p1 = 0;
    if(b == 0) p2 = 0;
    if(p1 != -1) for(int i = a; i < uc.size(); i++) unite.push_back(uc[i]);
    if(p2 != -1) for(int i = b; i < pc.size(); i++) unite.push_back(pc[i]);
    sort(unite.begin(), unite.end());
    if(unite.size() && c){
        if(c <= unite.size()){
            cnt += c;
            for(int i = 0; i < c; i++) sum += unite[i];
        }
        else{
            cnt += unite.size();
            for(int i = 0; i < unite.size(); i++) sum += unite[i];
        }
    }

    cout << cnt << " " << sum << "\n";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll a, b, c, m, cnt = 0, sum = 0; cin >> a >> b >> c >> m;
    vector<ll> p, u;
    if(m == 0){
        return cout << 0 << " " << 0 << "\n", 0;
    }
    for(int i = 0; i < m; i++){
        ll q; string k;
        cin >> q >> k;
        if(k == "USB") u.push_back(q);
        else p.push_back(q);
    }
    sort(u.begin(), u.end());
    sort(p.begin(), p.end());
    vector<ll> unite;
    vector<ll> uc = u, pc = p;
    for(int i = 1; i < u.size(); i++) u[i] += u[i-1];
    for(int i = 1; i < p.size(); i++) p[i] += p[i-1];
    ll p1 = -1, p2 = -1;
    ll q;
    if(a && m){
        if(u.size() >= a) {
            cnt += min(a, m);
            q = min(a, m);
            sum += u[q-1];
            p1 = q;
            m -= min(a, m);
        }
        else {
            q = min(m, (ll)u.size());
            sum += u[q-1];
            cnt += q;
            m -= min((ll)u.size(), m);
        }
    }
    if(b && m) {
        if(p.size() >= b){
            q = min(m, b);
            cnt += q;
            sum += p[q - 1];
            p2 = q;
            m -= min(m, b);
        }
        else {
            q = min(m, (ll)p.size());
            sum += p[q-1];
            cnt += q;
            m -= min((ll)p.size(), m);
        }
    }
    if(m && c){
        if(a == 0 ) p1 = 0;
        if(b == 0) p2 = 0;
        if(p1 != -1) for(int i = a; i < uc.size(); i++) unite.push_back(uc[i]);
        if(p2 != -1) for(int i = b; i < pc.size(); i++) unite.push_back(pc[i]);
        sort(unite.begin(), unite.end());
        for(int i = 1; i < unite.size(); i++) unite[i] += unite[i-1];
        if(unite.size() && c){
            if(c <= unite.size()){
                q = min(m, c);
                cnt += q;
                sum += unite[q-1];
            }
            else{
                q = min((ll)unite.size(), m);
                cnt += q;
                sum += unite[q-1];
            }
        }
    }

    cout << cnt << " " << sum << "\n";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll a, b, c, m, cnt = 0, sum = 0; cin >> a >> b >> c >> m;
    vector<ll> p, u;
    if(m == 0){
        return cout << 0 << " " << 0 << "\n", 0;
    }
    while(m--){
        ll q; string k;
        cin >> q >> k;
        if(k == "USB") u.push_back(q);
        else p.push_back(q);
    }
    sort(u.begin(), u.end());
    sort(p.begin(), p.end());
    vector<ll> unite;
    vector<ll> uc = u, pc = p;
    for(int i = 1; i < u.size(); i++) u[i] += u[i-1];
    for(int i = 1; i < p.size(); i++) p[i] += p[i-1];
    ll p1 = -1, p2 = -1;
    if(u.size() >= a && a) {
        cnt +=a;
        sum += u[a-1];
        p1 = a;
    }
    else if(a) {
        sum += u[u.size()-1];
        cnt += u.size();
    }
    if(p.size() >= b && b) {
        cnt +=b;
        sum += p[b-1];
        p2 = b;
    }
    else if(b) {
        sum += p[p.size()-1];
        cnt += p.size();
    }
    if(p1 != -1) for(int i = a; i < uc.size(); i++) unite.push_back(uc[i]);
    if(p2 != -1) for(int i = b; i < pc.size(); i++) unite.push_back(pc[i]);
    sort(unite.begin(), unite.end());
    if(unite.size() && c){
        if(c <= unite.size()){
            cnt += c;
            for(int i = 0; i < c; i++) sum += unite[i];
        }
        else{
            cnt += unite.size();
            for(int i = 0; i < unite.size(); i++) sum += unite[i];
        }
    }

    cout << cnt << " " << sum << "\n";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll a, b, c, m, cnt = 0, sum = 0; cin >> a >> b >> c >> m;
    vector<ll> p, u;
    if(m == 0){
        return cout << 0 << " " << 0 << "\n", 0;
    }
    while(m--){
        ll q; string k;
        cin >> q >> k;
        if(k == "USB") u.push_back(q);
        else p.push_back(q);
    }
    sort(u.begin(), u.end());
    sort(p.begin(), p.end());
    vector<ll> unite;
    vector<ll> uc = u, pc = p;
    for(int i = 1; i < u.size(); i++) u[i] += u[i-1];
    for(int i = 1; i < p.size(); i++) p[i] += p[i-1];
    ll p1 = -1, p2 = -1;
    if(u.size() >= a && a) {
        cnt +=a;
        sum += u[a-1];
        p1 = a;
    }
    else {
        sum += u[u.size()-1];
        cnt += u.size();
    }
    if(p.size() >= b && b) {
        cnt +=b;
        sum += p[b-1];
        p2 = b;
    }
    else {
        sum += p[p.size()-1];
        cnt += p.size();
    }
    if(p1 != -1) for(int i = a; i < uc.size(); i++) unite.push_back(uc[i]);
    if(p2 != -1) for(int i = b; i < pc.size(); i++) unite.push_back(pc[i]);
    sort(unite.begin(), unite.end());
    if(unite.size()){
        if(c <= unite.size()){
            cnt += c;
            for(int i = 0; i < c; i++) sum += unite[i];
        }
        else{
            cnt += unite.size();
            for(int i = 0; i < unite.size(); i++) sum += unite[i];
        }
    }

    cout << cnt << " " << sum << "\n";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll a, b, c, m, cnt = 0, sum = 0; cin >> a >> b >> c >> m;
    vector<ll> p, u;
    if(m == 0){
        return cout << 0 << " " << 0 << "\n", 0;
    }
    for(int i = 0; i < m; i++){
        ll q; string k;
        cin >> q >> k;
        if(k == "USB") u.push_back(q);
        else p.push_back(q);
    }
    sort(u.begin(), u.end());
    sort(p.begin(), p.end());
    vector<ll> unite;
    vector<ll> uc = u, pc = p;
    for(int i = 1; i < u.size(); i++) u[i] += u[i-1];
    for(int i = 1; i < p.size(); i++) p[i] += p[i-1];
    ll p1 = -1, p2 = -1;
    ll q;
    if(a && m){
        if(u.size() >= a) {
            cnt += min(a, m);
            q = min(a, m);
            sum += u[q-1];
            p1 = q;
            m -= min(a, m);
        }
        else {
            q = min(m, (ll)u.size());
            sum += u[q-1];
            cnt += q;
            m -= min((ll)u.size(), m);
        }
    }
    if(b && m) {
        if(p.size() >= b){
            q = min(m, b);
            cnt += q;
            sum += p[q - 1];
            p2 = q;
            m -= min(m, b);
        }
        else {
            q = min(m, (ll)p.size());
            sum += p[q-1];
            cnt += q;
            m -= min((ll)p.size(), m);
        }
    }
    if(m){
        if(a == 0 ) p1 = 0;
        if(b == 0) p2 = 0;
        if(p1 != -1) for(int i = a; i < uc.size(); i++) unite.push_back(uc[i]);
        if(p2 != -1) for(int i = b; i < pc.size(); i++) unite.push_back(pc[i]);
        sort(unite.begin(), unite.end());
        for(int i = 1; i < unite.size(); i++) unite[i] += unite[i-1];
        if(unite.size() && c){
            if(c <= unite.size()){
                q = min(m, c);
                cnt += q;
                sum += unite[q-1];
            }
            else{
                q = min((ll)unite.size(), m);
                cnt += q;
                sum += unite[q-1];
            }
        }
    }

    cout << cnt << " " << sum << "\n";

}


#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F(i, n) for (int i = 0; i < int(n); i++)

typedef unsigned long ul;
typedef long long ll;

int main()
{
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	ll a, b, c, m, x;
	cin >> a >> b >> c >> m;
	vector<ll> usb, ps;
	string s;
	while (m--)
	{
		cin >> x >> s;
		if (s[0] == 'U')
			usb.pb(x);
		else
			ps.pb(x);
	}
	sort(all(ps));
	sort(all(usb));
	ll sum = 0, eq = 0, pss = 0, usbs = 0;
	if (m == 0)
		cout << sum << " " << eq << endl;
	else
	{
		for (ul i = 0; i < ps.size() and b; i++, b--, eq++)
		{
			sum += ps[i];
			if (b == 1 or i == ps.size() - 1)
				pss = i + 1;
		}
		for (ul i = 0; i < usb.size() and a; i++, a--, eq++)
		{
			sum += usb[i];
			if (a == 1 or i == usb.size() - 1)
				usbs = i + 1;
		}
		for (ul i = pss, j = usbs; c; c--, eq++)
		{
			if (i == ps.size() and j == usb.size())
				break;
			else if (j == usb.size())
			{
				if (i < ps.size())
				{
					sum += ps[i];
					i++;
				}
				else
					break;
			}
			else if (i == ps.size())
			{
				if (j < usb.size())
				{
					sum += usb[j];
					j++;
				}
				else
					break;
			}
			else
			{
				if (ps[i] > usb[j] and j < usb.size())
				{
					sum += usb[j];
					j++;
				}
				else if (ps[i] <= usb[j] and i < ps.size())
				{
					sum += ps[i];
					i++;
				}
			}
		}
	}
	cout << eq << " " << sum << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F(i, n) for (int i = 0; i < int(n); i++)

typedef unsigned long ul;
typedef long long ll;

int main()
{
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int a, b, c, m, x;
	cin >> a >> b >> c >> m;
	vector<int> usb, ps;
	string s;
	while (m--)
	{
		cin >> x >> s;
		if (s[0] == 'U')
			usb.pb(x);
		else
			ps.pb(x);
	}
	sort(all(ps));
	sort(all(usb));
	int sum = 0, eq = 0, pss, usbs;
	for (ul i = 0, j = 0; c; c--, eq++)
	{
		if (ps[i] > usb[j] and j < usb.size())
		{
			sum += usb[j];
			j++;
		}
		else if (ps[i] <= usb[j] and i < ps.size())
		{
			sum += ps[i];
			i++;
		}
		if (c == 1)
		{
			usbs = j;
			pss = i;
		}
	}
	for (ul i = pss; i < ps.size() and b; i++, b--, eq++)
		sum += ps[i];
	for (ul i = usbs; i < usb.size() and a; i++, a--, eq++)
		sum += usb[i];
	cout << eq << " " << sum << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F(i, n) for (int i = 0; i < int(n); i++)

typedef unsigned long ul;
typedef long long ll;

int main()
{
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	ll a, b, c, m, x;
	cin >> a >> b >> c >> m;
	vector<ll> usb, ps;
	string s;
	while (m--)
	{
		cin >> x >> s;
		if (s[0] == 'U')
			usb.pb(x);
		else
			ps.pb(x);
	}
	sort(all(ps));
	sort(all(usb));
	ll sum = 0, eq = 0, pss, usbs;
	for (ul i = 0; i < ps.size() and b; i++, b--, eq++)
	{
		sum += ps[i];
		if (b == 1 or i == ps.size() - 1)
			pss = i + 1;
	}
	for (ul i = 0; i < usb.size() and a; i++, a--, eq++)
	{
		sum += usb[i];
		if (a == 1 or i == usb.size() - 1)
			usbs = i + 1;
	}
	for (ul i = pss, j = usbs; c; c--, eq++)
	{
		if (i == ps.size() and j == usb.size())
			break;
		else if (j == usb.size())
		{
			if (i < ps.size())
			{
				sum += ps[i];
				i++;
			}
			else
				break;
		}
		else if (i == ps.size())
		{
			if (j < usb.size())
			{
				sum += usb[j];
				j++;
			}
			else
				break;
		}
		else
		{
			if (ps[i] > usb[j] and j < usb.size())
			{
				sum += usb[j];
				j++;
			}
			else if (ps[i] <= usb[j] and i < ps.size())
			{
				sum += ps[i];
				i++;
			}
		}
	}
	cout << eq << " " << sum << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> usb, ps2;
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        int val;
        cin >> val;
        string type;
        cin >> type;
        if (type[0] == 'U') {
            usb.emplace_back(val);
        } else {
            ps2.emplace_back(val);
        }
    }
    usb.emplace_back(2000000000);
    ps2.emplace_back(2000000000);
    int m_usb = 0, m_ps2 = 0;
    long long cost = 0;
    sort(usb.begin(), usb.end());
    sort(ps2.begin(), ps2.end());
    for (int i = 0; i < m; ++i) {
        int v1 = 2000000000, v2 = 2000000000;
        if (a != 0 || c != 0) {
            v1 = usb[m_usb];
        }
        if (b != 0 || c != 0) {
            v2 = ps2[m_ps2];
        }
        if (v1 < v2) {
            cost += usb[m_usb];
            m_usb++;
            if (a != 0) {
                a--;
            } else {
                c--;
            }
        } else if (v1 > v2) {
            cost += ps2[m_ps2];
            m_ps2++;
            if (b != 0) {
                b--;
            } else {
                c--;
            }
        } else if (v1 == 2000000000) {
            break;
        }
    }
    cout << m_usb + m_ps2 << ' ' << cost;
}


#include <bits/stdc++.h>
#define int long long

using namespace std;

int32_t main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> usb, ps2;
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        int val;
        cin >> val;
        string type;
        cin >> type;
        if (type[0] == 'U') {
            usb.emplace_back(val);
        } else {
            ps2.emplace_back(val);
        }
    }
    usb.emplace_back(2000000000);
    ps2.emplace_back(2000000000);
    int m_usb = 0, m_ps2 = 0;
    long long cost = 0;
    sort(usb.begin(), usb.end());
    sort(ps2.begin(), ps2.end());
    for (int i = 0; i < m; ++i) {
        int v1 = 2000000000, v2 = 2000000000;
        if (a != 0 || c != 0) {
            v1 = usb[m_usb];
        }
        if (b != 0 || c != 0) {
            v2 = ps2[m_ps2];
        }
        if (v1 < v2) {
            cost += usb[m_usb];
            m_usb++;
            if (a != 0) {
                a--;
            } else {
                c--;
            }
        } else if (v1 > v2) {
            cost += ps2[m_ps2];
            m_ps2++;
            if (b != 0) {
                b--;
            } else {
                c--;
            }
        } else if (v1 == 2000000000) {
            break;
        }
    }
    cout << m_usb + m_ps2 << ' ' << cost;
}


#include <bits/stdc++.h>
#define int long long

using namespace std;

int32_t main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> usb, ps2;
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        int val;
        cin >> val;
        string type;
        cin >> type;
        if (type[0] == 'U') {
            usb.emplace_back(val);
        } else {
            ps2.emplace_back(val);
        }
    }
    usb.emplace_back(200000000000);
    ps2.emplace_back(200000000000);
    int m_usb = 0, m_ps2 = 0;
    long long cost = 0;
    sort(usb.begin(), usb.end());
    sort(ps2.begin(), ps2.end());
    for (int i = 0; i < m; ++i) {
        int v1 = 200000000000, v2 = 200000000000;
        if (a != 0 || c != 0) {
            v1 = usb[m_usb];
        }
        if (b != 0 || c != 0) {
            v2 = ps2[m_ps2];
        }
        if (v1 < v2) {
            cost += usb[m_usb];
            m_usb++;
            if (a != 0) {
                a--;
            } else {
                c--;
            }
        } else if (v1 >= v2 && v2 != 200000000000) {
            cost += ps2[m_ps2];
            m_ps2++;
            if (b != 0) {
                b--;
            } else {
                c--;
            }
        } else if (v1 == 200000000000) {
            break;
        }
    }
    cout << m_usb + m_ps2 << ' ' << cost;
}


#include <bits/stdc++.h>
#define int long long

using namespace std;

int32_t main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> usb, ps2;
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        int val;
        cin >> val;
        string type;
        cin >> type;
        if (type[0] == 'U') {
            usb.emplace_back(val);
        } else {
            ps2.emplace_back(val);
        }
    }
    usb.emplace_back(200000000000);
    ps2.emplace_back(200000000000);
    int m_usb = 0, m_ps2 = 0;
    long long cost = 0;
    sort(usb.begin(), usb.end());
    sort(ps2.begin(), ps2.end());
    for (int i = 0; i < m; ++i) {
        int v1 = 200000000000, v2 = 200000000000;
        if (a != 0 || c != 0) {
            v1 = usb[m_usb];
        }
        if (b != 0 || c != 0) {
            v2 = ps2[m_ps2];
        }
        if (v1 < v2) {
            cost += usb[m_usb];
            m_usb++;
            if (a != 0) {
                a--;
            } else {
                c--;
            }
        } else if (v1 > v2) {
            cost += ps2[m_ps2];
            m_ps2++;
            if (b != 0) {
                b--;
            } else {
                c--;
            }
        } else if (v1 == 200000000000) {
            assert(m_usb == usb.size() && m_ps2 == ps2.size());
            break;
        }
    }
    cout << m_usb + m_ps2 << ' ' << cost;
}


#include <bits/stdc++.h>
#define int long long

using namespace std;

int32_t main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> usb, ps2;
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        int val;
        cin >> val;
        string type;
        cin >> type;
        if (type[0] == 'U') {
            usb.emplace_back(val);
        } else {
            ps2.emplace_back(val);
        }
    }
    usb.emplace_back(200000000000);
    ps2.emplace_back(200000000000);
    int m_usb = 0, m_ps2 = 0;
    long long cost = 0;
    sort(usb.begin(), usb.end());
    sort(ps2.begin(), ps2.end());
    for (int i = 0; i < m; ++i) {
        int v1 = 200000000000, v2 = 200000000000;
        if (a != 0 || c != 0) {
            v1 = usb[m_usb];
            assert(m_usb < usb.size());
        }
        if (b != 0 || c != 0) {
            v2 = ps2[m_ps2];
            assert(m_ps2 < ps2.size());
        }
        if (v1 < v2) {
            cost += usb[m_usb];
            m_usb++;
            if (a != 0) {
                a--;
            } else {
                assert(c != 0);
                c--;
            }
        } else if (v1 > v2) {
            cost += ps2[m_ps2];
            m_ps2++;
            if (b != 0) {
                b--;
            } else {
                assert(c != 0);
                c--;
            }
        } else if (v1 == 200000000000) {
            break;
        }
    }
    cout << m_usb + m_ps2 << ' ' << cost;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test long int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define inf (1e9+5)
#define mod 1000000007

bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int a, b, c;
	cin >> a >> b >> c;
	int m;
	cin >> m;

	vector<pair<int, string>>v1;
	vector<pair<int, string>>v2;
	vector<pair<int, string>>v;
	zip(i, 0, m)
	{
		int x;
		cin >> x;
		string y;
		cin >> y;
		v.pb(mp(x, y));
	}
	int cnt = 0;
	int sum = 0;
	int ca = 0;
	int cb = 0;
	int cc = 0;

	sort(v.begin(), v.end());
	zip(i, 0, v.size())
	{
		if (v[i].ss == "USB" && ca < a)
		{
			cnt++;
			sum += v[i].ff;
			ca++;
		}
		else if (v[i].ss == "PS/2" && cb < b)
		{
			cnt++;
			sum += v[i].ff;
			cb++;
		}
		else if (cc < c)
		{
			cnt++;
			sum += v[i].ff;
			cc++;
		}

	}
	cout << cnt << " " << sum << en;

	/*zip(i, 0, c)
	{
		if (j1 >= v1.size() && j2 >= v2.size())
		{
			break;
		}
		else if (j1 >= v1.size())
		{
			sum += v2[j2].ff;
			j2++;
			cnt++;
		}
		else if (j2 >= v2.size())
		{
			sum += v1[j1].ff;
			j1++;
			cnt++;
		}
		else
		{
			if (v1[j1] < v2[j2])
			{
				sum += v1[j1].ff;
				j1++;
				cnt++;
			}
			else
			{
				sum += v2[j2].ff;
				j2++;
				cnt++;
			}
		}
	}*/

	//zip()

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test long int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define inf (1e9+5)
#define mod 1000000007

bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int a, b, c;
	cin >> a >> b >> c;
	int m;
	cin >> m;

	vector<pair<int, string>>v1;
	vector<pair<int, string>>v2;
	vector<pair<int, string>>v;
	zip(i, 0, m)
	{
		int x;
		cin >> x;
		string y;
		cin >> y;
		v.pb(mp(x, y));
		if (y == "USB")
		{
			v1.pb(mp(x, y));
		}
		else
		{
			v2.pb(mp(x, y));
		}
	}
	int j1 = 0;
	int j2 = 0;
	int n1 = v1.size();
	int n2 = v2.size();
	int cnt = 0;
	int sum = 0;
	int ca = 0;
	int cb = 0;
	int cc = 0;

	sort(v.begin(), v.end());
	zip(i, 0, v.size())
	{
		if (cc < c)
		{
			cnt++;
			sum += v[i].ff;
			cc++;
		}
		else
		{
			if (v[i].ss == "USB" && ca < a)
			{
				cnt++;
				sum += v[i].ff;
				ca++;
			}
			else if (v[i].ss == "PS/2" && cb < c)
			{
				cnt++;
				sum += v[i].ff;
				cb++;
			}
		}
	}
	cout << cnt << " " << sum << en;

	zip(i, 0, c)
	{
		if (j1 >= v1.size() && j2 >= v2.size())
		{
			break;
		}
		else if (j1 >= v1.size())
		{
			sum += v2[j2].ff;
			j2++;
			cnt++;
		}
		else if (j2 >= v2.size())
		{
			sum += v1[j1].ff;
			j1++;
			cnt++;
		}
		else
		{
			if (v1[j1] < v2[j2])
			{
				sum += v1[j1].ff;
				j1++;
				cnt++;
			}
			else
			{
				sum += v2[j2].ff;
				j2++;
				cnt++;
			}
		}
	}

	//zip()

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test long int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define inf (1e9+5)
#define mod 1000000007

bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int a, b, c;
	cin >> a >> b >> c;
	int m;
	cin >> m;

	vector<pair<int, string>>v1;
	vector<pair<int, string>>v2;
	vector<pair<int, string>>v;
	zip(i, 0, m)
	{
		int x;
		cin >> x;
		string y;
		cin >> y;
		v.pb(mp(x, y));
	}
	int cnt = 0;
	int sum = 0;
	int ca = 0;
	int cb = 0;
	int cc = 0;

	sort(v.begin(), v.end());
	zip(i, 0, v.size())
	{

		if (v[i].ss == "USB" && ca < a)
		{
			cnt++;
			sum += v[i].ff;
			ca++;
		}
		else if (v[i].ss == "PS/2" && cb < c)
		{
			cnt++;
			sum += v[i].ff;
			cb++;
		}
		else if (cc < c)
		{
			cnt++;
			sum += v[i].ff;
			cc++;
		}

	}
	cout << cnt << " " << sum << en;

	/*zip(i, 0, c)
	{
		if (j1 >= v1.size() && j2 >= v2.size())
		{
			break;
		}
		else if (j1 >= v1.size())
		{
			sum += v2[j2].ff;
			j2++;
			cnt++;
		}
		else if (j2 >= v2.size())
		{
			sum += v1[j1].ff;
			j1++;
			cnt++;
		}
		else
		{
			if (v1[j1] < v2[j2])
			{
				sum += v1[j1].ff;
				j1++;
				cnt++;
			}
			else
			{
				sum += v2[j2].ff;
				j2++;
				cnt++;
			}
		}
	}*/

	//zip()

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define f first
#define s second
#define vi vector<int>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vii vector<pair<int, int>>
#define vvb vector<vector<bool>>
#define piii pair<int, pair<int, int>>
#define vvpii vector<vector<pair<int, int>>>
#define inf 987654321
#define pb push_back
#define p push
#define ll long long
#define ull unsigned long long
#define get g

int main(void) {
    ll A, B, C, M, e = 0;
    cin >> A >> B >> C >> M;
    vector<ll> u, p;
    for (int i = 0; i < M; i++)
    {
        ll a;
        string s;
        cin >> a >> s;
        if (s[0] == 'U')
            u.pb(a);
        else
            p.pb(a);
    }
    sort (u.begin(), u.end());
    sort(p.begin(), p.end());
    ll mo = 0;
    ll uc = 0, pc = 0;
    for (int i = 0; i < min(A, (ll)u.size()); i++)
    {
        mo += u[i];
        uc++;
        e++;
    }
    for (int i = 0; i < min(B, (ll)p.size()); i++) {
        mo += p[i];
        pc++;
        e++;
    }
    for (int i = 0; i < C; i++)
    {
        if (uc < u.size() && pc < p.size())
        {
            if (p[pc] < u[uc])
            {
                mo += p[pc];
                pc++;
                e++;
            }
            else
            {
                mo += u[uc];
                uc++;
                e++;
            }
        }
        else if (uc < u.size())
        {
            mo += u[uc];
            uc++;
            e++;
        }
        else if (pc < p.size())
        {
            mo += p[pc];
            pc++;
            e++;
        }
        else
            break;
    }
    cout << e << " " << mo << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define f first
#define s second
#define vi vector<int>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vii vector<pair<int, int>>
#define vvb vector<vector<bool>>
#define piii pair<int, pair<int, int>>
#define vvpii vector<vector<pair<int, int>>>
#define inf 987654321
#define pb push_back
#define p push
#define ll long long
#define ull unsigned long long
#define get g

int main(void) {
    int A, B, C, M, e = 0;
    cin >> A >> B >> C >> M;
    vector<int> u, p;
    for (int i = 0; i < M; i++)
    {
        int a;
        string s;
        cin >> a >> s;
        if (s[0] == 'U')
            u.pb(a);
        else
            p.pb(a);
    }
    sort (u.begin(), u.end());
    sort(p.begin(), p.end());
    int mo = 0;
    int uc = 0, pc = 0;
    for (int i = 0; i < min(A, (int)u.size()); i++)
    {
        mo += u[i];
        uc++;
        e++;
    }
    for (int i = 0; i < min(B, (int)p.size()); i++) {
        mo += p[i];
        pc++;
        e++;
    }
    for (int i = 0; i < C; i++)
    {
        if (uc < u.size() && pc < p.size())
        {
            if (p[pc] < u[uc])
            {
                mo += p[pc];
                pc++;
                e++;
            }
            else
            {
                mo += u[uc];
                uc++;
                e++;
            }
        }
        else if (uc < u.size())
        {
            mo += u[uc];
            uc++;
            e++;
        }
        else if (pc < p.size())
        {
            mo += p[pc];
            pc++;
            e++;
        }
        else
            break;
    }
    cout << e << " " << mo << endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	long long int a, b, c;  cin>>a>>b>>c;
	long m;  cin>>m;
	vector<long> usb, ps2;
	for(long i=0; i<m; i++)
	{
		long x; string s;
		cin>>x>>s;
		if(s=="USB")
		usb.push_back(x);

		else
		ps2.push_back(x);
	}

	sort(usb.begin(), usb.end());
	sort(ps2.begin(), ps2.end());

	long long int count=0, cost=0, i, s;

	for(i=0; i<min(s, a); i++)
	{
		s=usb.size();
		if(s==0)
		break;

		cost+=*(usb.begin());
		usb.erase(usb.begin());
		count++;
	}

	for(i=0; i<b; i++)
	{
		s=ps2.size();
		if(s==0)
		break;

		cost+=*(ps2.begin());
		ps2.erase(ps2.begin());
		count++;
	}

	for(i=0; i<c; i++)
	{
		s=usb.size()+ps2.size();
		if(s==0)
		break;

		long long int pp=INT_MAX, uu=INT_MAX;
		if(!ps2.empty())
	    pp=*(ps2.begin());

        if(!usb.empty())
        uu=*(usb.begin());

        if(pp < uu)
		{
            cost+= pp;
            ps2.erase(ps2.begin());
        }
        else
		{
            cost+= uu;
            usb.erase(usb.begin());
        }

		count++;
	}

	cout<<count<<" "<<cost;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	long long int a, b, c;  cin>>a>>b>>c;
	long m;  cin>>m;
	vector<long> usb, ps2;
	for(long i=0; i<m; i++)
	{
		long x; string s;
		cin>>x>>s;
		if(s=="USB")
		usb.push_back(x);

		else
		ps2.push_back(x);
	}

	sort(usb.begin(), usb.end());
	sort(ps2.begin(), ps2.end());

	long long int count=0, cost=0, i, s;

	for(i=0; i<min(s, a); i++)
	{
		s=usb.size();
		if(s==0)
		break;

		cost+=*(usb.begin());
		usb.erase(usb.begin());
		count++;
	}

	for(i=0; i<b; i++)
	{
		s=ps2.size();
		if(s==0)
		break;

		cost+=*(ps2.begin());
		ps2.erase(ps2.begin());
		count++;
	}

	for(i=0; i<c; i++)
	{
		s=usb.size()+ps2.size();
		if(s==0)
		break;

		if(usb.size()==0 || *(ps2.begin())<=*(usb.begin()))
		{
			cost+=*(ps2.begin());
			ps2.erase(ps2.begin());
		}

		else if(ps2.size()==0 || *(ps2.begin())>=*(usb.begin()))
		{
			cost+=*(usb.begin());
			usb.erase(usb.begin());
		}

		count++;
	}

	cout<<count<<" "<<cost;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);  cout.tie(NULL);

	long long int a, b, c;  cin>>a>>b>>c;
	long m;  cin>>m;
	vector<long> usb, ps2;
	for(long i=0; i<m; i++)
	{
		long x; string s;
		cin>>x>>s;
		if(s=="USB")
		usb.push_back(x);

		else
		ps2.push_back(x);
	}

	sort(usb.begin(), usb.end());
	sort(ps2.begin(), ps2.end());

	long long int count=0, cost=0, i, s;

	for(i=0; i<a; i++)
	{
		if(usb.empty())
		break;

		cost+=*(usb.begin());
		usb.erase(usb.begin());
		count++;
	}

	for(i=0; i<b; i++)
	{
		if(ps2.empty())
		break;

		cost+=*(ps2.begin());
		ps2.erase(ps2.begin());
		count++;
	}

	for(i=0; i<c; i++)
	{
		if(usb.empty() && ps2.empty())
		break;

		long long int pp=INT_MAX, uu=INT_MAX;
		if(!ps2.empty())
	    pp=*(ps2.begin());

        if(!usb.empty())
        uu=*(usb.begin());

        if(pp < uu)
		{
            cost+= pp;
            ps2.erase(ps2.begin());
        }
        else
		{
            cost+= uu;
            usb.erase(usb.begin());
        }

		count++;
	}

	cout<<count<<" "<<cost;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	long long int a, b, c;  cin>>a>>b>>c;
	long m;  cin>>m;
	vector<long> usb, ps2;
	for(long i=0; i<m; i++)
	{
		long x; string s;
		cin>>x>>s;
		if(s=="USB")
		usb.push_back(x);

		else
		ps2.push_back(x);
	}

	sort(usb.begin(), usb.end());
	sort(ps2.begin(), ps2.end());

	long long int count=0, cost=0, i, s;
	s=usb.size();
	for(i=0; i<min(s, a); i++)
	{
		cost+=*(usb.begin());
		usb.erase(usb.begin());
		count++;
	}

	s=ps2.size();
	for(i=0; i<min(s, b); i++)
	{
		cost+=*(ps2.begin());
		ps2.erase(ps2.begin());
		count++;
	}

	s=usb.size()+ps2.size();
	for(i=0; i<min(s, c); i++)
	{
		if(usb.size()==0 || *(ps2.begin())<=*(usb.begin()))
		{
			cost+=*(ps2.begin());
			ps2.erase(ps2.begin());
		}

		else if(ps2.size()==0 || *(ps2.begin())>=*(usb.begin()))
		{
			cost+=*(usb.begin());
			usb.erase(usb.begin());
		}
		count++;
	}

	cout<<count<<" "<<cost;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);  cout.tie(NULL);

	long long int a, b, c;  cin>>a>>b>>c;
	long m;  cin>>m;
	vector<long long int> usb, ps2, v;
	for(long i=0; i<m; i++)
	{
		long x; string s;
		cin>>x>>s;
		if(s=="USB")
		usb.push_back(x);

		else
		ps2.push_back(x);
	}

	sort(usb.begin(), usb.end());
	sort(ps2.begin(), ps2.end());

	long long int count=0, cost=0, i, s, j;

	s=usb.size();
	for(i=0; i<s; i++)
	{
		if(a==0)
		break;

		cost+=usb[i];
		a--;
		count++;
	}

	s=ps2.size();
	for(j=0; j<s; j++)
	{
		if(b==0)
		break;

		cost+=ps2[j];
		b--;
		count++;
	}

	while(i<usb.size())
	{
		v.push_back(usb[i]);
		i++;
	}

	while(j<ps2.size())
	{
		v.push_back(ps2[j]);
		j++;
	}

	sort(v.begin(), v.end());
	s=v.size();
	for(long k=0; k<s; k++)
	{
		if(c==0)
		break;

		cost+=v[k];
		c--;
		count++;
	}

	cout<<count<<" "<<cost;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	long long int a, b, c;  cin>>a>>b>>c;
	long m;  cin>>m;
	vector<long> usb, ps2;
	for(long i=0; i<m; i++)
	{
		long x; string s;
		cin>>x>>s;
		if(s=="USB")
		usb.push_back(x);

		else
		ps2.push_back(x);
	}

	sort(usb.begin(), usb.end());
	sort(ps2.begin(), ps2.end());

	long long int count=0, cost=0, i, s;

	for(i=0; i<a; i++)
	{
		if(usb.empty())
		break;

		cost+=*(usb.begin());
		usb.erase(usb.begin());
		count++;
	}

	for(i=0; i<b; i++)
	{
		if(ps2.empty())
		break;

		cost+=*(ps2.begin());
		ps2.erase(ps2.begin());
		count++;
	}

	for(i=0; i<c; i++)
	{
		if(usb.empty() && ps2.empty())
		break;

		long long int pp=INT_MAX, uu=INT_MAX;
		if(!ps2.empty())
	    pp=*(ps2.begin());

        if(!usb.empty())
        uu=*(usb.begin());

        if(pp < uu)
		{
            cost+= pp;
            ps2.erase(ps2.begin());
        }
        else
		{
            cost+= uu;
            usb.erase(usb.begin());
        }

		count++;
	}

	cout<<count<<" "<<cost;
}


// Author : deetav
// Happy stalking ! :P
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define ll long long
#define ld long double
#define endl "\n"

const ld PI = acos(-1);
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
const int mod1 = 998244353;
const ll INF = 2e18;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);cerr.tie(nullptr);
    //test
    {
        vector <pair<int64_t,int64_t>> vv;
        int64_t n,m,k;cin>>n>>m>>k;int64_t tot=0;
        int64_t z;cin>>z;
        while(z--){
            int64_t zz;string s;
            cin>>zz>>s;
            if(s[0]=='U'){
                vv.push_back({zz,1LL});
            }else{
                vv.push_back({zz,2LL});
            }
        }
        sort(vv.begin(),vv.end());reverse(vv.begin(),vv.end());
        int64_t out=0;
        while(k-- && vv.size()){
            out+=vv[vv.size()-1].first;
            vv.pop_back();++tot;
        }
        vector <int64_t> u,p;
        for(int i=0;i<vv.size();i++){
            if(vv[i].second==2){
                p.push_back(vv[i].first);
            }else{
                u.push_back(vv[i].first);
            }
        }
        sort(p.begin(),p.end());reverse(p.begin(),p.end());
        sort(u.begin(),u.end());reverse(u.begin(),u.end());
        while(m-- && p.size()){
            out+=p[p.size()-1];
            p.pop_back();++tot;
        }
        while(n-- && u.size()){
            out+=u[u.size()-1];
            u.pop_back();++tot;
        }
        cout<<tot<<" "<<out<<endl;

    }
    return EXIT_SUCCESS;
}


// Author : deetav
// Happy stalking ! :P
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define ll long long
#define ld long double
#define endl "\n"

const ld PI = acos(-1);
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
const int mod1 = 998244353;
const ll INF = 2e18;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);cerr.tie(nullptr);
    //test
    {
        int64_t n,m,k;cin>>n>>m>>k;int64_t tot=0;
        int64_t z;
        cin >> z;
        vector<int64_t> u, p;
        while(z--){
            int64_t zz;string s;
            cin>>zz>>s;
            if(s[0]=='U'){
                u.push_back(zz);
            }else{
                p.push_back(zz);
            }
        }
        int64_t out=0;
        sort(p.begin(),p.end());reverse(p.begin(),p.end());
        sort(u.begin(),u.end());reverse(u.begin(),u.end());
        while(m-- && p.size()){
            out+=p[p.size()-1];
            p.pop_back();++tot;
        }
        while(n-- && u.size()){
            out+=u[u.size()-1];
            u.pop_back();++tot;
        }
        u.insert(u.end(), p.begin(),p.end());
        sort(u.begin(),u.end());
        // for(auto x:u){
        //     cout<<x<<" ";
        // }
        int64_t j=0LL;
        while(k-- && j<u.size()){
            out+=u[j];++j;++tot;
        }
        cout<<tot<<" "<<out<<endl;

    }
    return EXIT_SUCCESS;
}


// Author : deetav
// Happy stalking ! :P
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define ll long long
#define ld long double
#define endl "\n"

const ld PI = acos(-1);
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
const int mod1 = 998244353;
const ll INF = 2e18;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);cerr.tie(nullptr);
    //test
    {
        int64_t n,m,k;cin>>n>>m>>k;int64_t tot=0;
        int64_t z;
        cin >> z;
        vector<int64_t> u, p;
        while(z--){
            int64_t zz;string s;
            cin>>zz>>s;
            if(s[0]=='U'){
                u.push_back(zz);
            }else{
                p.push_back(zz);
            }
        }
        int64_t out=0;
        sort(p.begin(),p.end());reverse(p.begin(),p.end());
        sort(u.begin(),u.end());reverse(u.begin(),u.end());
        while(m-- && p.size()){
            out+=p[p.size()-1];
            p.pop_back();++tot;
        }
        while(n-- && u.size()){
            out+=u[u.size()-1];
            u.pop_back();++tot;
        }
        u.insert(u.end(), p.begin(),p.end());
        sort(u.begin(),u.end());
        int j=0;
        while(k-- && u.size()){
            out+=u[j];++j;++tot;
        }
        cout<<tot<<" "<<out<<endl;

    }
    return EXIT_SUCCESS;
}


# include <bits/stdc++.h>
using namespace std ;
typedef long long int ll ;

int main(){
   ll usb , ps , both ;
   cin >> usb >> ps >> both ;
   ll  n ;
   cin >> n ;
   vector <ll> us,p ;
   ll x ;
   string s ;
   for(ll i=0;i<n;i++){
       cin >> x >> s ;
       if(s=="USB"){
           us.push_back(x) ;
       }
       else{
           p.push_back(x) ;
       }
   }

   // first sell usb , then ps2 , then both
   sort(p.begin(),p.end()) ;
   sort(us.begin(),us.end()) ;
   ll current_ps = 0, current_us = 0 , sum =0 , c =0  ;
   if(usb > us.size()){
       current_us = us.size()+10 ;
       sum = accumulate(us.begin(),us.end(),sum) ;
       c += us.size() ;
   }
   else{
       current_us = usb ;
       sum = accumulate(us.begin(),us.begin()+usb,sum) ;
       c += usb ;

   }

   if(ps > p.size()){
       current_ps = p.size()+10  ;
       sum = accumulate(p.begin(),p.end(),sum) ;
       c += p.size() ;
   }
   else{
       current_ps = ps ;
       sum = accumulate(p.begin(),p.begin()+ps,sum) ;
       c += ps ;

   }

   // cout << sum <<" "<<c ;
   vector <ll> left ;
   for(ll i= current_us;i<us.size();i++){
       left.push_back(us[i]) ;
   }
   for(ll i= current_ps;i<p.size();i++){
       left.push_back(p[i]) ;
   }
    // cout << c <<" "<<sum <<"\n" ;

    // cout <<"\n" ;
    sort(left.begin(),left.end()) ;
//     for(ll i=0;i<left.size();i++){
//        cout << left[i] <<" " ;
//    }
//    cout <<"\n" ;
   if(both >left.size()){
       c += left.size() ;
       sum = accumulate(left.begin(),left.end(),sum) ;
   }
   else{
       c += both ;
       sum = accumulate(left.begin(),left.begin()+both,sum) ;
   }

   cout <<c<<" "<<sum<<"\n" ;

    return 0 ;

}


# include <bits/stdc++.h>
using namespace std ;
typedef long long int ll ;

int main(){
   ll usb , ps , both ;
   cin >> usb >> ps >> both ;
   ll  n ;
   cin >> n ;
   vector <ll> us,p ;
   ll x ;
   string s ;
   for(ll i=0;i<n;i++){
       cin >> x >> s ;
       if(s=="USB"){
           us.push_back(x) ;
       }
       else{
           p.push_back(x) ;
       }
   }

   // first sell usb , then ps2 , then both
   sort(p.begin(),p.end()) ;
   sort(us.begin(),us.end()) ;
   ll current_ps = 0, current_us = 0 , sum =0 , c =0  ;
   if(usb > us.size()){
       current_us = us.size()+10 ;
       sum = accumulate(us.begin(),us.end(),sum) ;
       c += us.size() ;
   }
   else{
       current_us = usb ;
       sum = accumulate(us.begin(),us.begin()+usb,sum) ;
       c += usb ;

   }

   if(ps > p.size()){
       current_ps = p.size()+10  ;
       sum = accumulate(p.begin(),p.end(),sum) ;
       c += p.size() ;
   }
   else{
       current_ps = ps ;
       sum = accumulate(p.begin(),p.begin()+ps,sum) ;
       c += ps ;

   }

   // cout << sum <<" "<<c ;
   vector <ll> left ;
   for(ll i= current_us;i<us.size();i++){
       left.push_back(us[i]) ;
   }
   for(ll i= current_ps;i<p.size();i++){
       left.push_back(p[i]) ;
   }
  //  cout << c <<" "<<sum <<"\n" ;
   for(ll i=0;i<left.size();i++){
      // cout << left[i] <<" " ;
   }
//    cout <<"\n" ;
//    sort(left.begin(),left.end()) ;
   if(both >left.size()){
       c += left.size() ;
       sum = accumulate(left.begin(),left.end(),sum) ;
   }
   else{
       c += both ;
       sum = accumulate(left.begin(),left.begin()+both,sum) ;
   }

   cout <<c<<" "<<sum<<"\n" ;

    return 0 ;

}


# include <bits/stdc++.h>
using namespace std ;

typedef long long int ll ;

int main(){
   ll usb , ps , both ;
   cin >> usb >> ps >> both ;
   ll  n ;
   cin >> n ;
   vector <ll> us,p ;
   ll x ;
   string s ;
   for(ll i=0;i<n;i++){
       cin >> x >> s ;
       if(s=="USB"){
           us.push_back(x) ;
       }
       else{
           p.push_back(x) ;
       }
   }

   // first sell usb , then ps2 , then both
   sort(p.begin(),p.end()) ;
   sort(us.begin(),us.end()) ;
   ll current_ps = 0, current_us = 0 , sum =0 , c =0  ;
   if(usb > us.size()){
       current_us = -1 ;
       sum = accumulate(us.begin(),us.end(),sum) ;
       c += us.size() ;
   }
   else{
       current_us = usb ;
       sum = accumulate(us.begin(),us.begin()+usb,sum) ;
       c += usb ;

   }

   if(ps > p.size()){
       current_ps = -1 ;
       sum = accumulate(p.begin(),p.end(),sum) ;
       c += p.size() ;
   }
   else{
       current_ps = ps ;
       sum = accumulate(p.begin(),p.begin()+ps,sum) ;
       c += ps ;

   }

   // cout << sum <<" "<<c ;
   vector <ll> left ;
   for(ll i= current_us;i<us.size();i++){
       left.push_back(us[i]) ;
   }
   for(ll i= current_ps;i<p.size();i++){
       left.push_back(p[i]) ;
   }
  //  cout << c <<" "<<sum <<"\n" ;
   for(ll i=0;i<left.size();i++){
      // cout << left[i] <<" " ;
   }
//    cout <<"\n" ;
//    sort(left.begin(),left.end()) ;
   if(both >left.size()){
       c += left.size() ;
       sum = accumulate(left.begin(),left.end(),sum) ;
   }
   else{
       c += both ;
       sum = accumulate(left.begin(),left.begin()+both,sum) ;
   }

   cout << c <<" "<<sum ;

    return 0 ;

}


# include<bits/stdc++.h>
using namespace std ;

typedef long long int ll ;

int main(){
   ll usb , ps , both ;
   cin >> usb >> ps >> both ;
   ll  n ;
   cin >> n ;
   vector <ll> us,p ;
   ll x ;
   string s ;
   for(ll i=0;i<n;i++){
       cin >> x >> s ;
       if(s=="USB"){
           us.push_back(x) ;
       }
       else{
           p.push_back(x) ;
       }
   }

   // first sell usb , then ps2 , then both
   sort(p.begin(),p.end()) ;
   sort(us.begin(),us.end()) ;
   ll current_ps = 0, current_us = 0 , sum =0 , c =0  ;
   if(usb > us.size()){
       current_us = -1 ;
       sum = accumulate(us.begin(),us.end(),sum) ;
       c += us.size() ;
   }
   else{
       current_us = usb ;
       sum = accumulate(us.begin(),us.begin()+usb,sum) ;
       c += usb ;

   }

   if(ps > p.size()){
       current_ps = -1 ;
       sum = accumulate(p.begin(),p.end(),sum) ;
       c += p.size() ;
   }
   else{
       current_ps = ps ;
       sum = accumulate(p.begin(),p.begin()+ps,sum) ;
       c += ps ;

   }

   // cout << sum <<" "<<c ;
   vector <ll> left ;
   for(ll i= current_us;i<us.size();i++){
       left.push_back(us[i]) ;
   }
   for(ll i= current_ps;i<p.size();i++){
       left.push_back(p[i]) ;
   }

    sort(left.begin(),left.end()) ;
   if(both >left.size()){
       c += left.size() ;
       sum = accumulate(left.begin(),left.end(),sum) ;
   }
   else{
       c += both ;
       sum = accumulate(left.begin(),left.begin()+both,sum) ;
   }

   cout << c <<" "<<sum ;

    return 0 ;

}


#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define cout2(x, y) cout<<x<<" "<<y<<endl
#define MAXN 300005

using namespace std;

int tree[MAXN];

int query(int x){

    int ans = 0;
    for(int i = x; i > 0; i -= i&-i)ans += tree[i];
    return ans;
}

void update(int x, int val){

    for(int i = x; i < MAXN; i += i&-i)tree[i] += val;

}

vector<int>L[MAXN];
int S[MAXN];

int main(){

    int n, p, x, y;
    while(cin>>n>>p){

        for(int i = 0; i < n; i++){
            cin>>x>>y;
            if(x > y)swap(x, y);

            L[x].pb(y);
            S[x]++, S[y]++;

        }

        for(int i = 1; i <= n; i++)update(S[i], 1);
        long long ans = 0;

        for(int i = 1; i <= n; i++)sort(all(L[i]));

        for(int i = 1; i <= n; i++){

            update(S[i], -1);
            ans += n - i - query(max(0, p - S[i] - 1));

            if(L[i].size() == 0)continue;
            int ct = 1;

            for(int j = 1; j < L[i].size(); j++){

                    if(L[i][j - 1] == L[i][j])ct++;
                    else{

                        if(S[i] + S[L[i][j - 1]] >= p && S[i] + S[L[i][j - 1]] - ct < p)ans--;
                        ct = 1;

                    }
            }

            int pos = L[i].back();
            if(ct > 0 && S[i] + S[pos] >= p && S[i] + S[pos] - ct < p)ans--;

        }

        cout<<ans<<endl;
    }

}


#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define cout2(x, y) cout<<x<<" "<<y<<endl
#define MAXN 300002

using namespace std;

int tree[MAXN];

int query(int x){

    int ans = 0;
    for(int i = x; i > 0; i -= i&-i)ans += tree[i];
    return ans;
}

void update(int x, int val){

    for(int i = x; i < MAXN; i += i&-i)tree[i] += val;

}

vector<int>L[MAXN];
int S[MAXN];

int main(){

    int n, p, x, y;
    while(cin>>n>>p){

        for(int i = 0; i < n; i++){
            scanf("%d%d", &x, &y);
            if(x > y)swap(x, y);

            L[x].pb(y);
            S[x]++, S[y]++;

        }

        for(int i = 1; i <= n; i++)if(S[i] > 0)update(S[i], 1);
        long long ans = 0;

        for(int i = 1; i <= n; i++)sort(all(L[i]));

        for(int i = 1; i <= n; i++){

            if(S[i] > 0)update(S[i], -1);
            ans += n - i - query(max(0, p - S[i] - 1));

            if(L[i].size() == 0)continue;
            int ct = 1;

            for(int j = 1; j < L[i].size(); j++){

                    if(L[i][j - 1] == L[i][j])ct++;
                    else{

                        if(S[i] + S[L[i][j - 1]] >= p && S[i] + S[L[i][j - 1]] - ct < p)ans--;
                        ct = 1;

                    }
            }

            int pos = L[i].back();
            if(ct > 0 && S[i] + S[pos] >= p && S[i] + S[pos] - ct < p)ans--;

        }

        cout<<ans<<endl;
    }

}