{- PSEUDOCODE:
for i = 1 to A.length-1
    key = A[i]
    /* insert A[i] into the sorted sequence A[0,...,j-1] */
    j = i - 1
    while j >= 0 and A[j] > key
        A[j+1] = A[j]
        j--
    A[j+1] = key
-}

main = do
    fs <- getLine
    ss <- getLine
    let a = map (\x -> read x :: Int) $ words ss
    doFor a 1

doFor :: [Int] -> Int -> IO ()
doFor a i = do
    putStrLn $ unwords $ map show a
    if i > (length a - 1)
        then return ()
        else do
            let key = a!!i
            let j = i-1
            let na = doWhile a j key
            doFor na (i+1)

doWhile :: [Int] -> Int -> Int -> [Int]
doWhile a j key
  | j >= 0 && a!!j > key = doWhile (replace a (j+1) (a!!j)) (j-1) key
  | otherwise = replace a (j+1) key

replace :: [Int] -> Int -> Int -> [Int]
replace a idx v = (take idx a) ++ [v] ++ (drop (idx+1) a)

