n = gets.to_i items = n.times.map { gets.split.map(&:to_i) } puts items .sort_by { |a, b| -a.to_f / b } .map { |a, b| "#{a} #{b}" }