import Data.Array
import Data.Array.ST
import Data.STRef
import Control.Monad.ST
import Control.Monad

--境界(s,e)、アレイ(s~e)、ソート済み前半部分の先頭インデックス(s-1~e)
insert::(Int,Int)->STArray s Int Int -> Int ->ST s ()
insert (s,e) ar idx= if idx == e then return () else do
   v<-readArray ar (idx+1)
   counter<-newSTRef (idx+1)
   whileM_ [idx-j |j<-[0..(idx-s)]] (\ i -> do
                                        a<-readArray ar i
                                        return (a>v))
                                    (\ i -> do
                                        a<-readArray ar i
                                        writeArray ar (i+1) a
                                        writeSTRef counter i)
   i<-readSTRef counter
   writeArray ar i v
   return ()

whileM::Monad m => [a]->(a->m Bool)->(a->m b)->m [b]
whileM []     cond proc  = return []
whileM (x:xs) cond proc  = do
  b<- cond x
  if b then do
    a<- proc x
    rest<-whileM xs cond proc
    return (a:rest)
       else return []

whileM_::Monad m => [a]->(a->m Bool)->(a-> m())->m ()
whileM_ []     cond proc = return ()
whileM_ (x:xs) cond proc = do
  b<-cond x
  if b then do
    proc x
    whileM_ xs cond proc
       else return ()

insertion_sort::(Int,Int) -> STArray s Int Int -> ST s ()
insertion_sort (s,e) ar = do
  forM_ [s..e] (insert (s,e) ar)

ins_sort::Array Int Int -> Array Int Int
ins_sort ar = runSTArray $ do
  let (s,e) =bounds ar
  mar<-thaw ar
  insertion_sort (s,e) mar
  return mar

ins_trace::Array Int Int -> [[Int]]
ins_trace ar = runST $ do
  let (s,e) = bounds ar
  mar<-thaw ar
  trace <- forM [s..e] (\ i -> do
                     insert (s,e) mar i
                     frz <- freeze mar
                     return (elems frz))
  return trace

main::IO()
main=do
  nc<-getLine
  let n = read nc
  ls<-getLine
  let ar = listArray (1,n) (map read (words ls))
  lss_print ((elems ar):init (ins_trace ar))


lss_print::[[Int]]->IO()
lss_print []     = return ()
lss_print (x:xs) = do
  putStr ((ls_show x)++"\n")
  lss_print xs

ls_show::[Int]->String
ls_show [] = " "
ls_show (x:xs) = (show x)++(' ':(ls_show xs))
