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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
import java.util.StringTokenizer;
import java.io.PrintWriter;
public class q2 {
	public static void main(String[] args) {
		InputReader s = new InputReader(System.in);
		PrintWriter o = new PrintWriter(System.out);
		int nu,nps,nb;
		nu=s.nextInt();
		nps=s.nextInt();
		nb=s.nextInt();	
		int m=s.nextInt();
		ArrayList<Integer> xu=new  ArrayList<>();
		ArrayList<Integer> xps=new  ArrayList<>();
		for(int i=0;i<m;i++){
			int c=s.nextInt();
			String s1=s.next();
			if(s1.charAt(0)=='U'){
				xu.add(c);
			}
			else{
				xps.add(c);
			}
		}
		Collections.sort(xu);
		Collections.sort(xps);
		long tot=0;
		int co=0;
		int idu,idxps;
		for(idu=0;idu<Math.min(nu,xu.size());idu++){
			tot=tot+xu.get(idu);
			co++;
		}
		for(idxps=0;idxps<Math.min(nps,xps.size());idxps++){
			tot=tot+xps.get(idxps);
			co++;
		}
		for(int i=0;i<nb;i++){
			int x=Integer.MAX_VALUE;
			if(idu<xu.size()){
				x=xu.get(idu);
			}
			int y=Integer.MAX_VALUE;
			if(idxps<xps.size()){
				y=xps.get(idxps);
			}
			if(x!=Integer.MAX_VALUE || y!=Integer.MAX_VALUE){
				if(x<y){
					tot=tot+x;
					idu++;
					co++;		
				}
				else{
					tot=tot+y;
					idxps++;
					co++;			
				}
				
			}
		}
		o.println(co+" "+tot);
		o.close();
	}

	static long GCD, Xinv, Yinv;

	static void gcd(long a, long b) {
		if (b == 0) {
			GCD = a;
			Xinv = 1;
			Yinv = 0;
		} else {
			gcd(b, a % b);
			long temp = Xinv;
			Xinv = Yinv;
			Yinv = temp - (a / b) * Yinv;
		}
	}

	static long modInverse(long a, long m) {
		gcd(a, m);
		return (Xinv % m + m) % m;
	}

	static long m = 1000000007;

	static long modularExpnentiation(long x, long y) {
		if (y == 0)
			return 1;
		if (y % 2 == 0)
			return modularExpnentiation((x * x) % m, y / 2);
		else
			return (x * modularExpnentiation(x, y - 1)) % m;
	}

	static int minPrime[];
	static long fac[], invfac[];

	static void facmod(int n, long m) {
		fac = new long[n + 1];
		invfac = new long[n + 1];
		fac[0] = 1;
		invfac[0] = 1;
		for (int i = 1; i <= n; i++) {
			fac[i] = (fac[i - 1] * i) % m;
		}
		invfac[n] = modInverse(fac[n], m);
		for (int i = n - 1; i >= 0; i--)
			invfac[i] = ((i + 1) * invfac[i + 1]) % m;
	}

	static void sieve(int n) {

		minPrime = new int[n + 1];
		for (int i = 2; i * i <= minPrime.length - 1; ++i) {
			if (minPrime[i] == 0) { //If i is prime
				for (int j = i * i; j <= minPrime.length - 1; j += i) {
					if (minPrime[j] == 0) {
						minPrime[j] = i;
					}
				}
			}
		}
		for (int i = 2; i <= minPrime.length - 1; ++i) {
			if (minPrime[i] == 0) {
				minPrime[i] = i;
			}
		}
	}

	static boolean checkprime(int N) {
		int count = 0;
		for (int i = 1; i * i <= N; ++i) {
			if (N % i == 0) {
				if (i * i == N)
					count++;
				else // i < sqrt(N) and (N / i) > sqrt(N)
					count += 2;
			}
			if (count > 2)
				break;
		}
		if (count == 2)
			return true;
		else
			return false;
	}

	static HashSet<Integer> factorize(int n) {
		HashSet<Integer> res = new HashSet<>();
		while (n != 1) {
			int x = minPrime[n];
			res.add(x);
			n /= minPrime[n];
		}
		return res;
	}

	static HashMap<Long, Integer> Primefactorize(long n) {
		HashMap<Long, Integer> res = new HashMap<Long, Integer>();
		for (long i = 2; i * i <= n; ++i) {
			while (n % i == 0) {
				if (res.containsKey(i)) {
					int x = res.get(i);
					res.put(i, x + 1);
				} else {
					res.put(i, 1);
				}
				n /= i;
			}
			if (n == 1)
				break;
		}
		if (n != 1) {
			res.put(n, 1);
		}
		return res;
	}

	public static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream inputstream) {
			reader = new BufferedReader(new InputStreamReader(inputstream));
			tokenizer = null;
		}

		public String nextLine() {
			String fullLine = null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine = reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}