• Source
    1. module Main where
    2.  
    3. main :: IO ()
    4. main = do
    5. _ <- getLine
    6. a <- getIntList
    7. mapM_ putStrLn $ solve a
    8.  
    9. m :: [Int]
    10. m = [1, 0, -1, 0] ++ [0, 0 ..]
    11.  
    12. solve :: [Int] -> [String]
    13. solve a = fmt . loop $ reverse a
    14. where
    15. loop a' | length a' <= 4 = calc a'
    16. | otherwise = loop $ calc a'
    17.  
    18. fmt :: [Int] -> [String]
    19. fmt ns | s2 == [] = ["0", "0"]
    20. | otherwise = [s1] ++ [s2]
    21. where
    22. ns' = dropWhile (==0) ns
    23. s1 = show . pred $ length ns'
    24. s2 = unwords . reverse $ map show ns'
    25.  
    26. calc :: [Int] -> [Int]
    27. calc ns = tail $ zipWith (-) ns $ map (* (head ns)) m
    28.  
    29. getIntList :: IO [Int]
    30. getIntList = map read . words <$> getLine