A = Array.new(3){Array.new(5, 0)} Z = Array.new(3) H = {} F = 5.times.map do |i| face, pay = gets.split H[face] = i [face, pay.to_i] end R = 3.times.map do |i| n = gets.to_i Z[i] = n n.times do j = H[gets.chomp] A[i][j] += 1 end end T = Z.inject(&:*) ANS2 = 5.times.map do |i| pay = F[i][1] A[0][i] * A[1][i] * A[2][i] * 5 end ANS1 = ANS2.each_with_index.inject(0.0){|s,(v,i)| s + F[i][1] * v } / T puts ANS1 puts ANS2