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

main = do
        n <- readLn
        nums <- map read.words<$>getLine
        arr <- newListArray (0,(n-1)) nums :: IO (IOArray Int Int)
        (arr, s) <- selectionSortCounted n arr
        getElems arr >>= putStrLn.unwords.map show
        print s

selectionSortCounted :: Int -> IOArray Int Int -> IO (IOArray Int Int, Int)
selectionSortCounted n arr = do
        swapped <- execStateT (countSwap 0) 0
        return (arr, swapped)
        where
            countSwap :: Int -> StateT Int IO ()
            countSwap i = if i >= n then return ()
                                    else do
                                        pos <- liftIO $ searchMinPos i n arr
                                        liftIO $ swap arr i pos
                                        if pos == i then countSwap (i+1)
                                                    else modify (+1) >> countSwap (i+1)

selectionSort n arr = do
        forM_ [0..(n-1)] $ \i ->do
            pos <- searchMinPos i n arr
            swap arr i pos
        return arr

swap arr x y = do
        v <- readArray arr x
        readArray arr y >>= writeArray arr x
        writeArray arr y v

searchMinPos :: Int -> Int -> IOArray Int Int -> IO Int
searchMinPos j n arr = evalStateT (func j) j
    where
        func :: Int -> StateT Int IO Int
        func count = if count >= n then get >>= return
                                   else do
                                       minj <- get
                                       ej <- liftIO $ readArray arr count
                                       eminj <- liftIO $ readArray arr minj
                                       if ej < eminj then put count >> func (count+1)
                                                     else func (count+1)