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.BufferedInputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


@SuppressWarnings("unused")
public class Main {

    public static void main(String[] args) throws IOException {

//		long startTime = new Date().getTime();

        InputReader in = new InputReader(System.in);
//		InputReader in = new InputReader(new FileInputStream(new File("simple.in")));

        PrintWriter writer = new PrintWriter(System.out);
//		PrintWriter writer = new PrintWriter("simple.out");

        solveTheProblem(in, writer);

//		long endTime = new Date().getTime();
//		System.err.println("Time: " + (endTime - startTime) + " millis");

    }

    static class Mouse implements Comparable<Mouse> {
        Integer price;
        @Override
        public int compareTo(Mouse mouse) {
            if (price.equals(mouse.price)) return -1; // we don't want equality
            return price.compareTo(mouse.price);
        }
    }

    public static void solveTheProblem(InputReader in, PrintWriter writer) throws IOException {

        int a = in.ni(); // usb
        int b = in.ni(); // ps/2
        int c = in.ni(); // both

        int m = in.ni();

        Set<Mouse> usb = new TreeSet<>();
        Set<Mouse> ps2 = new TreeSet<>();

        for (int i = 0; i < m; i++) {
            int val = in.ni();
            String type = in.nstr();
            Mouse mouse = new Mouse();
            mouse.price = val;
            if ("USB".equals(type)) {
                usb.add(mouse);
            } else {
                ps2.add(mouse);
            }
        }

        Iterator<Mouse> usbIT = usb.iterator();
        Iterator<Mouse> ps2IT = ps2.iterator();

        int equipped = 0;
        long spent = 0;
        while (a > 0 && usbIT.hasNext()) {
            equipped++;
            spent += usbIT.next().price;
            a--;
        }
        while (b > 0 && ps2IT.hasNext()) {
            equipped++;
            spent += ps2IT.next().price;
            b--;
        }
        int nextUSB = Integer.MAX_VALUE;
        int nextPS2 = Integer.MAX_VALUE;
        for(;;) {
            if (c == 0) break;
            if (usbIT.hasNext() && nextUSB == Integer.MAX_VALUE) nextUSB = usbIT.next().price;
            if (ps2IT.hasNext() && nextPS2 == Integer.MAX_VALUE) nextPS2 = ps2IT.next().price;
            if (nextUSB == Integer.MAX_VALUE && nextPS2 == Integer.MAX_VALUE) break;
            if (nextUSB < nextPS2) {
                spent += nextUSB;
                nextUSB = Integer.MAX_VALUE;
            } else {
                spent += nextPS2;
                nextPS2 = Integer.MAX_VALUE;
            }
            equipped++;
            c--;
        }

        writer.println(equipped + " " + spent);

        // don't forget partial flushes!
        writer.flush();

    }

    /** Utils **/

    private static final long MOD = (long) Math.pow(10, 9)+7;

    private static long mod(long n) {
        return n % MOD;
    }

    private static int pow(int n, int p) {
        return (int) Math.pow(n, p);
    }

    private static long pow(long n, long p) {
        return (long) Math.pow(n, p);
    }

    private static class BIT {

        private int n;
        private long[] freqs;
        private long[] cumulativeFreqs;

        public BIT(int n) {
            this.n = n;
            this.freqs = new long[n];
            this.cumulativeFreqs = new long[n];
        }

        public void add(int idx, long v) {

            this.freqs[idx] = mod(this.freqs[idx] + v);

            int i = idx;
            while (i < n) {

                this.cumulativeFreqs[i] = mod(this.cumulativeFreqs[i] + v);

                int lastDigit = i & -i;
                i += lastDigit;

            }

        }

        public long getCumulativeSum(int idx) {

            long ans = 0;

            int i = idx;
            while (i > 0) {

                ans = mod(ans + this.cumulativeFreqs[i]);

                int lastDigit = i & -i;
                i -= lastDigit;

            }

            return ans;
        }

    }

    private static String joinWithSpaces(Object... a) {
        StringBuilder str = new StringBuilder();
        if (a.length > 0) {
            str.append(a[0]);
            for (int i = 1; i < a.length; i++) {
                str.append(' ');
                str.append(a[i]);
            }
        }
        return str.toString();
    }

    private static String joinWithSpaces(long[] a) {
        StringBuilder str = new StringBuilder();
        if (a.length > 0) {
            str.append(a[0]);
            for (int i = 1; i < a.length; i++) {
                str.append(' ');
                str.append(a[i]);
            }
        }
        return str.toString();
    }

    private static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    private static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    private static boolean[] createPrimeSieve(int n) {
        boolean[] sieve = new boolean[n+1];
        Arrays.fill(sieve, true);
        for (int i = 2; i <= n; i++) {
            if (sieve[i]) {
                for (int j = i+i; j <= n; j += i)
                    sieve[j] = false;
            }
        }
        return sieve;
    }

    private static int countPrimes(boolean[] sieve) {
        int ans = 0;
        for (int i = 2; i < sieve.length; i++)
            if (sieve[i]) ans++;
        return ans;
    }

    public static class InputReader implements Closeable {

        //		private InputStream in;
        private Scanner in;
        private StringBuilder sb = new StringBuilder();

//		public InputReader(File file) throws FileNotFoundException {
//			this(new FileInputStream(file));
//		}
//
//		public InputReader(InputStream wrapped) {
//			this.in = new BufferedInputStream(wrapped);
//		}

        public InputReader(InputStream wrapped) {
            this.in = new Scanner(wrapped);
        }

        @Override
        public void close() throws IOException {
            this.in.close();
        }

        public int ni() throws IOException {
//			sb.setLength(0);
//		mainloop:
//			for (;;) {
//				int b = this.in.read();
//				while (b == -1 || !((b >= '0' && b <= '9') || b == '-')) {
//					if (sb.length() > 0) break mainloop;
//					else b = this.in.read();
//				}
//				sb.append((char) b);
//			}
//			return new Integer(sb.toString());
            return in.nextInt();
        }

        public String nstr() throws IOException {
//			sb.setLength(0);
//			int ans = 0;
//		mainloop:
//			for (;;) {
//				int b = this.in.read();
//				while (b == -1 || !((b >= 'a' && b <= 'z') || (b >= 'A' && b < 'Z'))) {
//					if (sb.length() > 0) break mainloop;
//					else b = this.in.read();
//				}
//				sb.append((char) b);
//			}
//			return sb.toString();
            return in.next();
        }

        public long nl() throws IOException {
            return in.nextLong();
        }

        public char[] nca(int n) throws IOException {
            char[] ca = new char[n];
            String str = nstr();
            for (int i = 0; i < n; i++)
                ca[i] = str.charAt(i);
            return ca;
        }

    }

}