import Control.Applicative
import Control.Monad.State
import Data.Array.IO

main = do
  n <- readLn
  list <- map read.words<$>getLine
  list <- newListArray (1,n) list
  (arr,i) <- bubbleSort list
  getElems arr >>= putStrLn.unwords.map show
  print i


bubbleSort :: IOArray Int Int -> IO (IOArray Int Int, Int)
bubbleSort arr = runStateT (bubble' arr True) 0

bubble' :: IOArray Int Int -> Bool -> StateT Int IO (IOArray Int Int)
bubble' arr False = return arr
bubble' arr True  = do
  (st, en) <- liftIO $ getBounds arr
  bs <- forM [st..(en-1)] $ \i -> do
    ei <- liftIO $ readArray arr i
    ei' <- liftIO $ readArray arr (i+1)
    if ei <= ei' then return False
                 else do
                   liftIO $ writeArray arr i ei'
                   liftIO $ writeArray arr (i+1) ei
                   modify (+1)
                   return True
  bubble' arr (any id bs)