import Control.Monad import Data.List (sort) main :: IO () main = do [h, w] <- f replicateM h f >>= solve w where f = map read <$> words <$> getLine solve :: Int -> [[Int]] -> IO () solve w ass = f as where as = sort $ concat ass f xs = do case xs of [] -> return () _ -> do putStrLn $ unwords $ map show $ take w xs f (drop w xs)