import Control.Applicative
import Data.List

bubbleSort :: [Int] -> ([Int], Int)
bubbleSort xs = loop (False, xs, 0) (tails [0 .. length xs - 2])
  where
    loop (_, xs, c) [[]] = (xs, c)
    loop (flag, xs, c) (ys : yss)
      | flag      = (xs, c)
      | otherwise = loop (foldr f (flag, xs, c) ys) yss

    f i (flag, xs, c) = if a > b
      then (flag && False, (as ++ b : a : bs), c + 1)
      else (flag || True,  (as ++ a : b : bs), c)
      where (as, a : b : bs) = splitAt i xs

main :: IO ()
main = do
  _  <- getLine
  xs <- map read . words <$> getLine
  let (list, count) = bubbleSort xs
  putStrLn $ unwords $ map show list
  print count

