import Data.List import Data.Ord import System.IO replace i xs = xs1 ++ (x':x:xs2) where (xs1,(x:x':xs2)) = splitAt i xs main = do getLine as <- map read . words <$> getLine let output = nmk as print (length output) mapM_ (putStrLn . unwords . map show) output hFlush stdout getLine nmk :: [Int] -> [[Int]] nmk xs = nmk' [] xs where nmk' acc xs' | sort xs' == xs' = acc | otherwise = let i = ikado (zip [0..] xs') in nmk' ([i,i+1]:acc) (replace i xs') ikado ixs = fst $ fst $ head $ filter (\(ix1,ix2) -> snd ix1 > snd ix2) $ zip ixs (tail ixs)