def insertion_sort(array, n, g)
  cnt = 0
  g.upto n - 1 do |i|
    v = array[i]
    j = i - g
    while j >= 0 && array[j] > v
      array[j + g] = array[j]
      j -= g
      cnt += 1
    end
    array[j + g] = v
  end
  cnt
end

def shell_sort(array, n)
  cnt = 0
  g = [1]
  g << 3 * g[-1] + 1 until 3 * g[-1] + 1 > n
  m = g.length
  g.reverse_each do |value|
    cnt += insertion_sort(array, n, value)
  end
  [array, cnt, m, g]
end

n = gets.to_i
array = []
n.times do
  array << gets.to_i
end

result = shell_sort array, n

puts result[2]
puts result[3].reverse.join(' ')
puts result[1]
puts result[0]

