-- | Main entry point to the application.
module Main where
 
import Control.Applicative
import Control.Monad
import Data.List

gcnt cnt a b = if a < b then succ cnt else cnt

inneriter [a,b] rest cnt = (reverse $ min a b:max a b:rest, gcnt cnt a b)
inneriter (a:b:rest) sofar cnt = inneriter (min a b:rest) (max a b:sofar) (gcnt cnt a b)
inneriter a _ cnt = (a, cnt)

iter ns cnt = let (nlist, ncnt) = inneriter ns [] cnt in if ncnt == cnt then (reverse ns, cnt) else iter nlist ncnt

bubbsort ns = iter (reverse ns) 0

-- | The main entry point.
main :: IO ()
main = do
    _ <- getLine
    ns <- concatMap (fmap (read :: String -> Int) . words) . lines <$> getContents
    let (sortedlist, count) = bubbsort ns
    putStrLn $ unwords $ map show sortedlist
    print count