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
  m = n / 2
  g = 1.upto(m).to_a
  m.times do |i|
    cnt += insertion_sort(array, n, g[i])
  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].join(' ')
puts result[1]
puts result[0]

