The year of 2012 is coming...

According to an ancient choradrican legend in this very year, in 2012, Diablo and his brothers Mephisto and Baal will escape from hell, and innumerable hordes of demons will enslave the human world. But seven brave heroes have already gathered on the top of a mountain Arreat to protect us mere mortals from the effect of this terrible evil.

The seven great heroes are: amazon Anka, barbarian Chapay, sorceress Cleo, druid Troll, necromancer Dracul, paladin Snowy and a professional hit girl Hexadecimal. Heroes already know how much experience will be given for each of the three megabosses: a for Mephisto, b for Diablo and c for Baal.

Here's the problem: heroes are as much as seven and megabosses are only three! Then our heroes decided to split into three teams, where each team will go to destroy their own megaboss. Each team member will receive a <image> of experience, rounded down, where x will be the amount of experience for the killed megaboss and y — the number of people in the team.

Heroes do not want to hurt each other's feelings, so they want to split into teams so that the difference between the hero who received the maximum number of experience and the hero who received the minimum number of experience were minimal. Since there can be several divisions into teams, then you need to find the one in which the total amount of liking in teams were maximum.

It is known that some heroes like others. But if hero p likes hero q, this does not mean that the hero q likes hero p. No hero likes himself.

The total amount of liking in teams is the amount of ordered pairs (p, q), such that heroes p and q are in the same group, and hero p likes hero q (but it is not important if hero q likes hero p). In case of heroes p and q likes each other and they are in the same group, this pair should be counted twice, as (p, q) and (q, p).

A team can consist even of a single hero, but it is important that every megaboss was destroyed. All heroes must be involved in the campaign against evil. None of the heroes can be in more than one team.

It is guaranteed that every hero is able to destroy any megaboss alone.

Input

The first line contains a single non-negative integer n (0 ≤ n ≤ 42) — amount of liking between the heroes. Next n lines describe liking in the form "p likes q", meaning that the hero p likes the hero q (p ≠  q). Every liking is described in the input exactly once, no hero likes himself.

In the last line are given three integers a, b and c (1 ≤ a, b, c ≤ 2·109), separated by spaces: the experience for Mephisto, the experience for Diablo and experience for Baal.

In all the pretests, except for examples from the statement, the following condition is satisfied: a = b = c.

Output

Print two integers — the minimal difference in the experience between two heroes who will receive the maximum and minimum number of experience points, and the maximal total amount of liking in teams (the number of friendships between heroes that end up in one team).

When calculating the second answer, the team division should satisfy the difference-minimizing contraint. I.e. primary you should minimize the difference in the experience and secondary you should maximize the total amount of liking.

Examples

Input

3
Troll likes Dracul
Dracul likes Anka
Snowy likes Hexadecimal
210 200 180


Output

30 3


Input

2
Anka likes Chapay
Chapay likes Anka
10000 50 50


Output

1950 2

Note

A note to first example: it the first team should be Dracul, Troll and Anka, in the second one Hexadecimal and Snowy, and in the third Cleo и Chapay.

Source: codeforces | Difficulty: MEDIUM
Tags: Implementation

Complete search


Solutions:
from itertools import product, permutations, combinations
n = int(input())
names = {}
nex = 0
mama = 128
liking = [0] * mama
likes = [[0] * 7 for _ in range(7)]

def getName(name):
	global nex
	if name in names:
		return names[name]
	names[name] = nex
	nex += 1
	return names[name]
for _ in range(n):
	(a, b, c) = input().split()
	likes[getName(a)][getName(c)] = 1
