fork download
  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. s1 = show . pred $ length s2
  23. s2 = unwords . reverse . map show $ dropWhile (==0) ns
  24.  
  25. calc :: [Int] -> [Int]
  26. calc ns = tail $ zipWith (-) ns $ map (* (head ns)) m
  27.  
  28. getIntList :: IO [Int]
  29. getIntList = map read . words <$> getLine
Success #stdin #stdout 0.01s 5280KB
stdin
8
0 -5 0 4 0 1 -1 0 1
stdout
0
0