Problem: 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.

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;


public class TestC {

	public void run() throws Exception{
		
		List<String> names = new ArrayList<String>();
		names.add("Troll");
		names.add("Anka");
		names.add("Chapay");
		names.add("Cleo");
		names.add("Dracul");
		names.add("Snowy");
		names.add("Hexadecimal");
		
		//BufferedReader br = new BufferedReader(new FileReader("input.txt"));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		int like = Integer.parseInt(line);
		List<List<String>> pair = new ArrayList<List<String>>();
		int a = 0;
		int b = 0;
		int c = 0;
		while( (line =br.readLine()) != null ){
			String[] lines = line.split("\\s");
			if(lines[1].equals("likes")){
				List<String> list = new ArrayList<String>();
				list.add(lines[0]);
				list.add(lines[2]);
				pair.add(list);
			}
			else{
				a = Integer.parseInt(lines[0]);
				b = Integer.parseInt(lines[1]);
				c = Integer.parseInt(lines[2]);
			}
		}
		if(a < b){
			int tmp = a;
			a = b;
			b = tmp;
		}
		if(b < c){
			int tmp = b;
			b = c;
			c = tmp;
		}
		if(a < b){
			int tmp = a;
			a = b;
			b = tmp;
		}
		
		int min = Integer.MAX_VALUE;
		int lk = 0;
		{
			int ae = a / 5;
			int be = b / 1;
			int ce = c / 1;
			int dif = check(ae, be, ce);
			min = dif;
			
			String[] strs = new String[0];
			strs = names.toArray(strs);
			int k = 5;
	
			Enumeration e = new CombEnum(strs, k);
			while(e.hasMoreElements()) {
				Object[] aa = (Object[])e.nextElement();
				List<String> flist = new ArrayList<String>();
				for(int i=0; i<aa.length; i++){
					flist.add((String)aa[i]);
				}
				int mylk = 0;
				for(int i = 0; i < pair.size(); i++){
					List<String> pp = pair.get(i);
					String fn = pp.get(0);
					String sn = pp.get(1);
					if(flist.contains(fn) && flist.contains(sn)){
						mylk++;
					}
				}
				if(lk < mylk){
					lk = mylk;
				}
			}
		}
		{
			int ae = a / 4;
			int be = b / 2;
			int ce = c / 1;
			int dif = check(ae, be, ce);
			if(dif < min){
				min = dif;
				String[] strs = new String[0];
				strs = names.toArray(strs);
				Enumeration e = new PermEnum(strs);
				int count = 0;
				int mylk = 0;
				while(e.hasMoreElements()) {
					String[] aa = (String[])e.nextElement();
					
					
					List<String> list1 = new ArrayList<String>();
					List<String> list2 = new ArrayList<String>();
					for(int i=0; i<4; i++){
						list1.add(aa[i]);
					}
					for(int i = 4; i < 6; i++){
						list2.add(aa[i]);
					}
					int tmplk = 0;
					int num1 = Math.max(tmplk, cntfrd(pair, list1, like));
					int num2 = Math.max(tmplk, cntfrd(pair, list2, like));
					tmplk = num1 + num2;
					if(mylk < tmplk){
						mylk = tmplk;
					}
				}
				lk = mylk;
			}
			else if(dif == min){
				min = dif;
				String[] strs = new String[0];
				strs = names.toArray(strs);
				Enumeration e = new PermEnum(strs);
				int count = 0;
				int mylk = 0;
				while(e.hasMoreElements()) {
					String[] aa = (String[])e.nextElement();
					
					
					List<String> list1 = new ArrayList<String>();
					List<String> list2 = new ArrayList<String>();
					for(int i=0; i<4; i++){
						list1.add(aa[i]);
					}
					for(int i = 4; i < 6; i++){
						list2.add(aa[i]);
					}
					int tmplk = 0;
					int num1 = Math.max(tmplk, cntfrd(pair, list1, like));
					int num2 = Math.max(tmplk, cntfrd(pair, list2, like));
					tmplk = num1 + num2;
					if(mylk < tmplk){
						mylk = tmplk;
					}
				}
				if(lk < mylk){
					lk = mylk;
				}
			}
		}
		{
			int ae = a / 3;
			int be = b / 3;
			int ce = c / 1;
			int dif = check(ae, be, ce);
			if(dif < min){
				min = dif;
				String[] strs = new String[0];
				strs = names.toArray(strs);
				Enumeration e = new PermEnum(strs);
				int count = 0;
				int mylk = 0;
				while(e.hasMoreElements()) {
					String[] aa = (String[])e.nextElement();
					
					
					List<String> list1 = new ArrayList<String>();
					List<String> list2 = new ArrayList<String>();
					for(int i=0; i<3; i++){
						list1.add(aa[i]);
					}
					for(int i = 3; i < 6; i++){
						list2.add(aa[i]);
					}
					int tmplk = 0;
					int num1 = Math.max(tmplk, cntfrd(pair, list1, like));
					int num2 = Math.max(tmplk, cntfrd(pair, list2, like));
					tmplk = num1 + num2;
					if(mylk < tmplk){
						mylk = tmplk;
					}
				}
				lk = mylk;
			}
			else if(dif == min){
				min = dif;
				String[] strs = new String[0];
				strs = names.toArray(strs);
				Enumeration e = new PermEnum(strs);
				int count = 0;
				int mylk = 0;
				while(e.hasMoreElements()) {
					String[] aa = (String[])e.nextElement();
					
					
					List<String> list1 = new ArrayList<String>();
					List<String> list2 = new ArrayList<String>();
					for(int i=0; i<3; i++){
						list1.add(aa[i]);
					}
					for(int i = 3; i < 6; i++){
						list2.add(aa[i]);
					}
					int tmplk = 0;
					int num1 = Math.max(tmplk, cntfrd(pair, list1, like));
					int num2 = Math.max(tmplk, cntfrd(pair, list2, like));
					tmplk = num1 + num2;
					if(mylk < tmplk){
						mylk = tmplk;
					}
				}
				if(lk < mylk){
					lk = mylk;
				}
			}
		}
		{
			int ae = a / 3;
			int be = b / 2;
			int ce = c / 2;
			int dif = check(ae, be, ce);
			if(dif < min){
				min = dif;
				String[] strs = new String[0];
				strs = names.toArray(strs);
				Enumeration e = new PermEnum(strs);
				int count = 0;
				int mylk = 0;
				while(e.hasMoreElements()) {
					String[] aa = (String[])e.nextElement();
					
					
					List<String> list1 = new ArrayList<String>();
					List<String> list2 = new ArrayList<String>();
					List<String> list3 = new ArrayList<String>();
					
					for(int i=0; i<3; i++){
						list1.add(aa[i]);
					}
					for(int i = 3; i < 5; i++){
						list2.add(aa[i]);
					}
					for(int i = 5; i < 7; i++){
						list3.add(aa[i]);
					}
					int tmplk = 0;
					int num1 = Math.max(tmplk, cntfrd(pair, list1, like));
					int num2 = Math.max(tmplk, cntfrd(pair, list2, like));
					int num3 = Math.max(tmplk, cntfrd(pair, list3, like));
					tmplk = num1 + num2 + num3;
					if(mylk < tmplk){
						mylk = tmplk;
					}
				}
				lk = mylk;
			}
			else if(dif == min){
				min = dif;
				String[] strs = new String[0];
				strs = names.toArray(strs);
				Enumeration e = new PermEnum(strs);
				int count = 0;
				int mylk = 0;
				while(e.hasMoreElements()) {
					String[] aa = (String[])e.nextElement();
					
					
					List<String> list1 = new ArrayList<String>();
					List<String> list2 = new ArrayList<String>();
					List<String> list3 = new ArrayList<String>();
					
					for(int i=0; i<3; i++){
						list1.add(aa[i]);
					}
					for(int i = 3; i < 5; i++){
						list2.add(aa[i]);
					}
					for(int i = 5; i < 7; i++){
						list3.add(aa[i]);
					}
					int tmplk = 0;
					int num1 = Math.max(tmplk, cntfrd(pair, list1, like));
					int num2 = Math.max(tmplk, cntfrd(pair, list2, like));
					int num3 = Math.max(tmplk, cntfrd(pair, list3, like));
					tmplk = num1 + num2 + num3;
					if(mylk < tmplk){
						mylk = tmplk;
					}
				}
				if(lk < mylk){
					lk = mylk;
				}
			}
		}
		System.out.println(min + " " + lk);
		
		
	}
	
