import Control.Applicative
import Control.Monad.State
import Data.Array.IO

main = do
  n <- readLn
  list <- map read.words<$>getLine
  newListArray (1,n) list >>= insertionSortA


insertionSortA arr = do
  st <- fst<$>getBounds arr
  runStateT insertSteps (st,arr)

insertSteps :: StateT (Int,IOArray Int Int)  IO (IOArray Int Int)
insertSteps = do
  (i,arr) <- get
  (st, en) <- liftIO $ getBounds arr
  if i > en then return arr
            else do
              e <- liftIO $ readArray arr i
              liftIO $ insertA i arr e
              liftIO $ getElems arr >>= putStrLn.unwords.map show
              put (i+1,arr)
              insertSteps

insertA :: Ord e => Int -> IOArray Int e -> e -> IO ()
insertA i arr e = do
  (st,en) <- getBounds arr
  if i == st then writeArray arr i e
             else do
               e' <- readArray arr (i-1)
               if e' > e then do
                           writeArray arr i e'
                           insertA (i-1) arr e
                         else writeArray arr i e