def ternary_search_tree(left, right) loop_cnt = 40 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 N = gets.to_i A = gets.split.map(&:to_i) B = gets.split.map(&:to_i) C = A.zip(B) def f(x) C.sum { |a, b| b * (x - a).abs } end res = ternary_search_tree(-1 * 10 ** 6, 10 ** 6) { |x| f(x) } puts [res, f(res).to_i].join(' ')