import Data.List

snd' :: ([Int], [Int], [Int]) -> Int -> ([Int], Int)
snd' (l, [a,b], []) n	
  | a >	b = (l ++ [b], n+1)
  | otherwise =	(l ++ [a], n)
snd' (l, [a,b], r) n
  | a > b = snd' (l++[b], [a, head r], tail r) (n + 1)
  | otherwise = snd' (l++[a], [b, head r], tail r) n

fst' ::	([Int], Int) ->	Int
fst' (x:[], n) = n
fst' (x:y:xs, n) = fst' (snd' ([], [x,y], xs) n)

main = do
  list <- fmap (tail . map read . words) getContents
  putStrLn $ unwords $ map show $ sort $ list
  print $ fst' (list, 0)