let cnt = ref 0

let insertion_sort n ?(gap=1) v =
  let rec insert v = function
      i when i < gap -> v
    | i ->
      let j = i-gap in
      let vi,vj = v.(i),v.(j) in
      if vj <= vi then v
      else (v.(i) <- vj; v.(j) <- vi;incr cnt; insert v j)
  in
  let rec loop v i =
    if i >= n then v
    else loop (insert v i) (i+gap)
  in loop v 0

let shell_sort array n =
  let gaps = [701;201;132;57;23;10;4;1] |> List.filter ((>) n) in
  let m = List.length gaps in
  let rec loop a = function
      [] -> a
    | h::t -> loop (insertion_sort n ~gap:h a) t in
  let a = loop array gaps in
  Printf.printf "%d\n" m;
  Array.iteri
    (fun i x -> Printf.printf (if i=m-1 then "%d\n" else "%d ") x)
    (Array.of_list gaps);
  Printf.printf "%d\n" !cnt;
  a

let () =
  let n = read_int () in
  let rec read a = function
      i when i = n -> a
    | i -> a.(i) <- (read_int ());
      read a (i+1) in
  let a = read (Array.make n 0) 0 in
  Array.iter (Printf.printf "%d\n") (shell_sort a n)