using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main() { var s = new string[5]; var v = new int[5]; for (int i = 0; i < 5; i++) { var inp = ReadLine().Split(); s[i] = inp[0]; v[i] = int.Parse(inp[1]); } var reel = new string[3][]; var n = new int[3]; n[0] = int.Parse(ReadLine()); reel[0] = new string[n[0]]; for (int i = 0; i < n[0]; i++) { reel[0][i] = ReadLine(); } n[1] = int.Parse(ReadLine()); reel[1] = new string[n[1]]; for (int i = 0; i < n[1]; i++) { reel[1][i] = ReadLine(); } n[2] = int.Parse(ReadLine()); reel[2] = new string[n[2]]; for (int i = 0; i < n[2]; i++) { reel[2][i] = ReadLine(); } var g = new int[3][] { new int[5], new int[5], new int[5] }; for (int i = 0; i < 3; i++) { for (int j = 0; j < 5; j++) { g[i][j] = reel[i].Count(x => x == s[j]); } } var u = new int[5]; for (int i = 0; i < 5; i++) { u[i] = g[0][i] * g[1][i] * g[2][i] * 5; } var r = new Random(); var rsa = 0L; for (int i = 0; i < 5000000; i++) { var rs = 0; var r0 = r.Next(n[0] ); var r1 = r.Next(n[1] ); var r2 = r.Next(n[2] ); if (reel[0][r0] == reel[1][r1] && reel[0][r0] == reel[2][r2]) { rs += reel[0][r0] == s[0] ? v[0] : reel[0][r0] == s[1] ? v[1] : reel[0][r0] == s[2] ? v[2] : reel[0][r0] == s[3] ? v[3] : reel[0][r0] == s[4] ? v[4] : 0; } if (reel[0][(r0 + 1)%n[0]] == reel[1][(r1 + 1)%n[1]] && reel[0][(r0 + 1)%n[0]] == reel[2][(r2 + 1)%n[2]]) { rs += reel[0][(r0 + 1)%n[0]] == s[0] ? v[0] : reel[0][(r0 + 1)%n[0]] == s[1] ? v[1] : reel[0][(r0 + 1)%n[0]] == s[2] ? v[2] : reel[0][(r0 + 1)%n[0]] == s[3] ? v[3] : reel[0][(r0 + 1)%n[0]] == s[4] ? v[4] : 0; } if (reel[0][(r0 + 2)%n[0]] == reel[1][(r1 + 2)%n[1]] && reel[0][(r0 + 2)%n[0]] == reel[2][(r2 + 2)%n[2]]) { rs += reel[0][(r0 + 2)%n[0]] == s[0] ? v[0] : reel[0][(r0 + 2)%n[0]] == s[1] ? v[1] : reel[0][(r0 + 2)%n[0]] == s[2] ? v[2] : reel[0][(r0 + 2)%n[0]] == s[3] ? v[3] : reel[0][(r0 + 2)%n[0]] == s[4] ? v[4] : 0; } if (reel[0][r0] == reel[1][(r1 + 1)%n[1]] && reel[0][r0] == reel[2][(r2 + 2)%n[2]]) { rs += reel[0][r0] == s[0] ? v[0] : reel[0][r0] == s[1] ? v[1] : reel[0][r0] == s[2] ? v[2] : reel[0][r0] == s[3] ? v[3] : reel[0][r0] == s[4] ? v[4] : 0; } if (reel[0][(r0 + 2)%n[0]] == reel[1][(r1 + 1)%n[1]] && reel[0][(r0 + 2)%n[0]] == reel[2][r2]) { rs += reel[0][(r0 + 2)%n[0]] == s[0] ? v[0] : reel[0][(r0 + 2)%n[0]] == s[1] ? v[1] : reel[0][(r0 + 2)%n[0]] == s[2] ? v[2] : reel[0][(r0 + 2)%n[0]] == s[3] ? v[3] : reel[0][(r0 + 2)%n[0]] == s[4] ? v[4] : 0; } rsa += rs ; } WriteLine($@"{rsa/5000000.0} {u[0]} {u[1]} {u[2]} {u[3]} {u[4]}"); } }