Problem: Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis!

The computers bought for the room were different. Some of them had only USB ports, some — only PS/2 ports, and some had both options.

You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once.

You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy.

Input

The first line contains three integers a, b and c (0 ≤ a, b, c ≤ 105) — the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively.

The next line contains one integer m (0 ≤ m ≤ 3·105) — the number of mouses in the price list.

The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≤ vali ≤ 109) — the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in.

Output

Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy.

Example

Input

2 1 1
4
5 USB
6 PS/2
3 PS/2
7 PS/2


Output

3 14

Note

In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.

Solution (in JAVA):

Solution:
import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Tester
{
	public static long mod=(long)(1e9+7);
	public static long xx,yy,d;
	static int minPrime[];
	static boolean isPrime[];
	
	public static void main(String[] args) throws IOException 
	{
		InputReader s=new InputReader(System.in);
        OutputStream outputStream = System.out;
        PrintWriter out=new PrintWriter(outputStream);
        
        int a=s.nextInt();
        int b=s.nextInt();
        int c=s.nextInt();
        
        int m=s.nextInt();
        
        ArrayList<Long> us = new ArrayList<>();
        ArrayList<Long> ps = new ArrayList<>();
        
        for(int i=0; i<m; i++)
        {
        	long x=s.nextLong();
        	String y = s.nextString();
        	
        	if(y.equals("USB"))
        		us.add(x);
        	else
        		ps.add(x);
        }
        		
        Collections.sort(us);
        Collections.sort(ps);
        
        long cost=0;
        long ans=0;
        
        int ind1=0;
        for(int i=0; i<Math.min(a, us.size()); i++)
        {
        	cost+=us.get(i);
        	ans++;
        	ind1++;
        }
        
        int ind2=0;
        for(int i=0; i<Math.min(b, ps.size()); i++)
        {
        	cost+=ps.get(i);
        	ans++;
        	ind2++;
        }
        
        ArrayList<Long> al = new ArrayList<>();
        
        for(int i=ind1; i<us.size(); i++)
        {
        	al.add(us.get(i));
        }
        
        for(int i=ind2; i<ps.size(); i++)
        {
        	al.add(ps.get(i));
        }
        
        Collections.sort(al);
        
        for(int i=0; i<Math.min(al.size(), c); i++)
        {
        	cost+=al.get(i);
        	ans++;
        }
        
        out.println(ans+" "+cost);
        
        out.close();
	}   
	
	static void modifiedSieve(int n)
	{
		minPrime = new int[n+1];
		
		for(int i=2; i<=Math.sqrt(n); i++)
		{
			if(minPrime[i] == 0)
			{
				for(int j=i*i; j<=n; j=j+i)
				{
					if(minPrime[j] == 0)
						minPrime[j] = i;
				}
			}
		}
		
		for(int i=2; i<=n; i++)
		{
			if(minPrime[i] == 0)
				minPrime[i] = i;
		}
		
	}
	
	static void Sieve(int n)
	{
		isPrime = new boolean[n+1];
		Arrays.fill(isPrime, true);
		
		isPrime[0]=false;
		isPrime[1]=false;
		
		for(int i=2; i<=Math.sqrt(n); i++)
		{
			if(isPrime[i])
			{
				for(int j=i*i; j<=n; j=j+i)
					isPrime[j]=false;
			}
		}
		
	}
	
	static void extendedEuclid(long A, long B)
	{
		if(B == 0) {
	        d = A;
	        xx = 1;
	        yy = 0;
	    }
	    else {
	        extendedEuclid(B, A%B);
	        long temp = xx;
	        xx = yy;
	        yy = temp - (A/B)*yy;
	    }
	}
	
	static long gcd(long a,long b)
	{
		if(b==0)
			return a;
		
		return gcd(b,a%b);
	}
	
	static long modulo(long x,long y,long p)	
	{
		 long res = 1;
		 x = x % p;  
		 
	    while (y > 0)
	    {
	        if (y%2==1)
	            res = (res*x) % p;
	 
	        y = y>>1;
	        x = (x*x) % p;  
	    }
	    return res;
	}
	
	public static void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
	
	static long exp(long a, long b)
	{
		if(b==0)
			return 1;
		if(b==1)
			return a;
		if(b==2)
			return a*a;

		if(b%2==0)
			return exp(exp(a,b/2),2);
		else
			return a*exp(exp(a,(b-1)/2),2);
	}

	static class Pair implements Comparable<Pair>
	{
		long x,y;
		Pair(long ii, long cc)
		{
			x=ii;
			y=cc;
		}
		
		public int compareTo(Pair o) 
		{
			return Long.compare(this.x, o.x);
		}
		
		public int hashCode() {
			int hu = (int) (x ^ (x >>> 32));
			int hv = (int) (y ^ (y >>> 32));
			return 31 * hu + hv;
		}
 
		public boolean equals(Object o) {
			Pair other = (Pair) o;
			return x == other.x && y == other.y;
		}
		
		public String toString() {
			return "[x=" + x + ", y=" + y + "]";
		}
		
	}

    static final class InputReader{
        private final InputStream stream;
        private final byte[] buf=new byte[1024];
        private int curChar;
        private int Chars;
        public InputReader(InputStream stream){this.stream=stream;}
        private int read()throws IOException{
            if(curChar>=Chars){
                curChar=0;
                Chars=stream.read(buf);
                if(Chars<=0)
                    return -1;
            }
            return buf[curChar++];
        }
        public final int nextInt()throws IOException{return (int)nextLong();}
        public final long nextLong()throws IOException{
            int c=read();
            while(isSpaceChar(c)){
                c=read();
                if(c==-1) throw new IOException();
            }
            boolean negative=false;
            if(c=='-'){
                negative=true;
                c=read();
            }
            long res=0;
            do{
                if(c<'0'||c>'9')throw new InputMismatchException();
                res*=10;
                res+=(c-'0');
                c=read();
            }while(!isSpaceChar(c));
            return negative?(-res):(res);
        }
        public final int[] nextIntBrray(int size)throws IOException{
            int[] arr=new int[size];
            for(int i=0;i<size;i++)arr[i]=nextInt();
            return arr;
        }
        public final String nextString()throws IOException{
            int c=read();
            while(isSpaceChar(c))c=read();
            StringBuilder res=new StringBuilder();
            do{
                res.append((char)c);
                c=read();
            }while(!isSpaceChar(c));
            return res.toString();
        }
        public final String nextLine()throws IOException{
            int c=read();
            while(isSpaceChar(c))c=read();
            StringBuilder res=new StringBuilder();
            do{
                res.append((char)c);
                c=read();
            }while(c!='\n'&&c!=-1);
            return res.toString();
        }
        private boolean isSpaceChar(int c)
        {
            return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
        }
    }
 
}