import           Control.Applicative
import           Control.Monad
import           Data.IORef

while :: IO Bool -> IO () -> IO ()
while condIO exe = do
  cond <- condIO
  when cond $ do
    exe
    while condIO exe

setNth :: IORef [a] -> (Int, a) -> IO ()
setNth listRef (idx, newV)= do
  list <- readIORef listRef
  writeIORef listRef (list `set` (idx, newV))
  where
    set :: [a] -> (Int, a) -> [a]
    set []     _      = []
    set (x:xs) (0, v) = v:xs
    set (x:xs) (n, v) = x : xs `set` (n-1, v)

printList :: Show a => [a] -> IO ()
printList a = putStrLn $ unwords . map show $ a

main :: IO ()
main = do
  _ <- getLine
  a <- map read . words <$> getLine

  aRef <- newIORef a
  vRef <- newIORef (undefined :: Int)
  jRef <- newIORef (undefined :: Int)
  a <- readIORef aRef


  forM_ [1.. length a-1] $ \i -> do
    a <- readIORef aRef
    printList a
    writeIORef vRef (a !! i)
    writeIORef jRef (i-1)
    while (do
      j <- readIORef jRef
      a <- readIORef aRef
      v <- readIORef vRef
      return $ j >= 0 && (a !! j) > v) $ do

        j <- readIORef jRef
        a <- readIORef aRef
        aRef `setNth` (j+1, a !! j)
        modifyIORef jRef pred

    j <- readIORef jRef
    v <- readIORef vRef
    aRef `setNth` (j+1, v)
    return ()

  a <- readIORef aRef
  printList a

  return ()