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 ≤ 10^5)  — 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·10^5)  — the number of mouses in the price list.

The next m lines each describe another mouse. The i-th line contains first integer val_{i} (1 ≤ val_{i} ≤ 10^9)  — 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.

Difficulty: MEDIUM

Solutions:
(a, b, c) = map(int, input().split())
m = int(input())
s1 = [list(map(str, input().split())) for i in range(m)]
for x in s1:
	x[0] = int(x[0])
s1 = sorted(s1)
k = 0
s = 0
for x in s1:
	flag = True
	if x[1] == 'USB':
		if a > 0:
			flag = False
			k += 1
			a -= 1
			s += x[0]
	elif b > 0:
		flag = False
		k += 1
		b -= 1
		s += x[0]
	if flag:
		if c > 0:
			k += 1
			c -= 1
			s += x[0]
print(k, s)


(Upc, Ppc, UPpc) = map(int, input().split())
m = int(input())
usb = []
ps2 = []
for i in range(m):
	value = input().split()
	if value[1] == 'PS/2':
		ps2 += [int(value[0])]
	else:
		usb += [int(value[0])]
usb = sorted(usb)
ps2 = sorted(ps2)
res1 = 0
res2 = 0
Ulength = len(usb)
Plength = len(ps2)
for i in range(Upc):
	if Ulength > 0:
		res1 += 1
		res2 += usb[i]
		Ulength -= 1
	else:
		break
for i in range(Ppc):
	if Plength > 0:
		res1 += 1
		res2 += ps2[i]
		Plength -= 1
	else:
		break
if Plength or Ulength:
	usb = sorted(ps2[len(ps2) - Plength:] + usb[len(usb) - Ulength:])
	UPlength = len(usb)
	for i in range(UPpc):
		if UPlength > 0:
			res1 += 1
			res2 += usb[i]
			UPlength -= 1
print(res1, res2)


import sys
(a, b, c) = map(int, sys.stdin.readline().split())
m = int(sys.stdin.readline())
num_item = 0
cost = 0
usb_l = []
ps2_l = []
for i in range(m):
	(val, type_p) = sys.stdin.readline().split()
	val = int(val)
	if type_p[0] == 'U':
		usb_l.append(val)
	else:
		ps2_l.append(val)
usb_l.sort()
ps2_l.sort()
len_usb = len(usb_l)
len_ps2 = len(ps2_l)
usb_l.append(float('inf'))
ps2_l.append(float('inf'))
pos1 = 0
pos2 = 0
if a > len_usb:
	num_item += len_usb
	cost += sum(usb_l[:-1])
	pos1 = len_usb
else:
	num_item += a
	cost += sum(usb_l[:a])
	pos1 = a
if b > len_ps2:
	num_item += len_ps2
	cost += sum(ps2_l[:-1])
	pos2 = len_ps2
else:
	num_item += b
	cost += sum(ps2_l[:b])
	pos2 = b
count = 0
while num_item < m and count < c:
	if usb_l[pos1] < ps2_l[pos2]:
		cost += usb_l[pos1]
		pos1 += 1
	else:
		cost += ps2_l[pos2]
		pos2 += 1
	num_item += 1
	count += 1
print(num_item, cost)


(a, b, c) = input().split()
(a, b, c) = (int(a), int(b), int(c))
usb = 'USB'
ps2 = 'PS/2'
u = []
ps = []
n = int(input())
while n > 0:
	(cost, s) = input().split()
	if s == usb:
		u.append(int(cost))
	elif s == ps2:
		ps.append(int(cost))
	n -= 1
u.sort()
ps.sort()
(cost, count) = (0, 0)
(a_curr, ps_curr) = (0, 0)
(a_count, ps_count) = (len(u), len(ps))
cost += sum(u[0:min(a_count, a)])
a_curr = min(a_count, a)
count = a_curr
cost += sum(ps[0:min(ps_count, b)])
ps_curr = min(ps_count, b)
count += ps_curr
new_arr = u[a_curr:] + ps[ps_curr:]
count += min(c, len(new_arr))
new_arr.sort()
cost += sum(new_arr[:c])
print(count, cost, sep=' ')


import math
import re
(a, b, c) = map(int, input().split())
q = 0
res = 0
val = int(input())
usb = []
ps2 = []
for i in range(val):
	(x, y) = input().split()
	if y == 'USB':
		usb.append(int(x))
	else:
		ps2.append(int(x))
usb = sorted(usb)
ps2 = sorted(ps2)
res += sum(usb[:min(len(usb), a)])
q += min(len(usb), a)
del usb[:min(len(usb), a)]
res += sum(ps2[:min(len(ps2), b)])
q += min(len(ps2), b)
del ps2[:min(len(ps2), b)]
usb = sorted(usb + ps2)
res += sum(usb[:min(len(usb), c)])
q += min(len(usb), c)
print(str(q) + ' ' + str(res))


(a, b, c) = list(map(int, input().split()))
m = int(input())
usb = []
ps = []
cost = 0
for i in range(m):
	(ca, t) = list(input().split())
	ca = int(ca)
	if t == 'USB':
		usb.append(ca)
	else:
		ps.append(ca)
usb.sort()
ps.sort()
usb_c = len(usb)
ps_c = len(ps)
j = 0
i = 0
ec = 0
while i < usb_c and a > 0:
	cost += usb[i]
	ec += 1
	i += 1
	a -= 1
while j < ps_c and b > 0:
	cost += ps[j]
	j += 1
	ec += 1
	b -= 1
na = usb[i:] + ps[j:]
na.sort()
i = 0
while i < len(na) and c > 0:
	cost = cost + na[i]
	ec += 1
	i += 1
	c -= 1
print(str(ec) + ' ' + str(cost))


[a, b, c] = list(map(int, input().split()))
m = int(input())
usb = []
ps2 = []
for i in range(m):
	[x, y] = list(map(str, input().split()))
	if y == 'USB':
		usb.append(int(x))
	else:
		ps2.append(int(x))
usb.sort()
ps2.sort()
cnt = 0
cost = 0
p = min(a, len(usb))
cnt += p
for i in range(p):
	cost += usb[i]
q = min(b, len(ps2))
cnt += q
for i in range(q):
	cost += ps2[i]
combine = []
for i in range(p, len(usb)):
	combine.append(usb[i])
for i in range(q, len(ps2)):
	combine.append(ps2[i])
combine.sort()
r = min(c, len(combine))
cnt += r
for i in range(r):
	cost += combine[i]
print(' '.join(map(str, [cnt, cost])))


from time import process_time
from sys import argv
from heapq import merge

def solve():
	(a, b, c) = map(int, input().split())
	m = int(input())
	(usb, ps2) = ([], [])
	for _ in range(m):
		(v, ty) = input().split()
		v = int(v)
		if ty == 'USB':
			usb.append(v)
		else:
			ps2.append(v)
	usb.sort()
	ps2.sort()
	(usbIdx, ps2Idx) = (0, 0)
	(cnt, sum_) = (0, 0)
	for _ in range(a):
		if usbIdx >= len(usb):
			break
		(cnt, sum_, usbIdx) = (cnt + 1, sum_ + usb[usbIdx], usbIdx + 1)
	for _ in range(b):
		if ps2Idx >= len(ps2):
			break
		(cnt, sum_, ps2Idx) = (cnt + 1, sum_ + ps2[ps2Idx], ps2Idx + 1)
	allMouse = merge(usb[usbIdx:], ps2[ps2Idx:])
	allMouseCnt = 0
	for mouse in allMouse:
		if allMouseCnt >= c:
			break
		(cnt, sum_, allMouseCnt) = (cnt + 1, sum_ + mouse, allMouseCnt + 1)
	print(cnt, sum_)
if len(argv) > 1:
	startTime = process_time()
	solve()
	print('Elapsed Time:', process_time() - startTime)
else:
	solve()


(a, b, c) = map(int, input().split())
n = int(input())
(u, p) = ([], [])
for i in range(n):
	(v, t) = input().split()
	v = int(v)
	if t[0] == 'U':
		u.append(v)
	else:
		p.append(v)
u = sorted(u)
p = sorted(p)
s = 0
mod = []
k = 0
if len(u) < a:
	s += sum(u)
	k += len(u)
else:
	s += sum(u[:a])
	mod += u[a:]
	k += a
if len(p) < b:
	s += sum(p)
	k += len(p)
else:
	s += sum(p[:b])
	mod += p[b:]
	k += b
if len(mod) < c:
	s += sum(mod)
	k += len(mod)
	print(k, s)
else:
	mod = sorted(mod)
	s += sum(mod[:c])
	k += c
	print(k, s)


(a, b, k) = map(int, input().split())
A = []
B = []
for _ in range(int(input())):
	s = input().split()
	if s[len(s) - 1][len(s[len(s) - 1]) - 1] == '2':
		B.append(int(s[0]))
	else:
		A.append(int(s[0]))
B.sort()
A.sort()
c = 0
ans = 0
T = []
if len(A) <= a:
	c += len(A)
	ans += sum(A)
else:
	c += a
	ans += sum(A[0:a])
	T += A[a:len(A)]
if len(B) <= b:
	c += len(B)
	ans += sum(B)
else:
	c += b
	ans += sum(B[0:b])
	T += B[b:len(B)]
T.sort()
if len(T) <= k:
	c += len(T)
	ans += sum(T)
else:
	c += k
	ans += sum(T[0:k])
print(c, ans)


(a, b, c) = map(int, input().split())
m = int(input())
m1 = []
m2 = []
for i in range(m):
	s = input().split(' ')
	if s[1] == 'USB':
		m1.append(int(s[0]))
	else:
		m2.append(int(s[0]))
m1 = sorted(m1)
m2 = sorted(m2)
m3 = []
ans1 = 0
ans2 = 0
for i in range(len(m1)):
	if a == 0:
		for j in range(i, len(m1)):
			m3.append(m1[j])
		break
	ans1 += 1
	ans2 += m1[i]
	a -= 1
for i in range(len(m2)):
	if b == 0:
		for j in range(i, len(m2)):
			m3.append(m2[j])
		break
	ans1 += 1
	ans2 += m2[i]
	b -= 1
