n = io.read("*n") t = {} k1, k2, k3, k4 = 0, 0, 0, 0 for i = 0, n - 1 do v = io.read("*n") table.insert(t, v) k1 = k1 - i k2 = k2 + i * i k3 = k3 + i * v k4 = k4 + v end -- a = (k1 / k2) * b + (k3 / k2) -- b = (k1 / n) * a + (k4 / n) -- a{1 - (k1/k2)(k1/n)} = (k1/k2)(k4/n) + (k3/k2) a = ((k1/k2)*(k4/n)+(k3/k2))/(1-(k1/k2)*(k1/n)) b = (k1/n)*a+k4/n print(string.format("%.8f %.8f", b, a)) sum = 0 for i = 0, n - 1 do sum = sum + (a * i + b - t[i + 1])^2 end print(sum)