{-# LANGUAGE BangPatterns #-}
module Main where

import Control.Arrow
import Data.Bool
import Data.Functor
import Data.List

main :: IO ()
main = do
  { [n] <- getInts
  ; xs  <- getInts
  ; case selectionSort xs of
      (c,ys) -> do
        { putInts ys
        ; putInts [c]
        }
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

selectionSort :: Ord a => [a] -> (Int,[a])
selectionSort []  = (0,[])
selectionSort xs  = first sum $ unzip $ unfoldr phi xs
  where
    phi []         = Nothing
    phi xxs@(x:xs) = case break (minx ==) xxs of
      ([],_)      -> Just ((0,x),xs)
      (y:ys,z:zs) -> Just ((1,z),ys++y:zs)
      where
        minx = minimum xxs