m3 = sorted(m3)
for i in range(len(m3)):
	if c == 0:
		break
	ans1 += 1
	ans2 += m3[i]
	c -= 1
print(str(ans1) + ' ' + str(ans2))


from sys import stdin as fin
(a, b, c) = [int(i) for i in input().split()]
n = int(input())
usb = []
ps2 = []
for i in range(n):
	(a1, a2) = fin.readline().strip().split()
	if a2 == 'USB':
		usb.append(int(a1))
	else:
		ps2.append(int(a1))
usb = sorted(usb)
ps2 = sorted(ps2)
n1 = len(usb)
n2 = len(ps2)
count = 0
cost = 0
l = 0
r = 0
cost += sum(usb[:min(a, n1)])
l += min(a, n1)
count += l
cost += sum(ps2[:min(b, n2)])
r += min(b, n2)
count += r
newarray = sorted(usb[l:] + ps2[r:])
cost += sum(newarray[:min(c, len(newarray))])
count += min(c, len(newarray))
print(count, cost)


(a, b, c) = map(int, input().split())
m = int(input())
usb = []
ps2 = []
cost = 0
for _ in range(m):
	s = input().split()
	if s[1] == 'USB':
		usb.append(int(s[0]))
	else:
		ps2.append(int(s[0]))
usb.sort()
ps2.sort()
u = len(usb)
p = len(ps2)
x = min(a, u)
y = min(b, p)
t = x + y
cost = sum(usb[:x]) + sum(ps2[:y])
if u > a or p > b:
	while c > 0 and (u > x or p > y):
		if x < u:
			if y < p:
				if usb[x] >= ps2[y]:
					cost += ps2[y]
					y += 1
				else:
					cost += usb[x]
					x += 1
			else:
				cost += usb[x]
				x += 1
		else:
			cost += ps2[y]
			y += 1
		t += 1
		c -= 1
print(t, cost)


from sys import stdin, stdout
(usb, ps2, both) = map(int, stdin.readline().split())
challengersu = []
challengersp = []
ind1 = 0
ind2 = 0
n = int(stdin.readline())
for i in range(n):
	(price, s) = stdin.readline().split()
	if s == 'USB':
		challengersu.append(int(price))
	else:
		challengersp.append(int(price))
(ans, cnt) = (0, 0)
challengersu.sort()
challengersp.sort()
while usb and ind1 != len(challengersu) or (ps2 and ind2 != len(challengersp)):
	if usb and ps2 and (ind1 != len(challengersu)) and (ind2 != len(challengersp)):
		if usb and challengersu[ind1] <= challengersp[ind2]:
			ans += 1
			cnt += challengersu[ind1]
			ind1 += 1
			usb -= 1
		elif ps2 and challengersu[ind1] >= challengersp[ind2]:
			ans += 1
			cnt += challengersp[ind2]
			ind2 += 1
			ps2 -= 1
	elif usb and ind1 != len(challengersu):
		ans += 1
		cnt += challengersu[ind1]
		ind1 += 1
		usb -= 1
	elif ps2 and ind2 != len(challengersp):
		ans += 1
		cnt += challengersp[ind2]
		ind2 += 1
		ps2 -= 1
while both and (ind1 != challengersu or ind2 != challengersp):
	both -= 1
	if ind1 != len(challengersu) and ind2 != len(challengersp):
		if challengersu[ind1] < challengersp[ind2]:
			ans += 1
			cnt += challengersu[ind1]
			ind1 += 1
		else:
			ans += 1
			cnt += challengersp[ind2]
			ind2 += 1
	elif ind1 != len(challengersu):
		ans += 1
		cnt += challengersu[ind1]
		ind1 += 1
	elif ind2 != len(challengersp):
		ans += 1
		cnt += challengersp[ind2]
		ind2 += 1
stdout.write(str(ans) + ' ' + str(cnt))


import sys
(usb, ps, pc) = map(int, sys.stdin.readline().split())
n = int(sys.stdin.readline())

def find(usb, ps, pc, n):
	buy = 0
	price = 0
	usbs = []
	pss = []
	for req_num in range(n):
		req = sys.stdin.readline().strip().split()
		req[0] = int(req[0])
		if req[1] == 'USB':
			usbs.append(req[0])
		else:
			pss.append(req[0])
	usbs.sort()
	pss.sort()
	min_usb_bord = min(len(usbs), usb)
	min_ps_bord = min(len(pss), ps)
	pos_usb = 0
	pos_pss = 0
	while pos_usb < min_usb_bord:
		buy += 1
		price += usbs[pos_usb]
		pos_usb += 1
	while pos_pss < min_ps_bord:
		buy += 1
		price += pss[pos_pss]
		pos_pss += 1
	while pos_usb < len(usbs) and pos_pss < len(pss) and (pc > 0):
		if usbs[pos_usb] < pss[pos_pss]:
			price += usbs[pos_usb]
			pos_usb += 1
		else:
			price += pss[pos_pss]
			pos_pss += 1
		pc -= 1
		buy += 1
	while pos_usb < len(usbs) and pc > 0:
		price += usbs[pos_usb]
		buy += 1
		pos_usb += 1
		pc -= 1
	while pos_pss < len(pss) and pc > 0:
		price += pss[pos_pss]
		buy += 1
		pos_pss += 1
		pc -= 1
	return [buy, price]
ret = find(usb, ps, pc, n)
print(ret[0], ret[1])


(a, b, c) = list(map(int, input().split()))
m = int(input())
(USB, PS) = ([], [])
for _ in range(m):
	s = input().split()
	(l, r) = (int(s[0]), s[1])
	if r == 'USB':
		USB.append(l)
	else:
		PS.append(l)
USB.sort()
PS.sort()
a = min(a, len(USB))
res = sum(USB[:a])
USB = USB[a:]
b = min(b, len(PS))
res += sum(PS[:b])
BOTH = PS[b:] + USB
BOTH.sort()
c = min(c, len(BOTH))
res += sum(BOTH[:c])
print(str(a + b + c) + ' ' + str(res))


USB = []
PS2 = []
(u, p, b) = map(int, input().split())
m = int(input())
for _ in range(m):
	(a, s) = input().split()
	if s[0] == 'U':
		USB += [int(a)]
	else:
		PS2 += [int(a)]
USB.sort()
PS2.sort()
ans = 0
n1 = min(u, len(USB))
n2 = min(p, len(PS2))
both = sorted(USB[n1:] + PS2[n2:])
print(n1 + n2 + min(len(both), b), sum(both[:b]) + sum(USB[:n1]) + sum(PS2[:n2]))


(usb, ps2, both) = map(int, input().split())
total = usb + ps2 + both
tests = int(input())
mouses = []
for _ in range(tests):
	(a, b) = input().split()
	if b == 'USB':
		mouses.append([int(a), 0])
	else:
		mouses.append([int(a), 1])
mouses.sort(key=lambda x: x[0])
i = 0
remaining = usb + ps2 + both
cost = 0
while i < len(mouses) and remaining > 0:
	if mouses[i][1] == 0:
		if usb > 0:
			usb -= 1
			cost += mouses[i][0]
		elif both > 0:
			both -= 1
			cost += mouses[i][0]
	elif ps2 > 0:
		ps2 -= 1
		cost += mouses[i][0]
	elif both > 0:
		both -= 1
		cost += mouses[i][0]
	remaining = usb + ps2 + both
	i += 1
print(total - remaining, cost)


__author__ = 'zihaozhu'
from sys import stdin
(USBOnly, UpsOnly, either) = map(int, stdin.readline().split())
options = int(stdin.readline().rstrip())
usb = []
ups = []
for i in range(options):
	ip = stdin.readline().split()
	if ip[1] == 'USB':
		usb.append(int(ip[0]))
	else:
		ups.append(int(ip[0]))
usb.sort()
ups.sort()
numMouse = 0
cost = 0
usbCnt = 0
upsCnt = 0
while USBOnly > 0 and usbCnt < len(usb):
	cost += usb[usbCnt]
	usbCnt += 1
	USBOnly -= 1
	numMouse += 1
while UpsOnly > 0 and upsCnt < len(ups):
	cost += ups[upsCnt]
	upsCnt += 1
	UpsOnly -= 1
	numMouse += 1
while either > 0 and (usbCnt < len(usb) or upsCnt < len(ups)):
	either -= 1
	val1 = float('inf')
	val2 = float('inf')
	if usbCnt < len(usb):
		val1 = usb[usbCnt]
	if upsCnt < len(ups):
		val2 = ups[upsCnt]
	numMouse += 1
	minVal = min(val1, val2)
	if minVal == val1:
		usbCnt += 1
	elif minVal == val2:
		upsCnt += 1
	cost += min(val1, val2)
print('%s %s' % (numMouse, cost))


info = input()
infos = info.split(' ')
unb = int(infos[0])
pnb = int(infos[1])
bnb = int(infos[2])
mnums = int(input())
usbs = []
ps2s = []
for i in range(mnums):
	ls = input().split(' ')
	if ls[1] == 'USB':
		usbs.append(int(ls[0]))
	else:
		ps2s.append(int(ls[0]))
usbs.sort()
ps2s.sort()
buyed = 0
cost = 0
nowu = 0
nowp = 0
if unb <= len(usbs):
	buyed += unb
	nowu = unb
	cost += sum(usbs[0:unb])
else:
	buyed += len(usbs)
	nowu = len(usbs)
	cost += sum(usbs)
if pnb <= len(ps2s):
	buyed += pnb
	nowp = pnb
	cost += sum(ps2s[0:pnb])
else:
	buyed += len(ps2s)
	nowp = len(ps2s)
	cost += sum(ps2s)
lst = []
if not nowu == len(usbs):
	lst.extend(usbs[nowu:])
if not nowp == len(ps2s):
	lst.extend(ps2s[nowp:])
lst.sort()
if bnb <= len(lst):
	buyed += bnb
	cost += sum(lst[0:bnb])
else:
	buyed += len(lst)
	cost += sum(lst)
