def insertion_sort arr, gap
    [*1...arr.length].each do |i|
        v = arr[i]
        j = i - gap
        while (j >= 0) && (v < arr[j])
            arr[j + gap] = arr[j]
            j -= gap
            @cnt += 1
        end
        arr[j + gap] = v
    end
    arr
end

def shell_sort arr
    # 間隔：gaps = [1, 4, 13, 40, 121, 364, 1093, ... ] (gaps[i] = gaps[i-1] * 3 + 1)
    @cnt = 0; gap = 1; gaps = []
    while gap <= arr.length
        gaps << gap
        gap = gap * 3 + 1
    end

    # 間隔指定のinsertion_sortを繰り返す
    gaps.reverse.reduce arr do |acc, gap|
        insertion_sort acc, gap
    end

    # 解答の出力
    puts gaps.length
    puts gaps.reverse.join(' ')
    puts @cnt
    puts arr
end

#-- main
arr = []
gets.to_i.times { arr << gets.to_i }
shell_sort arr
