import Control.Monad
import Control.Applicative
import Data.Array.ST
import Control.Monad.ST

type IA s = STArray s Int Int

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- getInt
  let (ns, cnt) = solve as
  putStrLn $ init $ concatMap (\i -> show i ++ " ") ns
  print cnt

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

solve :: [Int] -> ([Int], Int)
solve as = runST $ do
  as' <- newListArray (0, n) as :: ST s (IA s)
  cnt <- bsort as' 0
  ans <- getElems as'
  return (ans, cnt)
  where
    n = length as - 1
    swap arr i j = do
      tmp <- readArray arr i
      readArray arr j >>= writeArray arr i 
      writeArray arr j tmp
    bsort :: IA s -> Int -> ST s Int
    bsort arr cnt = do
      fs <- forM [1..n] $ \i -> do
        x <- readArray arr i
        y <- readArray arr (i - 1)
        if x < y then do
          swap arr i (i - 1)
          return 1
          else
          return 0
      let cnt' = sum fs
      if cnt' == 0 then return cnt
        else bsort arr (cnt+cnt')