import           Data.List
import           Control.Monad.State

sort' :: Ord a => [a] -> State Int [a]
sort' [] = return []
sort' xs = do
  res <- bubleAll xs
  case res of
    (y : ys) -> do
      l <- sort' ys
      return $ y : l
    [] -> return []

bubleAll :: Ord a => [a] -> State Int [a]
bubleAll [] = return []
bubleAll xs =
  foldr (\o acc -> acc >>= buble o) (return xs) [1 .. (length xs - 1)]

buble :: Ord a => Int -> [a] -> State Int [a]
buble n xs
  | x1 <= x2 = return xs
  | otherwise = do
    modify (+ 1)
    return $ h ++ [x2] ++ [x1] ++ t
 where
  x1 = last $ take n xs
  x2 = head $ drop n xs
  h  = take (n - 1) xs
  t  = drop (n + 1) xs

main = do
  n <- readLn
  l <- getLine
  let (rs, cnt) =
        runState (sort' $ take n $ map (read :: String -> Int) (words l)) 0
  putStrLn $ unwords (map show rs)
  print cnt


