ha, wa = gets.chomp.split.map &:to_i hb, wb = gets.chomp.split.map &:to_i hc, wc = gets.chomp.split.map &:to_i a = {"h"=>ha, "w"=>wa, "name"=>"A"} b = {"h"=>hb, "w"=>wb, "name"=>"B"} c = {"h"=>hc, "w"=>wc, "name"=>"C"} brothers = [a, b, c] puts brothers.sort{|x, y| if x["h"] == y["h"] x["w"] <=> y["w"] else y["h"] <=> x["h"] end }.map{|z| z["name"] }.join("\n")