import Data.List
import Control.Applicative
import Control.Monad
import Control.Monad.Writer
import Data.Monoid

main :: IO ()
main = do
    getLine
    input <- map read . words <$> getContents
    let result = runWriter $ solve input
    putStrLn . intercalate " " . map show $ fst result
    putStrLn . show . getSum $ snd result

-- 与えられたリストに現れる始めのaをbに置換したリストを返す
firstReplace :: Int -> Int -> [Int] -> [Int]
firstReplace a b (x:xs)
    | x == a = b:xs
    | otherwise = x:firstReplace a b xs

solve :: [Int] -> Writer (Sum Int) [Int]
solve [x] = return [x] -- 基底部
solve all@(x:_) = do
    let m = minimum all                       -- 先頭に来るべきもの
    when (m /= x) $ tell (Sum 1)              -- 交換が必要ならカウントする
    xs <- solve . tail $ firstReplace m x all -- tailに対して再帰的に適用する
    return (m:xs)

