main :: IO ()
main = do
  _ <- getLine
  as <- fmap (map read . words) getLine :: IO [Int]
  solve as

solve :: [Int] -> IO ()
solve as = bubbleSort [] as 0
  where
    bubbleSort :: [Int] -> [Int] -> Int -> IO()
    bubbleSort sorted (last:[]) n = do
      putStrLn . unwords . map show . reverse $ last:sorted
      print n
    bubbleSort as (b1:b2:bs) i
      | b1 < b2 = bubbleSort (b1:as) (b2:bs) i
      | otherwise = bubbleSort [] (reverse as ++ b2:b1:bs) (i + 1)

