using System;
using System.Collections.Generic;

namespace ALDS1_2_D
{
    public enum SortMethod
    {
        Bubble,
        Selection,
        Insertion,
        Shell
    }
    public static class Algorithm
    {
        public static long InsertionCount { get; private set; }
        public static void Sort<T>(this T[] array, SortMethod method) where T : IComparable<T>
        {
            InsertionCount = 0;
            switch (method)
            {
                case SortMethod.Bubble: BubbleSort(array); break;
                case SortMethod.Selection: SelectionSort(array); break;
                case SortMethod.Insertion: InsertionSort(array); break;
                case SortMethod.Shell: ShellSort(array); break;
            }
        }

        private static void BubbleSort<T>(T[] array) where T : IComparable<T>
        {
            var n = array.Length;
            for (int i = 0; i < n; i++)
            {
                for (int j = n - 1; j > i; j--)
                {
                    if (array[j - 1].CompareTo(array[j]) > 0)
                    {
                        var temp = array[j];
                        array[j] = array[j - 1];
                        array[j - 1] = temp;
                    }
                }
            }
        }
        private static void SelectionSort<T>(T[] array) where T : IComparable<T>
        {
            var n = array.Length;
            for (int i = 0; i < n - 1; i++)
            {
                int min = i;
                for (int j = i + 1; j < n; j++) if (array[min].CompareTo(array[j]) > 0) min = j;
                if (min != i)
                {
                    var temp = array[i];
                    array[i] = array[min];
                    array[min] = temp;
                }
            }
        }

        private static void InsertionSort<T>(T[] array, int step = 1) where T : IComparable<T>
        {
            var n = array.Length;
            for (int k = 0; k < step; k++)
            {
                for (int i = k + step; i < n; i += step)
                {
                    var key = array[i];
                    var j = i - step;
                    while (j >= 0 && array[j].CompareTo(key) == 1)
                    {
                        array[j + step] = array[j];
                        j -= step;
                        InsertionCount++;
                    }
                    array[j + step] = key;
                }
            }
        }

        private static void ShellSort<T>(T[] array, int step = 1) where T : IComparable<T>
        {
            var n = array.Length;
            n++;
            while (n / 2 > 0)
            {
                InsertionSort(array, n /= 2);
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var array = new int[n];
            for (int i = 0; i < n; i++) array[i] = int.Parse(Console.ReadLine());
            var g = new List<int>();
            n++;
            while (n / 2 > 0)
            { 
                g.Add(n /= 2);
            }
            Console.WriteLine(g.Count);
            for (int i = 0; i < g.Count - 1; i++) Console.Write(g[i] + " ");
            Console.WriteLine(g[g.Count - 1]);
            Algorithm.Sort(array, SortMethod.Shell);
            Console.WriteLine(Algorithm.InsertionCount);
            for (int i = 0; i < array.Length; i++) Console.WriteLine(array[i]);
        }
    }
}

Measured memory_bytes: 16740