sc = 5.times.map{s, c = gets.split [s, c.to_i] } A, B, C = 3.times.map{ gets.to_i.times.map{ gets.chomp } } comb = A.size * B.size * C.size u = [] p sc.map{|s,c| n = A.count(s) * B.count(s) * C.count(s) u << n * 5 n * 5 * c }.sum.fdiv comb p *u