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

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

let generate_g n =
  let new_g = ref 1 in
  incr n_g;
  while !new_g <= n do
    g := !new_g :: !g;
    new_g := int_of_float (4.**(float_of_int !n_g) +. 3.*.2.**(float_of_int (!n_g - 1)) +. 1.);
    incr n_g;
  done

let shell_sort (a : int array) n =
  cnt := 0;
  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" !n_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