	public int cntfrd(List<List<String>> pair, List<String> flist, int like){
		int mylk = 0;
		for(int i = 0; i < pair.size(); i++){
			List<String> pp = pair.get(i);
			String fn = pp.get(0);
			String sn = pp.get(1);
			if(flist.contains(fn) && flist.contains(sn)){
				mylk++;
			}
		}
		return mylk;
	}
	
	class PermEnum implements Enumeration {

		private int N;
		private int c[], k;
		private Object[] objs;

		public PermEnum(Object[] items) {
			N = items.length;
			c = new int[N + 1];
			for(int i=0; i<=N; i++) c[i] = i;
			objs = items;
			k = 1;
		}

		public boolean hasMoreElements() {
			return (k < N);
		}

		public Object nextElement() {
			int i = 0;
			if((k & 1) != 0) i = c[k];

			Object tmp = objs[k];
			objs[k] = objs[i];
			objs[i] = tmp;

			k = 1;
			while(c[k] == 0) c[k] = k++;

			c[k]--;
			return objs;
		}

	}

	
	class CombEnum implements Enumeration {

		private int N;
		private BitSet X;
		private Object[] items;
		private Object[] array;

		public CombEnum(Object[] items, int k) {
			this.items = items;
			N = items.length;
			array = new Object[k];
			X  = new BitSet(N + 1);
			for(int i=0; i<k; i++) X.set(i);
		}

