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 $ max 0 c

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

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