def insert_sort(a, n, g)
  cnt = 0
  g.upto(n-1){|i|
    v = a[i]
    j = i - g
    while j >= 0 && a[j] > v
      a[j+g] = a[j]
      j = j - g
      cnt += 1
    end
    a[j+g] = v
  }
  cnt
end

def shell_sort(a, n)
  cnt = 0
  g = []
  h = 1
  loop do
    break if h > n
    g.unshift(h)
    h = h * 3 + 1
  end
  p g.size
  puts g*" "
  g.size.times{|i|
    cnt += insert_sort(a, n, g[i])
  }
  p cnt
end

n=gets.to_i
a=$<.read.split.map &:to_i

shell_sort(a, n)
puts a

