import Control.Monad
import Control.Applicative
import Data.List

main = do
  n <- readLn :: IO Int
  xs <- map read . words <$> getLine :: IO [Int]
  mapM_ putStrLn $ solve xs

solve :: [Int] -> [String]
solve xs = [intercalate " " (map show ys),show c]
  where
    (c,ys) = bsort (0,xs)

bsort :: (Ord a) => (Int, [a]) -> (Int, [a])
bsort (c, []) = (c,[])
bsort (c, xs) = (nnc, y : zs)
  where
    (nnc, zs) = bsort (nc, ys)
    (nc, (y:ys)) = bsort' (c, xs)

bsort' :: (Ord a) => (Int,[a]) -> (Int,[a])
bsort' (c,[x]) = (c,[x])
bsort' (c,(x:xs))
  | x < y = (nc,x:y:ys)
  | otherwise = (nc+1,y:x:ys)
  where
    (nc,(y:ys)) = bsort' (c,xs)