class Main Brother = Struct.new(:i, :h, :w) def start brothers = input_term brothers = sort_term(brothers) echo brothers.map { |x| x.i }.join("\n") self.class.send(:remove_const, :Brother) return nil end private def sort_term(brothers) brothers.sort_by! { |x| x.w }.reverse! i = 0 brothers.sort_by! { |x| [-x.h, i += 1] }.reverse! brothers end def input_term a = [] for i in 0...3 h, w = input.split brother = Brother.new(("A".ord + i).chr, h, w) a += [brother] end return a end def echo(*x) print(*x) puts end def input = gets.chomp end Main.new.start