import Control.Applicative

bubble :: [Int] -> ([Int], Int, Bool)
bubble []         = ([],  0, False)
bubble (x:[])     = ([x], 0, False)
bubble (x1:x2:xs) =
    let (ys, c, flag) = if x1 > x2
                           then bubble (x1:xs)
                           else bubble (x2:xs)
    in if x1 > x2
          then (x2:ys, c+1, True)
          else (x1:ys, c,   flag)

bubbleSort :: Int -> [Int] -> (Int, [Int])
bubbleSort n nums =
    let (sorted, c, flag) = bubble nums
    in if flag
          then bubbleSort (n + c) sorted
          else (n, sorted)

main :: IO ()
main = do
    getLine
    nums <- map read . words <$> getLine :: IO [Int]
    let (count, sorted) = bubbleSort 0 nums
    putStrLn $ unwords (show <$> sorted)
    print count

