let (cnt: int ref) = ref 0

let insertion_sort (n:int) (gap:int) (a:int array) =
  for i=gap to n-1 do
    let (v:int) = a.(i) in
    let (j:int ref) = ref (i - gap) in
    while !j >= 0 && a.(!j) > v do
      a.(!j+gap) <- a.(!j);
      j := !j - gap;
      incr cnt;
    done;
    a.(!j+gap) <- v
  done

let gen_gaps (n:int) =
  let rec aux (l:int list) = match l with
      [] -> aux [1]
    | h::t when h > n -> t
    | h::_ as l -> aux ((float_of_int h |> ( *. ) 2.25 |> int_of_float) ::l) in
  (if n > 701 then aux [701;301;132;57;23;10;4;1]
   else List.filter ((>=) n) [701;301;132;57;23;10;4;1])
  |> Array.of_list

let shell_sort (array:int array) (n: int) =
  let (g:int array) = gen_gaps n in
  let (m:int) = Array.length g in
  for i=0 to m-1 do
    insertion_sort n g.(i) array;
  done;
  Printf.printf "%d\n" m;
  Array.iteri
    (fun i x -> Printf.printf (if i=m-1 then "%d\n" else "%d ") x)
    g;
  Printf.printf "%d\n" !cnt;
  array

let () =
  let (n:int) = read_int () in
  let (a:int array) = (Array.make n 0) in
  for i=0 to n-1 do
    a.(i) <- (read_int ())
  done;
  Array.iter (Printf.printf "%d\n") (shell_sort a n)