from sys import stdin
def stdinput():
    return stdin.readline().strip()

def main():
    n = int(stdinput())
    A = list(map(int, [stdinput() for _ in range(n)]))

    A, c, G = shell_sort(A, len(A))

    print(len(G))
    print(' '.join(map(str,G)))
    print(c)
    for a in A:
        print(a)

def insertion_sort(A, n, g):
    c = 0
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j = j - g
            c += 1
        A[j + g] = v
    return c

def shell_sort(A, n):
    G = sorted(iter_g(n), reverse=True)
    c = 0
    for g in G:
        c += insertion_sort(A, n, g)
    return A, c, G

def iter_g(n):
    v = 1
    d = 3
    while v <= n:
        yield v
        v += d
        d *= 3

if __name__ == '__main__':
    main() from sys import stdin def stdinput():
    return stdin.readline().strip() stdinput return stdin.readline().strip() stdin.readline().strip() stdin.readline().strip stdin.readline() stdin.readline stdin readline strip def main():
    n = int(stdinput())
    A = list(map(int, [stdinput() for _ in range(n)]))

    A, c, G = shell_sort(A, len(A))

    print(len(G))
    print(' '.join(map(str,G)))
    print(c)
    for a in A:
        print(a) main n = int(stdinput()) n int(stdinput()) int stdinput() stdinput stdinput() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) stdinput() stdinput A = list(map(int, [stdinput() for _ in range(n)])) A list(map(int, [stdinput() for _ in range(n)])) list map(int, [stdinput() for _ in range(n)]) map int [stdinput() for _ in range(n)] A, c, G = shell_sort(A, len(A)) A shell_sort(A, len(A)) shell_sort A len(A) len A c G print(len(G)) print len(G) len G print(' '.join(map(str,G))) print ' '.join(map(str,G)) ' '.join ' ' join map(str,G) map str G print(c) print c for a in A:
        print(a) a A print(a) print a def insertion_sort(A, n, g):
    c = 0
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j = j - g
            c += 1
        A[j + g] = v
    return c insertion_sort c = 0 c 0 for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j = j - g
            c += 1
        A[j + g] = v
     i range(g, n) range g n v = A[i] v A[i] A i j = i - g j i - g i g while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j = j - g
            c += 1
         j >= 0 and A[j] > v j >= 0 j 0 A[j] > v A[j] A j v A[j + g] = A[j] A[j + g] A j + g j g A[j] A j j = j - g j j - g j g c += 1 c 1 A[j + g] = v A[j + g] A j + g j g v return c c A A n n g g def shell_sort(A, n):
    G = sorted(iter_g(n), reverse=True)
    c = 0
    for g in G:
        c += insertion_sort(A, n, g)
    return A, c, G shell_sort G = sorted(iter_g(n), reverse=True) G sorted(iter_g(n), reverse=True) sorted iter_g(n) iter_g n reverse=True reverse True c = 0 c 0 for g in G:
        c += insertion_sort(A, n, g)
     g G c += insertion_sort(A, n, g) c insertion_sort(A, n, g) insertion_sort A n g return A, c, G return A, c, G A c G A A n n def iter_g(n):
    v = 1
    d = 3
    while v <= n:
        yield v
        v += d
        d *= 3 iter_g v = 1 v 1 d = 3 d 3 while v <= n:
        yield v
        v += d
        d *= 3 v <= n v n yield v v v += d v d d *= 3 d 3 n n if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def stdinput():
    return stdin.readline().strip() def stdinput():
    return stdin.readline().strip() stdinput def insertion_sort(A, n, g):
    c = 0
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j = j - g
            c += 1
        A[j + g] = v
    return c def insertion_sort(A, n, g):
    c = 0
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j = j - g
            c += 1
        A[j + g] = v
    return c insertion_sort def iter_g(n):
    v = 1
    d = 3
    while v <= n:
        yield v
        v += d
        d *= 3 def iter_g(n):
    v = 1
    d = 3
    while v <= n:
        yield v
        v += d
        d *= 3 iter_g def shell_sort(A, n):
    G = sorted(iter_g(n), reverse=True)
    c = 0
    for g in G:
        c += insertion_sort(A, n, g)
    return A, c, G def shell_sort(A, n):
    G = sorted(iter_g(n), reverse=True)
    c = 0
    for g in G:
        c += insertion_sort(A, n, g)
    return A, c, G shell_sort def main():
    n = int(stdinput())
    A = list(map(int, [stdinput() for _ in range(n)]))

    A, c, G = shell_sort(A, len(A))

    print(len(G))
    print(' '.join(map(str,G)))
    print(c)
    for a in A:
        print(a) def main():
    n = int(stdinput())
    A = list(map(int, [stdinput() for _ in range(n)]))

    A, c, G = shell_sort(A, len(A))

    print(len(G))
    print(' '.join(map(str,G)))
    print(c)
    for a in A:
        print(a) main
from sys import stdin
def stdinput():
    return stdin.readline().strip()

def main():
    n = int(stdinput())
    A = list(map(int, [stdinput() for _ in range(n)]))

    A, c, G = shell_sort(A, len(A))

    print(len(G))
    print(' '.join(map(str,G)))
    print(c)
    for a in A:
        print(a)

def insertion_sort(A, n, g):
    c = 0
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j = j - g
            c += 1
        A[j + g] = v
    return c

def shell_sort(A, n):
    G = sorted(iter_g(n), reverse=True)
    c = 0
    for g in G:
        c += insertion_sort(A, n, g)
    return A, c, G

def iter_g(n):
    v = 1
    d = 3
    while v <= n:
        yield v
        v += d
        d *= 3

if __name__ == '__main__':
    main()
