{-# LANGUAGE BangPatterns #-}
import Control.Monad (guard)
import Data.List

main :: IO ()
main = mapM_ print . solve . map read . words =<< getContents

solve :: [Int] -> [Int]
solve (n:_:qs) = take n $ (++repeat 0) $ map sum $ transpose $ map (flip replicate 1) $ foldl' f [n] qs'
  where f !xs !x = unfoldr (\(!l, (y:ys)) -> guard (l > 0) *> let !k = min l y in Just (k, (l - k, ys))) (x, cycle xs)
        qs' = let !q = minimum qs in q : reverse (takeWhile (/=q) (reverse qs))
solve _ = undefined
