f (x:xs) n =  (foldr1 (.) (replicate x (n :))) (f xs (n + 1))
f [] n = []

g w [] e = []
g w xs e = let row = if e then take w xs else reverse $ take w xs
               in row : g w (drop w xs) (not e)

concatWith ch xs = concat (map (++ ch) xs)
prettyPrint xss = concatWith "\n" $ map (concatWith " " . map show) xss

solver w xs = g w (f xs 1) True

main = do ln1 <- getLine
          ln2 <- getLine
          ln3 <- getLine
          let w = map read (words ln1) !! 1
              xs = map read (words ln3)
              ans = solver w xs
              in putStr (prettyPrint ans)