module Main where
-- import Debug.Trace
import Data.List
import Data.Char
import Data.Array
import Data.Maybe
import Data.Ord
import Control.Monad

solve :: Int -> [Int] -> [[Int]]
solve n l = iter 0 (0, listArray (0, n-1) l) where
    iter p (c, ar)
        | p >= n    = [elems ar, [c]]
        | otherwise = iter (p+1) (setMin p p) where
            setMin i mi
                | i < n     = setMin (i+1) $ if ar!i < ar!mi then i else mi
                | mi == p   = (c, ar) 
                | otherwise = (c+1, ar // [(p, ar!mi), (mi, ar!p)])

readLine:: IO [Int]
readLine = fmap (map read . words) getLine

main :: IO() 
main = do
    n <- readLn :: IO Int
    l <- readLine
    mapM_ putStrLn $ map (\y -> init (concatMap (\x-> show x ++ " ") y)) (solve n l)

