using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var str = new string[5]; for (var i = 0; i < 5; ++i) str[i] = ReadLine(); var dic = new Dictionary(); var coins = new int[5]; for (var i = 0; i < 5; ++i) { var s = str[i].Split(); dic[s[0]] = i; coins[i] = int.Parse(s[1]); } var n1 = NN; var acount = new int[5]; for (var i = 0; i < n1; ++i) { var s = ReadLine(); ++acount[dic[s]]; } var n2 = NN; var b = new int[n2]; var bcount = new int[5]; for (var i = 0; i < n2; ++i) { var s = ReadLine(); b[i] = dic[s]; ++bcount[dic[s]]; } var n3 = NN; var ccount = new int[5]; for (var i = 0; i < n3; ++i) { var s = ReadLine(); ++ccount[dic[s]]; } var counts = new long[5]; var ans = 0.0; for (var i = 0; i < 5; ++i) { counts[i] = (long)acount[i] * bcount[i] * ccount[i] * 5; ans += counts[i] / (double)n1 / n2 / n3 * coins[i]; } WriteLine(ans); WriteLine(string.Join("\n", counts)); } }