print(buyed, cost)


def r():
	return list(map(int, input().split()))
(n, ans) = (0, 0)
(a, b, c) = r()
m = int(input())
tt = []
for i in range(m):
	(val, port) = input().split()
	val = int(val)
	if port[0] is 'U':
		tt.append([val, 1])
	else:
		tt.append([val, 0])
tt.sort(key=lambda x: x[0])
tt2 = []
for (x, y) in tt:
	if y == 0 and b > 0:
		b -= 1
		ans += x
		n += 1
	elif y == 1 and a > 0:
		a -= 1
		ans += x
		n += 1
	else:
		tt2.append(x)
mn = min(c, len(tt2))
ans += sum(tt2[:mn])
n += mn
print(n, ans)


import math, re, itertools as it
prime = lambda n: len([i for i in range(2, int(math.sqrt(n) + 1)) if n % i == 0]) == 0
gcd = lambda a, b: gcd(b, a % b) if b else a
fact = lambda x: x * fact(x - 1) if x else 1
bino = lambda n, k: fact(n) / fact(k) / fact(n - k)
fib11 = lambda n: 1 if n < 2 else fib11(n - 1) + fib11(n - 2)
fib01 = lambda n: 0 if n == 0 else 1 if n == 1 else fib01(n - 1) + fib01(n - 2)
sumofd = lambda x: x if x < 10 else sumofd(x // 10) + x % 10
(a, b, c) = map(int, input().split())
m = int(input())
d = []
for i in range(m):
	s = input().split()
	d.append([int(s[0]), 1 if s[1] == 'USB' else 0])
d.sort()
i = 0
p = 0
nn = 0
while i < len(d) and (a or b or c):
	f1 = f2 = False
	if a and d[i][1]:
		a -= 1
		p += d[i][0]
		f1 = True
		nn += 1
	if b and d[i][1] == 0:
		b -= 1
		p += d[i][0]
		f2 = True
		nn += 1
	if not f1 and (not f2):
		if c:
			c -= 1
			p += d[i][0]
			nn += 1
	i += 1
print(nn, p)


(z, b, c) = map(int, input().split())
m = int(input())
a = []
for _ in range(m):
	(x, y) = input().split()
	if y == 'USB':
		a.append([int(x), 1])
	else:
		a.append([int(x), 2])
cost = ans = 0
a.sort()
for i in a:
	if i[1] == 1:
		if z:
			z -= 1
			ans += 1
			cost += i[0]
		elif c:
			c -= 1
			ans += 1
			cost += i[0]
	elif b:
		b -= 1
		ans += 1
		cost += i[0]
	elif c:
		c -= 1
		ans += 1
		cost += i[0]
print(ans, cost)


c = list(map(int, input().split()))
m = int(input())
a = []
for i in range(m):
	(n, t) = input().split()
	a.append((int(n), int(t == 'PS/2')))
a.sort()
res = 0
b = [0] * 3
for (n, t) in a:
	if c[t] - b[t] > 0:
		b[t] += 1
		res += n
	elif c[2] - b[2] > 0:
		b[2] += 1
		res += n
print(sum(b), res)


(a, b, c) = map(int, input().split())
m = int(input())

def merge(arr1, arr2):
	result = []
	ptr1 = ptr2 = 0
	while ptr1 < len(arr1) or ptr2 < len(arr2):
		if ptr1 >= len(arr1):
			result.append(arr2[ptr2])
			ptr2 += 1
		elif ptr2 >= len(arr2):
			result.append(arr1[ptr1])
			ptr1 += 1
		elif arr1[ptr1] < arr2[ptr2]:
			result.append(arr1[ptr1])
			ptr1 += 1
		else:
			result.append(arr2[ptr2])
			ptr2 += 1
	return result
usb = []
ps2 = []
for i in range(m):
	(cost, type) = input().split()
	if type == 'USB':
		usb.append(int(cost))
	else:
		ps2.append(int(cost))
usb.sort()
ps2.sort()
usbSold = min(len(usb), a)
usbCost = sum(usb[:usbSold])
ps2Sold = min(len(ps2), b)
ps2Cost = sum(ps2[:ps2Sold])
combined = merge(usb[usbSold:], ps2[ps2Sold:])
combinedSold = min(len(combined), c)
combinedCost = sum(combined[:combinedSold])
print('{} {}'.format(usbSold + ps2Sold + combinedSold, usbCost + ps2Cost + combinedCost))


import os
import sys
from io import BytesIO, IOBase
import math
from queue import Queue
import collections
import itertools
import bisect
import heapq
import random

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def primeFactorsCount(n):
	cnt = 0
	while n % 2 == 0:
		cnt += 1
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			cnt += 1
			n = n // i
	if n > 2:
		cnt += 1
	return cnt

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n

def p2(n):
	c = 0
	while n % 2 == 0:
		n //= 2
		c += 1
	return c

def seive(n):
	primes = [True] * (n + 1)
	primes[1] = primes[0] = False
	i = 2
	while i * i <= n:
		if primes[i] == True:
			for j in range(i * i, n + 1, i):
				primes[j] = False
		i += 1
	pr = []
	for i in range(0, n + 1):
		if primes[i]:
			pr.append(i)
	return pr

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def denofactinverse(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return pow(fac, m - 2, m)

def numofact(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return fac

def sod(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s
(a, b, c) = map(int, input().split())
u = []
p = []
for i in range(0, int(input())):
	s = input().split()
	if s[1][0] == 'P':
		p.append(int(s[0]))
	else:
		u.append(int(s[0]))
p.sort()
u.sort()
a2 = 0
ans = sum(u[:min(a, len(u))])
a2 += min(a, len(u))
ans += sum(p[:min(b, len(p))])
a2 += min(b, len(p))
u = u[min(a, len(u)):]
u += p[min(b, len(p)):]
u.sort()
a2 += min(len(u), c)
ans += sum(u[:min(len(u), c)])
print(a2, ans)


(a, b, c) = map(int, input().split())
m = int(input())
z = 0
A = []
B = []
su = 0
for i in range(m):
	s = input().split()
	if s[1] == 'USB':
		A.append(int(s[0]))
	else:
		B.append(int(s[0]))
A.sort()
B.sort()
if a < len(A):
	su += sum(A[:a])
	A = A[a:]
	z += a
	a = 0
else:
	su += sum(A)
	z += len(A)
	a += -len(A)
	A = []
if b < len(B):
	su += sum(B[:b])
	B = B[b:]
	z += b
	b = 0
else:
	su += sum(B)
	z += len(B)
	b += -len(B)
	B = []
i = 0
j = 0
while c > 0 and len(A) > i and (len(B) > j):
	if A[i] == B[j]:
		if len(A) - 1 - i > len(B) - 1 - j:
			su += A[i]
			i += 1
		else:
			su += B[j]
			j += 1
	elif min(A[i], B[j]) == A[i]:
		su += A[i]
		i += 1
	else:
		su += B[j]
		j += 1
	c += -1
	z += 1
su += sum(B[j:j + c]) + sum(A[i:i + c])
z += len(B[j:j + c]) + len(A[i:i + c])
print(z, su)


from sys import stdin
(A, B, C) = list(map(int, stdin.readline().split()))
M = int(stdin.readline())
usb_mouses = []
ps2_mouses = []
for m in range(M):
	(p, t) = stdin.readline().split()
	if t == 'USB':
		usb_mouses.append(int(p))
	elif t == 'PS/2':
		ps2_mouses.append(int(p))
usb_mouses.sort()
ps2_mouses.sort()
usb_cur = 0
ps2_cur = 0
cost = 0
while usb_cur < len(usb_mouses) and A > 0:
	cost += usb_mouses[usb_cur]
	usb_cur += 1
	A -= 1
while ps2_cur < len(ps2_mouses) and B > 0:
	cost += ps2_mouses[ps2_cur]
	ps2_cur += 1
	B -= 1
while C > 0:
	if usb_cur < len(usb_mouses) and ps2_cur < len(ps2_mouses):
		if usb_mouses[usb_cur] < ps2_mouses[ps2_cur]:
			cost += usb_mouses[usb_cur]
			usb_cur += 1
		else:
			cost += ps2_mouses[ps2_cur]
			ps2_cur += 1
	elif usb_cur < len(usb_mouses):
		cost += usb_mouses[usb_cur]
		usb_cur += 1
	elif ps2_cur < len(ps2_mouses):
		cost += ps2_mouses[ps2_cur]
		ps2_cur += 1
	else:
		break
	C -= 1
print('{} {}'.format(usb_cur + ps2_cur, cost))


(a, b, c) = map(int, input().split())
n = int(input())
usb = []
ps = []
for i in range(n):
	(k, t) = input().strip().split()
	if t == 'USB':
		usb.append(int(k))
	else:
		ps.append(int(k))
usb = sorted(usb)
ps = sorted(ps)
(eq, tot) = (0, 0)
if len(usb) < a:
	eq += len(usb)
	tot += sum(usb)
	usb = []
else:
	eq += a
	tot += sum(usb[:a])
	usb = usb[a:]
if len(ps) < b:
	eq += len(ps)
	tot += sum(ps)
	ps = []
else:
	eq += b
	tot += sum(ps[:b])
	ps = ps[b:]
usb = sorted(usb + ps)
if len(usb) < c:
	eq += len(usb)
	tot += sum(usb)
else:
	eq += c
	tot += sum(usb[:c])
print('{} {}'.format(eq, tot))


(a, b, c) = map(int, input().split())
m = int(input())
usb = []
ps2 = []
for i in range(m):
	(aa, bb) = input().split()
	if bb == 'USB':
		usb.append(int(aa))
	else:
		ps2.append(int(aa))
usb.sort()
ps2.sort()
equip = 0
cost = 0
t = min(a, len(usb))
equip += t
for i in range(t):
	cost += usb[i]
p = min(b, len(ps2))
equip += p
for i in range(p):
	cost += ps2[i]
rest = usb[t:] + ps2[p:]
rest.sort()
k = min(c, len(rest))
equip += k
for i in range(k):
	cost += rest[i]
print(equip, cost)


(a, b, c) = map(int, input().split())
m = int(input())
usb = []
ps = []
for i in range(m):
	(val, name) = input().split()
	if name == 'USB':
		usb.append(int(val))
	else:
		ps.append(int(val))
usb.sort()
ps.sort()
sum1 = sum(usb[:min(len(usb), a)])
sum2 = sum(ps[:min(len(ps), b)])
u1 = min(len(usb), a)
u2 = min(len(ps), b)
usbps = usb[min(len(usb), a):] + ps[min(len(ps), b):]
usbps.sort()
sum3 = sum(usbps[:min(len(usbps), c)])
u3 = min(len(usbps), c)
print(u1 + u2 + u3, sum1 + sum2 + sum3)


(a, b, c) = (int(i) for i in input().split())
m = int(input())
l1 = []
l2 = []
(c1, c2) = (0, 0)
c3 = 0
s = 0
for i in range(m):
	(x, y) = (i for i in input().split())
	if y == 'USB':
		l1.append(int(x))
		c1 += 1
	else:
		l2.append(int(x))
		c2 += 1
l1.sort()
l2.sort()
(i1, i2) = (0, 0)
while m > 0:
	if i1 < c1 and i2 < c2:
		if l1[i1] < l2[i2]:
			if a > 0:
				a -= 1
				s += l1[i1]
				i1 += 1
				c3 += 1
			elif c > 0:
				c -= 1
				s += l1[i1]
				i1 += 1
				c3 += 1
			else:
				i1 = c1
		elif b > 0:
			b -= 1
			s += l2[i2]
			i2 += 1
			c3 += 1
		elif c > 0:
			c -= 1
			s += l2[i2]
			i2 += 1
			c3 += 1
		else:
			i2 = c2
	elif i1 == c1 and i2 == c2:
		break
	elif i1 == c1:
		if b > 0:
			b -= 1
			s += l2[i2]
			i2 += 1
			c3 += 1
		elif c > 0:
			c -= 1
			s += l2[i2]
			i2 += 1
			c3 += 1
		else:
			i2 = c2
	elif a > 0:
		a -= 1
		s += l1[i1]
		i1 += 1
		c3 += 1
	elif c > 0:
		c -= 1
		s += l1[i1]
		i1 += 1
		c3 += 1
	else:
		i1 = c1
	m -= 1
print(c3, s)


(a, b, c) = list(map(int, input().split()))
m = int(input())
USB = []
PS = []
i2 = 0
i1 = 0
ans1 = 0
ans2 = 0
for i in range(m):
	(n, k) = input().split()
	if k == 'USB':
		USB.append(int(n))
	else:
		PS.append(int(n))
USB.sort()
PS.sort()
for i in range(a):
	if i >= len(USB):
		break
	ans1 += USB[i]
	ans2 += 1
	i1 = i + 1
for i in range(b):
	if i >= len(PS):
		break
	ans1 += PS[i]
	ans2 += 1
	i2 = i + 1
for i in range(c):
	if i2 < len(PS) and i1 < len(USB):
		if PS[i2] < USB[i1]:
			ans1 += PS[i2]
			i2 += 1
			ans2 += 1
		else:
			ans1 += USB[i1]
			i1 += 1
			ans2 += 1
	elif i2 >= len(PS):
		if i1 < len(USB):
			ans1 += USB[i1]
			i1 += 1
			ans2 += 1
	elif i1 >= len(USB):
		if i2 < len(PS):
			ans1 += PS[i2]
			i2 += 1
			ans2 += 1
print(ans2, ans1)


(a, b, c) = map(int, input().split())
n = int(input())
cop = []
for i in range(n):
	(x, y) = input().split()
	z = 0
	if y == 'USB':
		z = 1
	if y == 'PS/2':
		z = 2
	cop.append((int(x), z))
ans = 0
num = 0
cop.sort(key=lambda x: x[0])
for terms in cop:
	if terms[1] == 1:
		if a > 0:
			a -= 1
			ans += terms[0]
			num += 1
			continue
		if c > 0:
			c -= 1
			num += 1
			ans += terms[0]
	if terms[1] == 2:
		if b > 0:
			b -= 1
			num += 1
			ans += terms[0]
			continue
		if c > 0:
			c -= 1
			num += 1
			ans += terms[0]
print(num, ans)


import sys
input = sys.stdin.readline
(num_usb, num_ps, num_both) = map(int, input().split())
m = int(input())
usb = []
ps = []
for _ in range(m):
	(c, con) = input().rstrip().split()
	c = int(c)
	if con == 'USB':
		usb.append(c)
	else:
		ps.append(c)
usb.sort(reverse=True)
ps.sort(reverse=True)
cost = 0
count = 0
while num_usb and usb:
	num_usb -= 1
	cost += usb.pop()
	count += 1
while num_ps and ps:
	num_ps -= 1
	cost += ps.pop()
	count += 1
usb.extend(ps)
both = usb
both.sort(reverse=True)
while num_both and usb:
	num_both -= 1
	cost += both.pop()
	count += 1
print(count, cost)


(a, b, c) = input().split()
(a, b, c) = (int(a), int(b), int(c))
n = int(input())
usb = []
ps = []
for i in range(n):
	x = input().split()
	if x[1] == 'USB':
		usb.append(int(x[0]))
	else:
		ps.append(int(x[0]))
usb.sort()
usb.reverse()
ps.sort()
ps.reverse()
usb_k = min(a, len(usb))
ps_k = min(b, len(ps))
price = 0
for i in range(usb_k):
	price += usb.pop()
for i in range(ps_k):
	price += ps.pop()
usb.extend(ps)
usb.sort()
usb.reverse()
k = min(c, len(usb))
for i in range(k):
	price += usb.pop()
k = k + usb_k + ps_k
print(k, price)


import sys
(a, b, c) = map(int, next(sys.stdin).split())
mouses = {'USB': [], 'PS/2': []}
for _ in range(int(input())):
	(value, key) = next(sys.stdin).strip().split()
	mouses[key].append(int(value))
for key in mouses.keys():
	mouses[key].sort()
(usb, ps) = (min(a, len(mouses['USB'])), min(b, len(mouses['PS/2'])))
remains = list(sorted(mouses['USB'][usb:] + mouses['PS/2'][ps:]))
both = min(c, len(remains))
cost = sum(mouses['USB'][:usb]) + sum(mouses['PS/2'][:ps]) + sum(remains[:both])
print(usb + ps + both, cost)


from sys import stdin as fin
(u, p, pu) = map(int, fin.readline().split())
m = int(fin.readline())
(ps2, usb) = ([], [])
for i in range(m):
	(cost, typ) = fin.readline().strip().split()
	cost = int(cost)
	if typ == 'PS/2':
		ps2.append(cost)
	else:
		usb.append(cost)
ps2.sort()
usb.sort()
sumcost = 0
cnt = 0
i = j = 0
(n1, n2) = (len(ps2), len(usb))

def inc(x):
	global cnt, sumcost
	cnt += 1
	sumcost += x
while (p or u or pu) and (i < n1 or j < n2):
	if i < n1 and (j == n2 or ps2[i] <= usb[j]):
		if p or pu:
			inc(ps2[i])
			i += 1
		if p:
			p -= 1
		elif pu:
			pu -= 1
		else:
			i = n1
	elif j < n2:
		if u or pu:
			inc(usb[j])
			j += 1
		if u:
			u -= 1
		elif pu:
			pu -= 1
		else:
			j = n2
print(cnt, sumcost)


(a, b, c) = list(map(int, input().split()))
(n, u0, u1) = (int(input()), [], [])
for i in range(n):
	(e0, e1) = input().split()
	if e1 == 'USB':
		u0.append(int(e0))
	else:
		u1.append(int(e0))
u0.sort()
u1.sort()
n = 0
x = 0
if len(u0) > a:
	x = x + sum(u0[:a])
	u0 = u0[a:]
	n = n + a
else:
	x = x + sum(u0)
	n = n + len(u0)
	u0 = []
if len(u1) > b:
	x = x + sum(u1[:b])
	u1 = u1[b:]
	n = n + b
else:
	x = x + sum(u1)
	n = n + len(u1)
	u1 = []
u = u1 + u0
u.sort()
if len(u) > c:
	x = x + sum(u[:c])
	n = n + c
else:
	x = x + sum(u)
	n = n + len(u)
print(str(n) + ' ' + str(x))


(u, p, b) = map(int, input().split())
n = int(input())
arr = []
cnt = 0
m = 0
for i in range(n):
	(a, bb) = input().split()
	arr.append([int(a), bb])
arr = sorted(arr)
for i in range(n):
	if arr[i][1] == 'USB' and u != 0:
		u -= 1
		cnt += arr[i][0]
		m += 1
	elif arr[i][1] == 'PS/2' and p != 0:
		p -= 1
		cnt += arr[i][0]
		m += 1
	elif (arr[i][1] == 'PS/2' or arr[i][1] == 'USB') and b != 0:
		b -= 1
		cnt += arr[i][0]
		m += 1
print(m, cnt)


MAXINT = 10 ** 10
(a, b, c) = map(int, input().split())
(m,) = map(int, input().split())
(usb, ps2) = ([], [])
for _ in range(m):
	(v, tp) = input().split()
	if tp == 'USB':
		usb.append(int(v))
	else:
		ps2.append(int(v))
usb.sort()
ps2.sort()
(ui, pi) = (0, 0)
(un, pn) = (len(usb), len(ps2))
usb.append(MAXINT)
ps2.append(MAXINT)
(res, cost) = (0, 0)
while ui < un and a > 0:
	res += 1
	cost += usb[ui]
	ui += 1
	a -= 1
while pi < pn and b > 0:
	res += 1
	cost += ps2[pi]
	pi += 1
	b -= 1
while c > 0 and (ui < un or pi < pn):
	v = None
	if usb[ui] <= ps2[pi]:
		v = usb[ui]
		ui += 1
	else:
		v = ps2[pi]
		pi += 1
	res += 1
	cost += v
	c -= 1
print(res, cost)


(a, b, c) = map(int, input().split())
n = int(input())
mice_usb = []
mice_ps = []
for i in range(n):
	(price, mice_type) = input().split()
	if mice_type[0] == 'U':
		mice_usb.append(int(price))
	else:
		mice_ps.append(int(price))
usb = min(len(mice_usb), a)
ps2 = min(len(mice_ps), b)
mice_usb.sort()
mice_ps.sort()
answer = sum(mice_usb[:usb]) + sum(mice_ps[:ps2])
num = usb + ps2
left = mice_usb[usb:] + mice_ps[ps2:]
left.sort()
any_num = min(len(left), c)
answer += sum(left[:any_num])
num += any_num
print(num, answer)


(a, b, c) = map(int, input().split())
arr = [[], []]
for i in range(int(input())):
	(p, s) = input().split()
	pr = int(p)
	if s == 'USB':
		arr[0].append(pr)
	else:
		arr[1].append(pr)
arr[0].sort()
arr[1].sort()
pr = 0
n = 0
d = []
for j in range(min(a, len(arr[0]))):
	n += 1
	pr += arr[0][j]
d += arr[0][min(a, len(arr[0])):]
for j in range(min(b, len(arr[1]))):
	n += 1
	pr += arr[1][j]
	arr[1][j] = 10000000000.0
d += arr[1][min(b, len(arr[1])):]
d.sort()
for k in range(min(c, len(d))):
	n += 1
	pr += d[k]
print(n, pr)


from collections import deque
(a, b, c) = list(map(int, input().split()))
m = int(input())
usb_cost = []
ps_cost = []
for i in range(m):
	(cost, t) = input().split()
	cost = int(cost)
	if t == 'USB':
		usb_cost.append(cost)
	else:
		ps_cost.append(cost)
usb_cost.sort(reverse=True)
ps_cost.sort(reverse=True)
ans = 0
ans_sum = 0
for i in range(min(a, len(usb_cost))):
	ans_sum += usb_cost.pop()
	ans += 1
for i in range(min(b, len(ps_cost))):
	ans_sum += ps_cost.pop()
	ans += 1
all_types = sorted(usb_cost + ps_cost, reverse=True)
for i in range(min(c, len(all_types))):
	ans_sum += all_types.pop()
	ans += 1
print(ans, ans_sum)


(a, b, c) = map(int, input().split())
m = int(input())
ms = [[] for _ in range(2)]
for i in range(m):
	(ct, t) = input().split()
	ct = int(ct)
	ms[int(t != 'USB')].append(ct)
from itertools import accumulate
for i in range(2):
	ms[i].sort()
	ms[i] = list(accumulate(ms[i]))
ans = (0, 0)
cost = lambda x, a: (0, 0) if x == 0 or len(a) == 0 else (min(len(a), x), a[min(len(a), x) - 1])
for i in range(c + 1):
	ai = a + i
	bi = b + c - i
	csa = cost(ai, ms[0])
	csb = cost(bi, ms[1])
	tc = (csa[0] + csb[0], csa[1] + csb[1])
	if tc[0] > ans[0]:
		ans = tc
	elif tc[0] == ans[0] and tc[1] < ans[1]:
		ans = tc
print(*ans)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]

def merge(a, b):
	from heapq import merge
	return list(merge(a, b))
(a, b, c) = value()
n = Int()
d = defaultdict(list)
for i in range(n):
	(m, t) = input().split()
	d[t[0]].append(int(m))
for i in d:
	d[i].sort()
mouse = min(a, len(d['U'])) + min(b, len(d['P']))
ans = sum(d['U'][:a]) + sum(d['P'][:b])
d['U'] = d['U'][a:]
d['P'] = d['P'][b:]
mouse += min(c, len(d['U']) + len(d['P']))
ans += sum(merge(d['U'], d['P'])[:c])
print(mouse, ans)


(a, b, c) = map(int, input().split())
n = int(input())
USB = []
PS2 = []
for i in range(n):
	(s1, s2) = map(str, input().split())
	s1 = int(s1)
	if s2 == 'USB':
		USB.append(s1)
	else:
		PS2.append(s1)
USB.sort()
PS2.sort()
count = 0
s = 0
if a > len(USB):
	count += len(USB)
	for i in USB:
		s += i
	USB = []
else:
	count += a
	for i in USB[:a]:
		s += i
	USB = USB[a:]
if b > len(PS2):
	count += len(PS2)
	for i in PS2:
		s += i
	PS2 = []
else:
	count += b
	for i in PS2[:b]:
		s += i
	PS2 = PS2[b:]
A = USB + PS2
A.sort()
if c > len(A):
	count += len(A)
	for i in A:
		s += i
else:
	count += c
	for i in A[:c]:
		s += i
print(str(count) + ' ' + str(s))


(a, b, c) = [int(i) for i in input().split()]
m = int(input())
u_list = []
p_list = []
for i in range(m):
	(price, port) = input().split()
	price = int(price)
	if port[0] == 'U':
		u_list.append(price)
	else:
		p_list.append(price)
u_list_len = len(u_list)
p_list_len = len(p_list)
u_list = sorted(u_list)
p_list = sorted(p_list)
mouse_count = 0
cost = 0
if u_list_len >= a:
	mouse_count += a
	cost += sum(u_list[:a])
	u_list = u_list[a:]
else:
	mouse_count += u_list_len
	cost += sum(u_list)
	u_list = []
if p_list_len >= b:
	mouse_count += b
	cost += sum(p_list[:b])
	p_list = p_list[b:]
else:
	mouse_count += p_list_len
	cost += sum(p_list)
	p_list = []
pu_list = p_list + u_list
pu_list = sorted(pu_list)
pu_list_len = len(pu_list)
if pu_list_len >= c:
	mouse_count += c
	cost += sum(pu_list[:c])
else:
	mouse_count += pu_list_len
	cost += sum(pu_list)
print(mouse_count, cost)


(a, b, c) = map(int, input().split())
m = int(input())
d = {'USB': [], 'PS/2': []}
for _ in range(m):
	(v, t) = input().split()
	d[t].append(int(v))
d['PS/2'].sort()
d['USB'].sort()
eq = cst = f1 = f2 = 0
nusb = len(d['USB'])
nps2 = len(d['PS/2'])
while a > 0 and f1 < nusb:
	a -= 1
	eq += 1
	cst += d['USB'][f1]
	f1 += 1
while b > 0 and f2 < nps2:
	b -= 1
	eq += 1
	cst += d['PS/2'][f2]
	f2 += 1
while c > 0 and (f1 < nusb or f2 < nps2):
	c -= 1
	eq += 1
	if f1 == nusb:
		cst += d['PS/2'][f2]
		f2 += 1
		continue
	elif f2 == nps2:
		cst += d['USB'][f1]
		f1 += 1
		continue
	if d['PS/2'][f2] < d['USB'][f1]:
		cst += d['PS/2'][f2]
		f2 += 1
	else:
		cst += d['USB'][f1]
		f1 += 1
print(eq, cst)


(a, b, c) = map(int, input().split())
ans = 0
m = int(input())
u = []
p = []
for i in range(m):
	s = input().split()
	if s[1] == 'USB':
		u.append(int(s[0]))
	else:
		p.append(int(s[0]))
u.sort()
p.sort()
a = min(a, len(u))
b = min(b, len(p))
ans += sum(u[:a]) + sum(p[:b])
d = sorted(u[a:] + p[b:])
c = min(c, len(d))
ans += sum(d[:c])
print(a + b + c, ans)


(a, b, c) = map(int, input().split())
g = [input().split() for i in range(int(input()))]
(v, vc) = (0, 0)
for (x, y) in sorted(((int(x), y == 'USB') for (x, y) in g)):
	if a and y or (b and (not y)) or c:
		v += 1
		vc += x
	if y:
		if a:
			a -= 1
		elif c:
			c -= 1
	elif b:
		b -= 1
	elif c:
		c -= 1
print(v, vc)


(u, p, b) = map(int, input().split())
t = int(input())
usb = []
ps2 = []
for i in range(t):
	val = input().split()
	if val[1] == 'USB':
		usb.append(int(val[0]))
	else:
		ps2.append(int(val[0]))
c = 0
s = 0
usb.sort(reverse=True)
ps2.sort(reverse=True)
leu = len(usb)
lep = len(ps2)
j = 0
for i in range(leu):
	if j >= u:
		break
	s += usb.pop()
	j += 1
	c += 1
k = 0
for i in range(lep):
	if k >= p:
		break
	s += ps2.pop()
	k += 1
	c += 1
for i in range(b):
	if len(usb) > 0 and len(ps2) > 0:
		if usb[-1] < ps2[-1]:
			s += usb.pop()
			c += 1
		else:
			s += ps2.pop()
			c += 1
	elif len(usb) > 0:
		s += usb.pop()
		c += 1
	elif len(ps2) > 0:
		s += ps2.pop()
		c += 1
	else:
		break
print(c, s)


(a, b, c) = map(int, input().split())
m = int(input())
usb = []
ps = []
count = 0
for _ in range(m):
	(x, y) = input().split()
	if y == 'USB':
		usb.append(int(x))
	else:
		ps.append(int(x))
usb.sort()
ps.sort()
ans = 0
usbc = 0
psc = 0
if a > len(usb):
	ans += sum(usb)
	usbc = len(usb)
	count += len(usb)
else:
	for i in range(a):
		ans += usb[i]
		usbc = i
		count += 1
if a > 0:
	usbc += 1
if b > len(ps):
	ans += sum(ps)
	psc = len(ps)
	count += len(ps)
else:
	for i in range(b):
		ans += ps[i]
		psc = i
		count += 1
if b > 0:
	psc += 1
cc = c
if len(usb) - 1 >= usbc and len(ps) - 1 >= psc:
	while usbc <= len(usb) - 1 and psc <= len(ps) - 1 and (cc > 0):
		if usb[usbc] < ps[psc]:
			ans += usb[usbc]
			usbc += 1
			cc -= 1
			count += 1
		else:
			ans += ps[psc]
			psc += 1
			cc -= 1
			count += 1
if cc > 0 and usbc <= len(usb) - 1:
	while cc > 0 and usbc <= len(usb) - 1:
		cc -= 1
		ans += usb[usbc]
		usbc += 1
		count += 1
if cc > 0 and psc <= len(ps) - 1:
	while cc > 0 and psc <= len(ps) - 1:
		cc -= 1
		ans += ps[psc]
		psc += 1
		count += 1
print(count, ans)


import sys, itertools, math, collections, random

def ia():
	return [int(i) for i in sys.stdin.readline().strip().split(' ')]

def ii():
	return int(sys.stdin.readline().strip())

def istr():
	return sys.stdin.readline().strip()
USB = []
PS2 = []
(a, b, c) = ia()
for _ in range(ii()):
	(cost, t) = istr().split(' ')
	cost = int(cost)
	if t == 'USB':
		USB.append(cost)
	else:
		PS2.append(cost)
USB = sorted(USB, reverse=True)
PS2 = sorted(PS2, reverse=True)
(n, s) = (0, 0)
while a > 0 and USB:
	s += USB.pop()
	n += 1
	a -= 1
while b > 0 and PS2:
	s += PS2.pop()
	n += 1
	b -= 1
BOTH = sorted(USB + PS2, reverse=True)
while c > 0 and BOTH:
	s += BOTH.pop()
	n += 1
	c -= 1
print(n, s)


(un, pn, n) = map(int, input().split())
m = int(input())
(lu, lp) = ([], [])
(lui, lpi) = (0, 0)
for i in range(m):
	(v, t) = input().split()
	if t == 'USB':
		lu.append(int(v))
	else:
		lp.append(int(v))
list.sort(lu)
list.sort(lp)
(lui, lpi) = (0, 0)
mxu = len(lu)
mxp = len(lp)
rc = 0
rv = 0
while un > 0 and lui < mxu:
	rv += lu[lui]
	lui += 1
	un -= 1
while pn > 0 and lpi < mxp:
	rv += lp[lpi]
	lpi += 1
	pn -= 1
while n > 0 and lui < mxu and (lpi < mxp):
	if lu[lui] < lp[lpi]:
		rv += lu[lui]
		lui += 1
	else:
		rv += lp[lpi]
		lpi += 1
	n -= 1
while n > 0 and lui < mxu:
	rv += lu[lui]
	lui += 1
	n -= 1
while n > 0 and lpi < mxp:
	rv += lp[lpi]
	lpi += 1
	n -= 1
rc = lui + lpi
print(rc, rv)


import math
str1 = [int(a) for a in input().split()]
z0 = str1[0]
z1 = str1[1]
z2 = str1[2]
k = z0 + z1 + z2
N = int(input())
A = []
sum = 0
if N:
	for i in range(N):
		str = [a for a in input().split()]
		str1 = [int(str[0]), str[1]]
		A.append(str1)
	A.sort()
	for i in A:
		if i[1] == 'USB' and z0:
			sum += int(i[0])
			z0 -= 1
		elif i[1] == 'PS/2' and z1:
			sum += int(i[0])
			z1 -= 1
		elif z2:
			sum += int(i[0])
			z2 -= 1
	b = k - (z0 + z1 + z2)
	print(b, sum)
else:
	print(0, ' ', 0)


import os
import sys
from io import BytesIO, IOBase

def main():
	(n, m, k) = map(int, input().split(' '))
	mm = int(input())
	usb = []
	ps = []
	for x in range(mm):
		a = input().split(' ')
		if a[1][0] == 'U':
			usb.append(int(a[0]))
		else:
			ps.append(int(a[0]))
	usb.sort()
	ps.sort()
	ans = 0
	cnt = 0
	ans += sum(usb[:n])
	ans += sum(ps[:m])
	lenusb = len(usb)
	lenps = len(ps)
	cnt += min(lenusb, n)
	cnt += min(lenps, m)
	cnt += min(k, max(lenusb - n, 0) + max(lenps - m, 0))
	while n < lenusb and m < lenps and (k > 0):
		if usb[n] <= ps[m]:
			ans += usb[n]
			n += 1
		else:
			ans += ps[m]
			m += 1
		k -= 1
	ans += sum(usb[n:n + k]) + sum(ps[m:m + k])
	print(cnt, ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
from bisect import bisect_right as rb
from collections import deque
from queue import PriorityQueue
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
mod = 10 ** 9 + 7
(a, p, c) = il()
b = []
m = ii()
for i in range(m):
	(x, y) = ip().split()
	b.append([int(x), y])
b.sort()
t = 0
cnt = 0
for i in range(m):
	if b[i][1] == 'USB' and a != 0:
		a -= 1
		t += b[i][0]
		cnt += 1
	elif b[i][1] == 'PS/2' and p != 0:
		p -= 1
		t += b[i][0]
		cnt += 1
	elif c != 0:
		c -= 1
		t += b[i][0]
		cnt += 1
print(cnt, t)


def ri():
	return map(int, input().split())
(a, b, c) = ri()
m = int(input())
u = []
p = []
for i in range(m):
	(cost, t) = input().split()
	cost = int(cost)
	if t == 'USB':
		u.append(cost)
	else:
		p.append(cost)
u.sort(reverse=True)
p.sort(reverse=True)
count = 0
totcost = 0
for i in range(a):
	if len(u):
		count += 1
		totcost += u[-1]
		u.pop(-1)
	else:
		break
for i in range(b):
	if len(p):
		count += 1
		totcost += p[-1]
		p.pop(-1)
	else:
		break
for i in range(c):
	if len(u) and len(p):
		count += 1
		if u[-1] < p[-1]:
			totcost += u[-1]
			u.pop(-1)
		else:
			totcost += p[-1]
			p.pop(-1)
	elif len(u):
		count += 1
		totcost += u[-1]
		u.pop(-1)
	elif len(p):
		count += 1
		totcost += p[-1]
		p.pop(-1)
	else:
		break
print(count, totcost)


from collections import *
import pdb
(usb, ps_2, both) = map(int, input().split())
sales_usb = deque()
sales_ps_2 = deque()
for _ in range(int(input())):
	(value, type_) = input().split()
	value = int(value)
	if type_ == 'USB':
		sales_usb.append(value)
	else:
		sales_ps_2.append(value)

def remove_both(usb, ps, both):
	total = 0
	sold = 0
	while both != 0:
		if len(usb) != 0 and len(ps) != 0:
			if usb[0] >= ps[0]:
				total += ps.popleft()
				sold += 1
				both -= 1
			elif usb[0] < ps[0]:
				total += usb.popleft()
				sold += 1
				both -= 1
		elif len(usb) == 0 and len(ps) != 0:
			(temp_total, temp_sold, _) = remove_single(ps, both)
			total += temp_total
			sold += temp_sold
			both = 0
		elif len(ps) == 0 and len(usb) != 0:
			(temp_total, temp_sold, _) = remove_single(usb, both)
			total += temp_total
			sold += temp_sold
			both = 0
		else:
			both = 0
	return (total, sold)

def remove_single(slist, number):
	total = 0
	sold = 0
	while number != 0 and len(slist) > 0:
		total += slist.popleft()
		sold += 1
		number -= 1
	return (total, sold, slist)
sum_all = 0
sold = 0
sales_usb = sorted(sales_usb)
sales_ps_2 = sorted(sales_ps_2)
(t_sum_all, t_sold, sales_ps_2) = remove_single(deque(sales_ps_2), ps_2)
sum_all += t_sum_all
sold += t_sold
(t_sum_all, t_sold, sales_usb) = remove_single(deque(sales_usb), usb)
sold += t_sold
sum_all += t_sum_all
(t_sum_all, t_sold) = remove_both(deque(sales_usb), deque(sales_ps_2), both)
sum_all += t_sum_all
sold += t_sold
print(sold, sum_all)


(a, b, c) = map(int, input().split())
n = int(input())
usb = []
ps2 = []
for i in range(n):
	(n, m) = input().split()
	if m == 'USB':
		usb.append(int(n))
	else:
		ps2.append(int(n))
usb.sort()
ps2.sort()
u = min(len(usb), a)
p = min(len(ps2), b)
pr1 = sum(usb[:u])
pr2 = sum(ps2[:p])
com = usb[u:] + ps2[p:]
com.sort()
pr3 = sum(com[:c])
print(u + p + min(c, len(com)), pr1 + pr2 + pr3)


def list_from_input():
	return list(map(int, input().split()))

class Mouse:

	def __init__(self, price, type):
		self.type = type
		self.price = price

	@classmethod
	def from_input(cls):
		mouse_data = input().split()
		price = int(mouse_data[0])
		type = mouse_data[1][0]
		return Mouse(price, type)

def main():
	(usb_pc, ps_pc, both_pc) = list_from_input()
	mouses_count = int(input())
	mouses = []
	for i in range(mouses_count):
		mouses.append(Mouse.from_input())
	mouses.sort(key=lambda mouse: mouse.price)
	purchase_amount = 0
	pc_with_mouses = 0
	for mouse in mouses:
		if mouse.type is 'U' and usb_pc > 0:
			usb_pc -= 1
			purchase_amount += mouse.price
			pc_with_mouses += 1
		elif mouse.type is 'P' and ps_pc > 0:
			ps_pc -= 1
			purchase_amount += mouse.price
			pc_with_mouses += 1
		elif both_pc > 0:
			both_pc -= 1
			purchase_amount += mouse.price
			pc_with_mouses += 1
	print(pc_with_mouses, purchase_amount)
main()


inputLine = input().split()
pcU = int(inputLine[0])
pcP = int(inputLine[1])
pcUP = int(inputLine[2])
priceList1 = []
priceList2 = []
readSize = int(input())
for i in range(readSize):
	tmpList = input().split()
	if tmpList[1] == 'USB':
		priceList1.append(int(tmpList[0]))
	else:
		priceList2.append(int(tmpList[0]))
uNum = len(priceList1)
pNum = len(priceList2)
priceList1.sort()
priceList2.sort()
price = 0
equip = 0
tmp = min(uNum, pcU)
price += sum(priceList1[0:tmp])
equip += tmp
del priceList1[0:tmp]
uNum -= tmp
pcU -= tmp
tmp = min(pNum, pcP)
price += sum(priceList2[0:tmp])
equip += tmp
del priceList2[0:tmp]
pNum -= tmp
pcP -= tmp
priceList = priceList1
priceList.extend(priceList2)
priceList.sort()
fNum = len(priceList)
tmp = min(fNum, pcUP)
price += sum(priceList[0:tmp])
equip += tmp
print(str(equip) + ' ' + str(price))


(a, b, c) = input().strip().split()
(a, b, c) = (int(a), int(b), int(c))
m = int(input())
usb = []
ps = []
cnt = 0
sum = 0
up = []
for a0 in range(m):
	l = input().strip().split()
	if l[1] == 'USB':
		usb.append(l[0])
	else:
		ps.append(l[0])
usb = [int(i) for i in usb]
ps = [int(j) for j in ps]
usb.sort()
ps.sort()
lu = len(usb)
lp = len(ps)
if lu >= a:
	cnt += a
	for i in usb[0:a]:
		sum += i
	for j in usb[a:lu]:
		up.append(j)
else:
	cnt += lu
	for i in usb:
		sum += i
if lp >= b:
	cnt += b
	for i in ps[0:b]:
		sum += i
	for j in ps[b:lp]:
		up.append(j)
else:
	cnt += lp
	for i in ps:
		sum += i
up.sort()
lup = len(up)
if lup >= c:
	cnt += c
	for i in up[0:c]:
		sum += i
else:
	cnt += lup
	for i in up:
		sum += i
print(cnt, sum)


import math
import bisect
from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
(a, b, c) = M()
n = I()
u = []
p = []
for i in range(n):
	(n, k) = map(str, input().split())
	if k[0] == 'U':
		u += [int(n)]
	else:
		p += [int(n)]
u.sort()
p.sort()
ans = 0
ch = 0
for i in range(min(a, len(u))):
	ans += u[i]
	ch += 1
for i in range(min(b, len(p))):
	ans += p[i]
	ch += 1
d = u[min(a, len(u)):] + p[min(b, len(p)):]
d.sort()
for i in range(min(c, len(d))):
	ans += d[i]
	ch += 1
print(ch, ans)


(a, b, c) = map(int, input().split())
m = int(input())
dct = {}
if m == 0:
	print(0, 0)
	exit()
for _ in range(m):
	(i, j) = input().split()
	if j in dct.keys():
		dct[j].append(int(i))
	else:
		dct[j] = [int(i)]
lst1 = ['USB', 'PS/2']
for i in lst1:
	if i not in dct.keys():
		dct[i] = []
compct = 0
cost = 0
if len(dct['USB']) <= a:
	cost += sum(list(dct['USB']))
	compct += len(dct['USB'])
	rem1 = []
else:
	lst = list(dct['USB'])
	lst.sort()
	cost += sum(lst[:a])
	compct += a
	rem1 = lst[a:]
if len(dct['PS/2']) <= b:
	cost += sum(list(dct['PS/2']))
	compct += len(dct['PS/2'])
	rem2 = []
else:
	lst = list(dct['PS/2'])
	lst.sort()
	cost += sum(lst[:b])
	compct += b
	rem2 = lst[b:]
newlst = rem1 + rem2
l = len(newlst)
if l <= c:
	compct += l
	cost += sum(newlst)
else:
	newlst.sort()
	compct += c
	cost += sum(newlst[:c])
print(compct, cost)


(a, b, c) = map(int, input().split())
m = int(input())
PS = []
USB = []
res = 0
for i in range(m):
	q = input().split()
	if q[1] == 'USB':
		USB.append(int(q[0]))
	else:
		PS.append(int(q[0]))
PS.sort()
USB.sort()
a = min(a, len(USB))
b = min(b, len(PS))
res += sum(USB[:a])
res += sum(PS[:b])
UN = USB[a:] + PS[b:]
UN.sort()
c = min(c, len(UN))
res += sum(UN[:c])
print(a + b + c, res)


from sys import stdin, stdout
(a, b, c) = stdin.readline().split()
a = int(a)
b = int(b)
c = int(c)
m = int(stdin.readline())
vals = []
for _ in range(m):
	(cost, type) = stdin.readline().split()
	cost = int(cost)
	vals.append((cost, type))
vals.sort(key=lambda x: x[0])
cost = 0
total = 0
for (i, val) in enumerate(vals):
	(price, type) = val
	price = int(price)
	if a + b + c == 0:
		break
	if type == 'USB':
		if a > 0:
			a -= 1
			cost += price
			total += 1
		elif c > 0:
			c -= 1
			cost += price
			total += 1
	elif b > 0:
		b -= 1
		cost += price
		total += 1
	elif c > 0:
		c -= 1
		cost += price
		total += 1
print(total, cost)


(a, b, c) = list(map(int, input().split()))
n = int(input())
usb = list()
pc2 = list()
for i in range(n):
	kl = input().split()
	if kl[1] == 'USB':
		usb.append(int(kl[0]))
	else:
		pc2.append(int(kl[0]))
usb = sorted(usb)
pc2 = sorted(pc2)
summ = 0
num = 0
i = 0
j = 0
can = True
if len(usb) <= a:
	summ += sum(usb)
	i = len(usb)
	a -= len(usb)
	num += i
else:
	summ += sum(usb[0:a])
	i = a
	a = 0
	num += i
if len(pc2) <= b:
	summ += sum(pc2)
	j = len(pc2)
	b = 0
	num += len(pc2)
else:
	summ += sum(pc2[0:b])
	j = b
	b = 0
	num += j
while c > 0 and (i < len(usb) or j < len(pc2)):
	if i >= len(usb):
		if len(pc2) - j >= c:
			summ += sum(pc2[j:j + c])
			num += c
			c = 0
		else:
			summ += sum(pc2[j:])
			c = 0
			num += len(pc2[j:])
	elif j >= len(pc2):
		if len(usb) - i >= c:
			summ += sum(usb[i:i + c])
			num += c
			c = 0
		else:
			summ += sum(usb[i:])
			num += len(usb[i:])
			c = 0
	else:
		num += 1
		if usb[i] <= pc2[j]:
			summ += usb[i]
			c = c - 1
			i += 1
		else:
			summ += pc2[j]
			c = c - 1
			j += 1
print(num, summ)


(a, b, c) = map(int, input().split())
n = int(input())
u = []
p = []
ans = 0
if n == 0:
	print(0, 0)
else:
	for i in range(n):
		(x, y) = map(str, input().split())
		x = int(x)
		if y == 'USB':
			u.append(x)
		else:
			p.append(x)
	u.sort()
	p.sort()
	l = min(a, len(u))
	for i in range(l):
		ans += u[i]
	m = min(b, len(p))
	for i in range(m):
		ans += p[i]
		x = i
	uv = u[l:] + p[m:]
	uv.sort()
	n = min(c, len(uv))
	for i in range(n):
		ans += uv[i]
	print(l + m + n, ans)


(a, b, c) = map(int, input().split())
m = int(input())
(usb, ps2) = ([], [])
for i in range(m):
	s = input().split()
	if s[1] == 'USB':
		usb.append(int(s[0]))
	else:
		ps2.append(int(s[0]))
usb.sort()
ps2.sort()
(kusb, kps2) = (min(a, len(usb)), min(b, len(ps2)))
kans = kusb + kps2
sans = sum(usb[:kusb]) + sum(ps2[:kps2])
other = usb[kusb:] + ps2[kps2:]
other.sort()
kother = min(c, len(other))
kans += kother
sans += sum(other[:kother])
print(str(kans) + ' ' + str(sans))


(a, b, c) = map(int, input().split())
m = int(input())
x = list()
y = list()
for _ in range(m):
	(cost, mouse) = input().split()
	cost = int(cost)
	if mouse == 'USB':
		x.append(cost)
	else:
		y.append(cost)
x.sort(reverse=True)
y.sort(reverse=True)
total = 0
amount = 0
while x and (a > 0 or c > 0) or (y and (b > 0 or c > 0)):
	if a > 0 and x:
		a -= 1
		total += 1
		amount += x.pop()
	elif b > 0 and y:
		b -= 1
		total += 1
		amount += y.pop()
	elif c > 0:
		if x and y:
			if x[-1] < y[-1]:
				total += 1
				amount += x.pop()
			else:
				total += 1
				amount += y.pop()
		elif x:
			total += 1
			amount += x.pop()
		else:
			total += 1
			amount += y.pop()
		c -= 1
print(total, amount)


(u, p, b) = tuple(map(int, input().split()))
n = int(input())
equiped = 0
fullPrice = 0
arrusb = []
arrpc2 = []
for k in range(n):
	(price, mtype) = tuple(input().split())
	if mtype == 'USB':
		arrusb.append(int(price))
	else:
		arrpc2.append(int(price))
arrusb.sort()
arrpc2.sort()
bcounter = 0
pcounter = 0
for i in range(n):
	if bcounter == len(arrusb):
		if p > 0:
			fullPrice += arrpc2[pcounter]
			p -= 1
			equiped += 1
		elif b > 0:
			fullPrice += arrpc2[pcounter]
			b -= 1
			equiped += 1
		pcounter += 1
		continue
	if pcounter == len(arrpc2):
		if u > 0:
			fullPrice += arrusb[bcounter]
			u -= 1
			equiped += 1
		elif b > 0:
			fullPrice += arrusb[bcounter]
			b -= 1
			equiped += 1
		bcounter += 1
		continue
	if arrusb[bcounter] < arrpc2[pcounter]:
		if u > 0:
			fullPrice += arrusb[bcounter]
			u -= 1
			equiped += 1
		elif b > 0:
			fullPrice += arrusb[bcounter]
			b -= 1
			equiped += 1
		bcounter += 1
	else:
		if p > 0:
			fullPrice += arrpc2[pcounter]
			p -= 1
			equiped += 1
		elif b > 0:
			fullPrice += arrpc2[pcounter]
			b -= 1
			equiped += 1
		pcounter += 1
print(str(equiped) + ' ' + str(fullPrice))


from sys import stdin as fin
(a, b, c) = input().split()
a = int(a)
b = int(b)
c = int(c)
n = int(input())
mouses = []
for i in range(0, n):
	(l, r) = fin.readline().strip().split()
	mouses.append((int(l), r))
mouses.sort()
money_count = 0
comp_count = 0
for t in mouses:
	if t[1] == 'USB' and a + c or (t[1] == 'PS/2' and b + c):
		money_count += t[0]
		comp_count += 1
	if t[1] == 'USB':
		if a:
			a -= 1
		elif c:
			c -= 1
	if t[1] == 'PS/2':
		if b:
			b -= 1
		elif c:
			c -= 1
print(comp_count, money_count)


(a, b, c) = map(int, input().split())
m = int(input())
u = []
p = []
x = 0
y = 0
for i in range(m):
	s = input().split()
	if s[1] == 'USB':
		u.append(int(s[0]))
	else:
		p.append(int(s[0]))
u.sort()
p.sort()
u.reverse()
p.reverse()
while u and a:
	a -= 1
	y += u[-1]
	u.pop()
	x += 1
while p and b:
	b -= 1
	y += p[-1]
	p.pop()
	x += 1
u += p
u.sort()
u.reverse()
while u and c:
	c -= 1
	y += u[-1]
	u.pop()
	x += 1
print(x, y)


usb = []
ps = []
nc = 0
pr = 0
s = input()
s = s.split()
u = int(s[0])
p = int(s[1])
up = int(s[2])
m = int(input())
for i in range(m):
	b = input()
	b = b.split()
	pri = int(b[0])
	ty = b[1]
	if ty == 'USB':
		usb.append(pri)
	else:
		ps.append(pri)
usb.sort()
ps.sort()
if len(usb) <= u:
	pr += sum(usb)
	nc += len(usb)
	k1 = []
else:
	pr += sum(usb[0:u])
	nc += u
	k1 = usb[u:len(usb)]
if len(ps) <= p:
	pr += sum(ps)
	nc += len(ps)
	k2 = []
else:
	pr += sum(ps[0:p])
	nc += p
	k2 = ps[p:len(ps)]
k = k1 + k2
k.sort()
if len(k) <= up:
	pr += sum(k)
	nc += len(k)
else:
	pr += sum(k[0:up])
	nc += up
print(nc, pr)


(a, b, c) = map(int, input().split())
m = int(input())
usbMice = []
ps2Mice = []
for i in range(m):
	(price, mouseType) = input().split()
	if mouseType == 'USB':
		usbMice.append(int(price))
	else:
		ps2Mice.append(int(price))
usbMice.sort()
ps2Mice.sort()
quantity = 0
totalPrice = 0
aOk = min(a, len(usbMice))
bOk = min(b, len(ps2Mice))
totalPrice += sum(usbMice[:aOk])
totalPrice += sum(ps2Mice[:bOk])
mixMice = usbMice[aOk:] + ps2Mice[bOk:]
mixMice.sort()
cOk = min(c, len(mixMice))
totalPrice += sum(mixMice[:cOk])
quantity = aOk + bOk + cOk
print(quantity, totalPrice)


from collections import deque

class CodeforcesTask762BSolution:

	def __init__(self):
		self.result = ''
		self.a_b_c = []
		self.m = 0
		self.prices = []

	def read_input(self):
		self.a_b_c = [int(x) for x in input().split(' ')]
		self.m = int(input())
		for _ in range(self.m):
			self.prices.append(input().split(' '))
			self.prices[-1][0] = int(self.prices[-1][0])
			self.prices[-1][1] = 0 if self.prices[-1][1] == 'USB' else 1

	def process_task(self):
		prices1 = [x[0] for x in self.prices if not x[1]]
		prices2 = [x[0] for x in self.prices if x[1]]
		prices1.sort()
		prices2.sort()
		equipped = 0
		cost = 0
		prices1 = deque(prices1)
		prices2 = deque(prices2)
		while prices1 and self.a_b_c[0]:
			equipped += 1
			cost += prices1.popleft()
			self.a_b_c[0] -= 1
		while prices2 and self.a_b_c[1]:
			equipped += 1
			cost += prices2.popleft()
			self.a_b_c[1] -= 1
		while (prices1 or prices2) and self.a_b_c[2]:
			equipped += 1
			self.a_b_c[2] -= 1
			if prices1 and prices2:
				if prices1[0] <= prices2[0]:
					cost += prices1.popleft()
				else:
					cost += prices2.popleft()
			elif prices1:
				cost += prices1.popleft()
			else:
				cost += prices2.popleft()
		self.result = f'{equipped} {cost}'

	def get_result(self):
		return self.result
Solution = CodeforcesTask762BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


comp = []
ind = input().split()
for i in range(3):
	comp.append(int(ind[i]))
USB = []
PS2 = []
for i in range(int(input())):
	a = input().split()
	if a[1] == 'PS/2':
		PS2.append(int(a[0]))
	else:
		USB.append(int(a[0]))
USB.sort()
PS2.sort()
usb = min(comp[0], len(USB))
ps2 = min(comp[1], len(PS2))
ALL = USB[usb:] + PS2[ps2:]
ALL.sort()
two = min(len(ALL), comp[2])
print(usb + ps2 + two, sum(USB[:usb]) + sum(PS2[:ps2]) + sum(ALL[:two]))


(a, b, c) = [int(i) for i in input().split()]
n = int(input())
A = []
ps = []
usb = []
for i in range(n):
	s = input().split()
	s[0] = int(s[0])
	if s[1] == 'USB':
		usb.append(s[0])
	else:
		ps.append(s[0])
ps.sort()
usb.sort()
usbptr = 0
psptr = 0
totalnum = 0
totalcost = 0
for i in range(a):
	if usbptr < len(usb):
		totalcost += usb[usbptr]
		usbptr += 1
		totalnum += 1
	elif usbptr == len(usb):
		break
for i in range(b):
	if psptr < len(ps):
		totalcost += ps[psptr]
		psptr += 1
		totalnum += 1
	elif psptr == len(ps):
		break
for i in range(c):
	if usbptr < len(usb) and psptr < len(ps):
		if usb[usbptr] < ps[psptr]:
			totalcost += usb[usbptr]
			usbptr += 1
			totalnum += 1
		else:
			totalcost += ps[psptr]
			psptr += 1
			totalnum += 1
	elif usbptr == len(usb) and psptr < len(ps):
		totalcost += ps[psptr]
		psptr += 1
		totalnum += 1
	elif usbptr < len(usb) and psptr == len(ps):
		totalcost += usb[usbptr]
		usbptr += 1
		totalnum += 1
	else:
		break
print(totalnum, totalcost)


import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def SieveOfEratosthenes(n):
	prime = []
	primes = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if primes[p] == True:
			prime.append(p)
			for i in range(p * p, n + 1, p):
				primes[i] = False
		p += 1
	return prime

def primefactors(n):
	fac = []
	while n % 2 == 0:
		fac.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 2):
		while n % i == 0:
			fac.append(i)
			n = n // i
	if n > 1:
		fac.append(n)
	return fac

def factors(n):
	fac = set()
	fac.add(1)
	fac.add(n)
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			fac.add(i)
			fac.add(n // i)
	return list(fac)

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x
(a, b, c) = list(map(int, input().split()))
m = int(input())
usb = []
ps = []
cost = 0
for i in range(m):
	(ca, t) = list(input().split())
	ca = int(ca)
	if t == 'USB':
		usb.append(ca)
	else:
		ps.append(ca)
usb.sort()
ps.sort()
usb_c = len(usb)
ps_c = len(ps)
j = 0
i = 0
ec = 0
while i < usb_c and a > 0:
	cost += usb[i]
	ec += 1
	i += 1
	a -= 1
while j < ps_c and b > 0:
	cost += ps[j]
	j += 1
	ec += 1
	b -= 1
na = usb[i:] + ps[j:]
na.sort()
i = 0
while i < len(na) and c > 0:
	cost = cost + na[i]
	ec += 1
	i += 1
	c -= 1
print(str(ec) + ' ' + str(cost))


(a, b, c) = map(int, input().split())
m = int(input())
usb = []
ps2 = []
for i in range(m):
	s = input().split()
	if s[1] == 'USB':
		usb.append(int(s[0]))
	else:
		ps2.append(int(s[0]))
usb.sort()
if a > len(usb):
	sum1 = sum(usb)
	p1 = len(usb)
	usb = []
else:
	sum1 = sum(usb[:a])
	p1 = a
	usb = usb[a:]
ps2.sort()
if b > len(ps2):
	sum2 = sum(ps2)
	p2 = len(ps2)
	ps2 = []
else:
	sum2 = sum(ps2[:b])
	p2 = b
	ps2 = ps2[b:]
uni = usb + ps2
uni.sort()
if c > len(uni):
	sum3 = sum(uni)
	p3 = len(uni)
else:
	sum3 = sum(uni[:c])
	p3 = c
p = p1 + p2 + p3
sumall = sum1 + sum2 + sum3
print(p, sumall)


def calc(a, b, c, p):
	s = 0
	comp = 0
	for (k, v) in p:
		if a > 0 or b > 0 or c > 0:
			if 'USB' == v and (a > 0 or c > 0):
				if a > 0:
					comp += 1
					a -= 1
				elif c > 0:
					comp += 1
					c -= 1
				s += int(k)
			elif 'PS/2' == v and (b > 0 or c > 0):
				if b > 0:
					comp += 1
					b -= 1
				elif c > 0:
					comp += 1
					c -= 1
				s += int(k)
		else:
			return (comp, s)
	return (comp, s)

def convertor(lis):
	(a, b) = lis.split(' ')
	return [int(a), b]
(a, b, c) = list(map(int, input().split(' ')))
m = int(input())
p = sorted([convertor(input()) for i in range(m)])
r = calc(a, b, c, p)
print(str(r[0]) + ' ' + str(r[1]))