import Control.Applicative

bubbleSort :: [Int] -> (Int ,[Int])
bubbleSort xs = loop (1, 0, xs)
  where
    n = length xs - 2
    loop (0, m, xs) = (m, xs)
    loop (1, m, xs) = loop $ foldr f (0, m, xs) [0 .. n]
    f i  (f, m, xs) = if b > c
                      then (1, m + 1, (as ++ c : b : ds))
                      else (f, m, as ++ bs)
      where (as, bs@(b : c : ds)) = splitAt i xs

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

