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 ans [] = ans
  16. loop ans a' = let x = head a'
  17. in loop (x:ans) $ calc x a'
  18.  
  19. fmt :: [Int] -> [String]
  20. fmt ns = [s1] ++ [s2]
  21. where
  22. s1 = show $ length ns
  23. s2 = unwords $ map show ns
  24.  
  25. calc :: Int -> [Int] -> [Int]
  26. calc x ns = tail $ zipWith (-) ns $ map (*x) m
  27.  
  28. getIntList :: IO [Int]
  29. getIntList = map read . words <$> getLine
Success #stdin #stdout 0.01s 5312KB
stdin
5
1 1 1 0 0 1
stdout
6
0 2 1 -1 0 1