bosses = [int(x) for x in input().split()]
part = set()
part.add((0, 0, 0))
dipart = 10 ** 10
for i in range(1, 4):
	for j in range(i, 7):
		k = 7 - i - j
		if k < j:
			continue
		for per in permutations(bosses):
			aa = (per[0] // i, per[1] // j, per[2] // k)
			difi = max(aa) - min(aa)
			if difi < dipart:
				dipart = difi
				part = set()
				part.add((i, j, k))
			elif difi == dipart:
				part.add((i, j, k))
for (i, j) in product(range(7), repeat=2):
	if likes[i][j] == 0:
		continue
	mask = 1 << i | 1 << j
	for k in range(mama):
		if k & mask == mask:
			liking[k] += 1
nums = list(range(7))

def tonum(ite):
	r = 0
	for nu in ite:
		r |= 1 << nu
	return r
bea = 0
for (a, b, c) in part:
	for pera in combinations(range(7), a):
		lefta = [x for x in nums if x not in pera]
		for perb in combinations(lefta, b):
			perc = [x for x in lefta if x not in perb]
			susu = liking[tonum(pera)] + liking[tonum(perb)] + liking[tonum(perc)]
			if susu > bea:
				bea = susu
print(dipart, bea)


import itertools
heroes = ['Anka', 'Chapay', 'Cleo', 'Troll', 'Dracul', 'Snowy', 'Hexadecimal']
n = int(input())
edges = []
for i in range(n):
	(p, likes, q) = input().split()
	edges.append((heroes.index(p), heroes.index(q)))
boss_xp = list(map(int, input().split()))
min_difference = float('inf')
max_liking = float('-inf')
for assignment in itertools.product(range(3), repeat=7):
	assignment_heroes = [[hero for (hero, boss) in enumerate(assignment) if boss == i] for i in range(3)]
	if any((len(attackers) == 0 for attackers in assignment_heroes)):
		continue
	xp_division = [xp // len(attackers) for (xp, attackers) in zip(boss_xp, assignment_heroes)]
	difference = max(xp_division) - min(xp_division)
	if difference < min_difference:
		min_difference = difference
		max_liking = sum((len([(p, q) for (p, q) in edges if p in attackers and q in attackers]) for attackers in assignment_heroes))
	elif difference == min_difference:
		liking = sum((len([(p, q) for (p, q) in edges if p in attackers and q in attackers]) for attackers in assignment_heroes))
		max_liking = max(max_liking, liking)
print('%d %d' % (min_difference, max_liking))


from itertools import combinations

def main():
	heroes = ('Anka', 'Chapay', 'Cleo', 'Troll', 'Dracul', 'Snowy', 'Hexadecimal')
	sympaty = [[False] * 7 for _ in range(7)]
	for _ in range(int(input())):
		(a, _, b) = input().split()
		sympaty[heroes.index(a)][heroes.index(b)] = True
	(a, b, c) = map(int, input().split())
	(tmp, res) = ([], [])
	for i in range(1, 6):
		for j in range(1, 7 - i):
			t = (int(a / i), int(b / j), int(c / (7 - i - j)))
			tmp.append((max(t) - min(t), i, j))
	delta = min(tmp)[0]
	for (i, j) in ((i, j) for (x, i, j) in tmp if x == delta):
		for aa in combinations(range(7), i):
			rest = [x for x in range(7) if x not in aa]
			for bb in combinations(rest, j):
				res.append(sum((sum((sympaty[x][y] for x in xy for y in xy)) for xy in (aa, bb, [x for x in rest if x not in bb]))))
	print(delta, max(res))
main()


import itertools

def sets(heros, min_elem, max_elem):
	ans = []
	if max_elem > len(heros):
		max_elem = len(heros)
	if min_elem > len(heros):
		return []
	for i in range(min_elem, max_elem + 1):
		s = itertools.combinations(heros, i)
		for ss in s:
			ans.append(ss)
	return ans

def update(set1, set2, set3, x, y, a, b, c, pairs):
	q = a // len(set1)
	w = b // len(set2)
	e = c // len(set3)
	m = max(abs(q - w), abs(w - e), abs(e - q))
	if m == x:
		x = m
		y1 = 0
		for p in pairs:
			if p[0] in set1 and p[1] in set1 or (p[0] in set2 and p[1] in set2) or (p[0] in set3 and p[1] in set3):
				y1 += 1
		if y < y1:
			y = y1
	if m < x:
		x = m
		y = 0
		for p in pairs:
			if p[0] in set1 and p[1] in set1 or (p[0] in set2 and p[1] in set2) or (p[0] in set3 and p[1] in set3):
				y += 1
	return (x, y)

def solve(n, pairs, a, b, c):
	(x, y) = (100000000000000, 0)
	heros = ['Anka', 'Chapay', 'Cleo', 'Troll', 'Dracul', 'Snowy', 'Hexadecimal']
	for_set1 = sets(heros, 1, 5)
	for set1 in for_set1:
		heros2 = []
		for i in heros:
			if i not in set1:
				heros2.append(i)
		for_set2 = sets(heros2, 1, 7 - len(set1))
		for set2 in for_set2:
			set3 = []
			for i in heros2:
				if i not in set2:
					set3.append(i)
			if len(set1) > 0 and len(set2) > 0 and (len(set3) > 0):
				(x, y) = update(set1, set2, set3, x, y, a, b, c, pairs)
	return (x, y)
n = int(input())
pairs = []
for i in range(n):
	(x, _, y) = input().split()
	pairs.append((x, y))
(a, b, c) = input().split()
a = int(a)
b = int(b)
c = int(c)
(x, y) = solve(a, pairs, a, b, c)
print(x, y)


R = range
S = str.split
I = input
L = S('Anka Chapay Cleo Troll Dracul Snowy Hexadecimal')
h = {}
for i in R(7):
	h[L[i]] = i
d = [[] for i in R(9)]
for z in '0' * int(I()):
	(a, _, b) = S(I())
	d[h[a]] += [h[b]]
(a, b, c) = map(int, S(I()))
o = [10 ** 9, 0]

def C(q, w, e, n):
	if n == 7:
		if not (q and w and e):
			return
		p = [a // len(q), b // len(w), c // len(e)]
		p = max(p) - min(p)
		l = sum((k in g for g in (q, w, e) for h in g for k in d[h]))
		global o
		if o[0] > p or (o[0] == p and o[1] < l):
			o = (p, l)
	else:
		C(q + [n], w, e, n + 1)
		C(q, w + [n], e, n + 1)
		C(q, w, e + [n], n + 1)
C([], [], [], 0)
print(o[0], o[1])


from itertools import *
p = {'An': 0, 'Ch': 1, 'Cl': 2, 'Tr': 3, 'Dr': 4, 'Sn': 5, 'He': 6}

def f():
	(u, l, v) = input().split()
	return (p[u[:2]], p[v[:2]])
s = [f() for k in range(int(input()))]
(a, b, c) = map(int, input().split())
d = l = 9000000000.0
for i in range(1, 6):
	for j in range(1, 7 - i):
		k = 7 - i - j
		t = [a // i, b // j, c // k]
		t = max(t) - min(t)
		if t < d:
			(d, l) = (t, 0)
		if t == d:
			for q in set(permutations([0] * i + [1] * j + [2] * k)):
				l = max(l, sum((q[u] == q[v] for (u, v) in s)))
print(d, l)