list = Array.new 3.times{list << gets.chomp.split(" ").map(&:to_i)} heights = {"A" => list[0], "B" => list[1], "C" => list[2]} list.sort!{|a, b| a[1] <=> b[1]} list.sort!{|a, b| b[0] <=> a[0]} list.each{|val| puts heights.key(val)}