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.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class USBPS2 {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int USBonly = scanner.nextInt();
		int PS2only = scanner.nextInt();
		int both = scanner.nextInt();
		int totalComputers = USBonly+PS2only+both;

		int numMice = scanner.nextInt();
		ArrayList<Integer> USB = new ArrayList<Integer>();
		ArrayList<Integer> PS2 = new ArrayList<Integer>();

		for(int i = 0; i < numMice; i++) {
			long price = scanner.nextLong();
			if(scanner.next().equals("USB")) USB.add((int) price);
			else PS2.add((int) price);
			scanner.nextLine();
		}

		Collections.sort(USB);
		Collections.sort(PS2);

		long totalPrice = 0;
		int i = 0;
		if(USBonly >= USB.size()) {

			while(i < USB.size()) {
				totalPrice+=USB.get(i);
				i++;
			}
		}
		else {
			while(i < USBonly) {
				totalPrice+=USB.get(i);
				i++;
			}
		}

		int j = 0;
		if(PS2only >= PS2.size()) {
			while(j < PS2.size()) {
				totalPrice+=PS2.get(j);
				j++;
			}
		}
		else {
			while(j < PS2only) {
				totalPrice+=PS2.get(j);
				j++;
			}
		}

		if(both>=PS2.size()-j+USB.size()-i) {
			for(int x = j; x < PS2.size(); x++) {
				totalPrice+=PS2.get(x);
			}
			for(int y = i; y < USB.size(); y++) {
				totalPrice+=USB.get(y);
			}
			j=PS2.size();
			i=USB.size();
		}

		else {
		/*I	if(i==USB.size()||(USBonly==0)) {
				for(int a = j; a < both+1; a++) {
					totalPrice+=PS2.get(a);
					j++;
				}
			}
			else if(j==PS2.size()||PS2only==0) {
				for(int a = i; a < both+1; a++) {
					totalPrice+=USB.get(a);
					i++;
				}
			}
			else { */
				for(int b = 0; b < both; b++) {
					if (i==USB.size()){
						totalPrice+=PS2.get(j);
						j++;
					}
					else if (j==PS2.size()){
						totalPrice+=USB.get(i);
						i++;
					}
					else if(PS2.get(j)>USB.get(i)) {
						totalPrice+=USB.get(i);
						i++;
					}
					else {
						totalPrice+=PS2.get(j);
						j++;
					}
				}				
			}
		System.out.println((i+j)+" "+totalPrice);
	}
}