import Data.Functor( (<$>))

main = do
    getLine
    values <- (read <$>) . words <$> getLine	::IO [Int]
    let
	bubbleSort (list,count)
	  = let
	    v@(scanResult, swapCount) = bubbleScan (reverse list) [] count
	      where
		bubbleScan [x] l count	    = (x:l, count)
		bubbleScan (x1:x2:xs) l count
		  |  x1 < x2		= bubbleScan (x1:xs) (x2:l) (count+1)
		  | otherwise		= bubbleScan (x2:xs) (x1:l) count
	  in
	    if count == swapCount
	    then v
	    else bubbleSort v

	(sorted, numSwap)  = bubbleSort (values, 0)

    putStrLn . unwords $ show <$> sorted
    print numSwap

