import Control.Monad
import Control.Applicative
import Debug.Trace

main :: IO ()
main = do
  n <- readLn :: IO Int
  ns <- getInts
  let (ls, c) = solve ns
  putStrLn $ unwords $ map show ls
  print c

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

solve :: [Int] -> ([Int], Int)
solve xs = go xs 1 
  where
    n = length xs
    go ns i
      | i == n = (ns, 0)
      | otherwise =
      let (m, idx) = minimum $ zip ns [0..]
          (ls, _:rs) = splitAt idx ns
          cnt' = if idx /= 0 then 1 else 0
          x = head ns
          ls' = if x == m then [] else tail ls ++ [x]
          (r, c) = --trace (show (m, idx)) $
            go (ls' ++ rs) (i+1) in
        (m:r, c+cnt')
        