import Control.Monad (replicateM)
import Control.Monad.State
import Data.List ( iterate
                 , transpose)

main = do
    n <- readLn
    list <- getList n :: IO [Int]
    let gaps = reverse . takeWhile (< length list) . iterate (\i -> 3*i+1) $ 1
        (list', cnt) = runState (shellSortGaps gaps list) 0
    print $ length gaps
    putStrLn $ unwords.map show $ gaps
    print cnt
    printList list'

getList :: (Read a) => Int -> IO [a]
getList n = do
    list <- replicateM n readLn
    return $ reverse list

printList [] = putStr ""
printList (x:xs) = printList xs >> print x

insert :: (Ord a) => a -> [a] -> State Int [a]
insert x [] = return [x]
insert x (y:ys) = if y > x
                     then do
                         modify (+1)
                         ys' <- insert x ys
                         return (y:ys')
                     else do
                         return (x:y:ys)

insertionSort :: (Ord a) => [a] -> State Int [a]
insertionSort []     = return $ []
insertionSort [x]    = return $ [x]
insertionSort (x:xs) = do
    xs' <- insertionSort xs
    insert x xs'

columnize k = transpose.takeWhile (not.null).map (take k).iterate (drop k)

decolumnize = concat . transpose

shellSortPitch :: (Ord a) => Int -> [a] -> State Int [a]
shellSortPitch k xs = do
    let xss = columnize k xs
    xss' <- mapM insertionSort xss
    return $ decolumnize xss'

shellSortGaps :: (Ord a) => [Int] -> [a] -> State Int [a]
shellSortGaps [] xs = return xs
shellSortGaps (g:gs) xs = do
    xs' <- shellSortPitch g xs
    shellSortGaps gs xs'

