use std::env;
use std::io;
use std::io::prelude::*;

//===================================================
// MACROs need to be defined above the use place ... ?
macro_rules! dprintln {
    ($($x:expr),*) => {{
        if $crate::is_debug_mode() {
            let f = || {println!( $($x),*)};
            f()
        }
    }}
}

/// Backward For-Loop Helper
///  from -> to (exclude `to`)
///
/// # Examples
/// see tests::macro_backward()
///
#[macro_export]
macro_rules! backward_ho {
    ($from:expr, $to:expr) => {{
        (($to + 1)..($from + 1)).rev()
    }};
}
//===================================================

fn main() {
    // Initialize
    set_debug_mode(false);
    for arg in env::args() {
        if arg == "--debug" {
            set_debug_mode(true);
        }
    }
    dprintln!("[DebugMode] {}", "On");

    // Execute
    dprintln!("=================");
    dprintln!("= READ INPUT     ");
    let stdin = io::stdin();
    let input = Input::new(stdin.lock());
    dprintln!("[Input] \n{:?}", input);
    dprintln!("=================");
    dprintln!("= INTERPRET INPUT");
    let q = input.into_quiz();
    dprintln!("[Quiz] \n{:?}", q);
    dprintln!("=================");
    dprintln!("= SOLVE QUIZE    ");
    let a = q.solve();
    dprintln!("[Answer] \n{:?}", a);
    dprintln!("=================");
    dprintln!("= PRINT ANSWER   ");
    a.print();
    dprintln!("=================");
}

#[derive(Debug)]
struct Quiz {
    n: usize,    // 1 <= n <= 1,000,000
    v: Vec<u32>, // 0 <= v[i] <= 10^9, length=N
}

#[derive(Debug)]
struct Answer {
    m: usize,
    g: Vec<usize>,
    cnt: u32,
    v: Vec<u32>,
}

impl Input {
    fn into_quiz(mut self) -> Quiz {
        let n: usize = self.parse_next().unwrap();
        let v: Vec<u32> = self.parse_next_vec(n).unwrap();
        Quiz { n, v }
    }
}

impl Quiz {
    fn solve(self) -> Answer {
        let f = |i| (3usize.pow(i) -1) /2;
        let mut gs = Vec::new();
        let mut i = 1;
        let mut gi = f(i);
        while gi < self.n {
            gs.push( gi );
            i += 1;
            gi = f(i);
        }
        gs.reverse();
        if gs.len() <= 0 { // UGH 
            gs.push( 1 );
        }
        let m = gs.len();
        dprintln!("gs: {:?}", gs);

        let (v, cnt) = Quiz::shell_sort(&self.v, self.v.len(), &gs, m);

        Answer {
            m : m,
            g : gs,
            cnt : cnt,
            v : v,
        }
    }

    fn shell_sort(v: &Vec<u32>, length: usize, gs: &Vec<usize>, m: usize) -> (Vec<u32>, u32) {
        let mut cnt = 0;

        let mut vv = v.to_vec();
        for i in 0usize..(m as usize) {
            let (v_i, cnt_i) = Quiz::insertion_sort(&vv, length, gs[i]);
            vv = v_i;
            cnt += cnt_i;
        }

        (vv, cnt)
    }

    fn insertion_sort(v: &Vec<u32>, length: usize, g: usize) -> (Vec<u32>, u32) {
        let mut cnt = 0;
        let mut v = v.to_vec();
        let length = length;

        dprintln!("insertion_sort by g={}", g);

        let mut i = g;
        while i < length {
            let key = v[i].clone();
            dprintln!(" v:{:?}", v);
            dprintln!(" i {}, v[{}] = {}", i, i, key);
            let mut j: i32 = (i - g) as i32;
            while j >= 0 && v[j as usize] > key {
                dprintln!("  v[{}] > key, swap", j);
                let jj = j as usize; // j>=0
                v[jj + g] = v[jj];
                j = j - g as i32;
                cnt += 1;
            }
            let j_plus_g = (j + g as i32) as usize;
            dprintln!("  v[{}] <- {}", j_plus_g, key);
            dprintln!("    swap_cnt {}", cnt);
            v[j_plus_g] = key;
            i += 1; 
        }

        dprintln!(" result v: {:?}, cnt:{}", v, cnt);

        (v, cnt)
    }
}

impl Answer {
    fn print(self) {
        println!("{}", self.m);
        println!("{}", concat_vec_to_string(&self.g));
        println!("{}", self.cnt);
        for e in self.v {
            println!("{}", e);
        }
    }
}

// =====================================================
// =
// =====================================================

//==================================================
// Stdin Reader
#[derive(Debug)]
pub enum Token {
    Word(String),
    LineBreak,
}

impl Token {
    pub fn is_word(&self) -> bool {
        match *self {
            Token::Word(ref _x) => true,
            _ => false,
        }
    }
}

#[derive(Debug)]
pub struct Input {
    tokens: Vec<Token>,
}

impl Input {
    pub fn new<T: BufRead>(input: T) -> Self {
        let lines = input.lines();
        let words = lines.flat_map(|l| tokenaize(l.unwrap()));
        let mut words = words.collect::<Vec<_>>();

        words.reverse();

        Input { tokens: words }
    }

    pub fn read_next_word(&mut self) -> Option<Token> {
        loop {
            match self.tokens.pop() {
                Some(Token::LineBreak) => (),
                x => return x,
            }
        }
    }

    pub fn parse_next<T>(&mut self) -> Option<T>
    where
        T: std::str::FromStr,
    {
        if let Some(Token::Word(str)) = self.read_next_word() {
            match str.parse() {
                Ok(x) => Some(x),
                _ => None,
            }
        } else {
            None
        }
    }

    pub fn parse_next_vec<T>(&mut self, size: usize) -> Option<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::new();

        for _i in 0..size {
            if let Some(t) = self.parse_next() {
                v.push(t);
            } else {
                return None;
            }
        }

        Some(v)
    }

    pub fn parse_next_vec2<T>(&mut self, size2: usize, size1: usize) -> Option<Vec<Vec<T>>>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::new();

        for _i in 0..size2 {
            if let Some(t) = self.parse_next_vec(size1) {
                v.push(t);
            } else {
                return None;
            }
        }

        Some(v)
    }
}

fn tokenaize(str: String) -> Vec<Token> {
    let mut v = Vec::new();

    for w in str.split_whitespace() {
        v.push(Token::Word(w.to_string()));
    }
    v.push(Token::LineBreak);
    v
}

//==================================================
// Utility Functions
pub fn concat_vec_to_string<T>(v: &Vec<T>) -> String
where
    T: std::fmt::Display,
{
    let mut string = String::new();

    if let Some((h, t)) = v.split_first() {
        string = h.to_string();

        for obj in t {
            string = format!("{} {}", string, obj);
        }
    }

    return string;
}

//==================================================
// Debug Switch
static mut S_DEBUG_MODE: bool = false;
fn is_debug_mode() -> bool {
    unsafe { S_DEBUG_MODE }
}

fn set_debug_mode(mode: bool) {
    unsafe {
        S_DEBUG_MODE = mode;
    }
}

//==================================================
// Usage
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn macro_backward() {
        let mut v = Vec::new();
        for i in backward_ho!(5, 1) {
            v.push(i);
        }
        assert_eq!(vec![5, 4, 3, 2], v);
    }
}



Measured memory_bytes: 68512