def ascan; gets.split.map(&:to_f); end def trisearch(left, right, equal = nil, &block) 100.times { l = right - (2 * right - 2 * left) / 3.0 r = right - (right - left) / 3.0 lval = block.call(l) rval = block.call(r) if (lval <= rval) right = r else left = l end return left if (left == right) } return left end N = gets.to_i A = ascan b = 0 d = 0 100.times do b = trisearch(0.0,1e5){|x| N.times.map{|i| (A[i]-(x+d*i))**2}.reduce(:+)} d = trisearch(-1e5,1e5){|x| N.times.map{|i| (A[i]-(b+x*i))**2}.reduce(:+)} end puts "#{b} #{d}" p N.times.map{|i| (A[i]-(b+d*i))**2}.reduce(:+)