R,G,B = Array.new(3) {gets.chomp} RS = (R == "NONE" ? [] : R.split(",")) GS = (G == "NONE" ? [] : G.split(",")) BS = (B == "NONE" ? [] : B.split(",")) ALL = %w(0 1 2 3 4 5 6 7 8 9 A B C D E F).repeated_permutation(2) puts [RS, GS, BS].map {|negative| ALL.filter{|part| negative.none?{|ng| part.include?(ng)}}.size}.inject(:*)