let cnt = ref 0
let (g : int list ref) = ref []

let insertion_sort (a : int array) n g =
  let rec insert j v =
    if j < 0 || a.(j) <= v then a.(j+g) <- v
    else begin
      a.(j+g) <- a.(j);
      incr cnt;
      insert (j - g) v
    end in
  let rec doit i =
    if i < n then begin
      insert (i - g) a.(i);
      doit (i + 1)
    end in
  doit g

let generate_g n =
  let rec doit i g acc =
    if g > n then acc
    else doit (i + 1) (int_of_float (4.**(float_of_int i) +. 3.*.2.**(float_of_int (i - 1)) +. 1.)) (g :: acc) in
  doit 1 1 []

let shell_sort (a : int array) n =
  cnt := 0;
  g := generate_g n;
  List.iter (fun g -> insertion_sort a n g) !g

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> read_int ()) in
  shell_sort a n;
  Printf.printf "%d\n" (List.length !g);
  List.iteri (fun i n -> if i <> 0 then print_string " "; print_int n) !g;
  print_newline ();
  Printf.printf "%d\n" !cnt;
  Array.iter (fun n -> Printf.printf "%d\n" n) a