		public boolean hasMoreElements() {
			return ! X.get(N);
		}

		// �E���猩�čŏ��ɂP�ƂȂ�ʒu��Ԃ�
		// �I�[���O�Ȃ� -1 ��Ԃ�
		// bs = 10011100
		// return 2
		private int findOne(BitSet bs) {
			int len = bs.size();
			for(int i=0; i<=N; i++) {
				if(bs.get(i)) return i;
			}
			return -1;
		}

		// �w�肳�ꂽ�ʒu�ŃC���N�������g����
		// ���オ�肵�����̌�����Ԃ�
		// bs = 10011100, n = 2
		// bs = 10100000
		// return 3
		private int incr(BitSet bs, int n) {
			int a = 0;
			for(;;) {
				if(bs.get(n)) {
					bs.clear(n); n++; a++;
				} else {
					bs.set(n); break;
				}
			}
			return a;
		}

		public Object nextElement() {
			int k = 0;
			for(int i=0; i<=N; i++) {
				if(X.get(i)) array[k++] = items[i];
			}
			int u = incr(X, findOne(X)) - 1;
			for(int i=0; i<u; i++) X.set(i);
			return array;
		}

		/*
		public static void main(String[] args) {
			String[] strs = {"1", "2", "3", "4", "5", "6"};
			int k = 3;
			System.out.println("N="+strs.length);
			System.out.println("K="+k);
			int count = 0;
			Enumeration e = new CombEnum(strs, k);
			while(e.hasMoreElements()) {
				Object[] a = (Object[])e.nextElement();
				System.out.print("{" + a[0]);
				for(int i=1; i<a.length; i++)
					System.out.print(", "+a[i]);
				System.out.println("}");
				count++;
			}
			System.out.println("count="+count);
		}
		*/
	}


	
	public int check(int a, int b, int c){
		if(a < b){
			int tmp = a;
			a = b;
			b = tmp;
		}
		if(b < c){
			int tmp = b;
			b = c;
			c = tmp;
		}
		if(a < b){
			int tmp = a;
			a = b;
			b = tmp;
		}
		return a - c;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		TestC t = new TestC();
		t.run();
	}

}