def insertion_sort(array, num, interval)
  cnt = 0

  (interval).upto(num-1) do |i|
    v = array[i]
    j = i - interval
    while (j >= 0 && array[j] > v) do
      array[j+interval] = array[j]
      j -= interval 
      cnt += 1
    end
    array[j+interval] = v
  end

  return cnt
end

def shell_sort(array, num)
  cnt = 0
  intervals = [1]
  interval = 1
  
  (Math.log2(num).floor.to_i - 1).times do |i|
    interval *= 2
    intervals << interval
  end

  puts intervals.size
  puts (intervals.reverse.join(' '))

  intervals.reverse.each do |i|
    cnt += insertion_sort(array, num, i)
  end

  puts cnt
end

num = gets.strip.to_i
array = []
(num).times do |n|
  array << gets.strip.to_i
end

shell_sort(array, num)
array.each{|i| puts i}