N = gets.to_i Q = N.times.map { gets.split.map(&:to_i) } def ternary_search_tree(left, right) loop_cnt = 10000 loop_cnt.times do if yield((left * 2 + right) / 3) <= yield((left + right * 2) / 3) right = (left + right * 2) / 3 else left = (left * 2 + right) / 3 end end (left + right) / 2 end t = ternary_search_tree(1, 10 ** 10) { |x| u, v = Q.map { |a, b| a + b * x }.minmax v - u } pp t