import Control.Applicative import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.List import Data.Char (isSpace) main :: IO () main = solve <$> readLn <*> f >>= prt where f = readil B.readInt <$> B.getLine solve :: Int -> [Int] -> (Double, Double, Double) solve n as = (b, a, c) where xb = fromIntegral (n - 1) / 2.0 yb = fromIntegral (sum as) / fromIntegral n dxs = map (\x -> fromIntegral x - xb) [0 .. n-1] dys = map (\y -> fromIntegral y - yb) as a = (sum $ zipWith (*) dxs dys) / (sum $ map (^2) dxs) b = yb - a * xb f x = a * x + b c = sum $ map (^2) $ zipWith (\u v -> u - fromIntegral v) (map (\x -> f (fromIntegral x)) [0 .. n-1]) as prt :: (Double, Double, Double) -> IO () prt (a, b, c) = do putStrLn $ show a ++ " " ++ show b print c readil :: Integral a => (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a] readil f = unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s')