def calc(xs) ys = xs.sort {|a, b| b[0] <=> a[0] || a[1] <=> b[1] } ys.each {|y| puts (y[2] + ?A.ord).chr } end xs = (0..2).map {|i| gets.split.map(&:to_i) + [i] } calc(xs)