def ternary_search_tree(left, right) loop_cnt = 10000 loop_cnt.times do if yield((left * 2 + right) / 3.0) < yield((left + right * 2) / 3.0) right = (left + right * 2) / 3.0 else left = (left * 2 + right) / 3.0 end end (left + right) / 2.0 end N = gets.to_i A = gets.split.map(&:to_i) B = gets.split.map(&:to_i) def f(x) sum = 0 N.times do |i| sum += B[i] * (x - A[i]).abs end sum end res = ternary_search_tree(-1 * 10 ** 7, 10 ** 7) { |x| f(x) } puts [res, f(res).to_i].join(' ')