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.*;
import java.util.*;
import java.text.DecimalFormat;

public class B {
    static long mod=(long)1e9+7;
    static long mod1=998244353;
    static InputStream inputStream = System.in;
    static OutputStream outputStream = System.out;
    static InputReader in = new InputReader(inputStream);
    static PrintWriter out = new PrintWriter(outputStream);

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

        int u = in.nextInt();
        int p = in.nextInt();
        int pu = in.nextInt();
        long sum = 0;

        int e = in.nextInt();
        ArrayList<Integer> usb = new ArrayList<>();
        ArrayList<Integer> ps = new ArrayList<>();
        while(e-->0){
            int s = in.nextInt();
            String st = in.next();
            if(st.equals("USB"))
                usb.add(s);
            else
                ps.add(s);
        }

        Collections.sort(usb);
        Collections.sort(ps);
        int i;
        int count = 0;
        for(i = 0;i<Math.min(usb.size(),u);i++)
            sum += usb.get(i);
        count += i;
        ArrayList<Integer> both = new ArrayList<>();
        for(;i<usb.size();i++)
            both.add(usb.get(i));

        for(i = 0;i<Math.min(ps.size(),p);i++)
            sum += ps.get(i);
        count += i;
        for(;i<ps.size();i++)
            both.add(ps.get(i));

        Collections.sort(both);
        for(i = 0;i<Math.min(pu,both.size());i++)
            sum += both.get(i);
        count += i;

        out.println(count+" "+sum);

        out.close();
    }




    static final Random random=new Random();

    static void ruffleSort(int[] a) {
        int n=a.length;//shuffle, then sort
        for (int i=0; i<n; i++) {
            int oi=random.nextInt(n), temp=a[oi];
            a[oi]=a[i]; a[i]=temp;
        }
        Arrays.sort(a);
    }
    static long gcd(long x, long y){
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = Math.max(x, y);
        b = Math.min(x, y);
        r = b;
        while(a % b != 0){
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }
    static long modulo(long a,long b,long c){
        long x=1,y=a%c;
        while(b > 0){
            if(b%2 == 1)
                x=(x*y)%c;
            y = (y*y)%c;
            b = b>>1;
        }
        return  x%c;
    }
    public static void debug(Object... o){
        System.err.println(Arrays.deepToString(o));
    }

    static int upper_bound(int[] arr,int n,int x){
        int mid;
        int low=0;
        int high=n;
        while(low<high){
            mid=low+(high-low)/2;
            if(x>=arr[mid])
                low=mid+1;
            else
                high=mid;
        }
        return low;
    }

    static int lower_bound(int[] arr,int n,int x){
        int mid;
        int low=0;
        int high=n;
        while(low<high){
            mid=low+(high-low)/2;
            if(x<=arr[mid])
                high=mid;
            else
                low=mid+1;
        }
        return low;
    }
    static String printPrecision(double d){
        DecimalFormat ft = new DecimalFormat("0.00000000000");
        return String.valueOf(ft.format(d));
    }
    static int countBit(long mask){
        int ans=0;
        while(mask!=0){
            mask&=(mask-1);
            ans++;
        }
        return ans;
    }

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

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        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 int nextInt() {
            return Integer.parseInt(next());
        }

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

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int[] readArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) arr[i] = nextInt();
            return arr;
        }
    }
}