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