from typing import List, Tuple


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


def shell_sort(A: List[int], n: int) -> Tuple[int, List[int], int, List[int]]:
    cnt: int = 0
    G: List[int] = [1]
    h: int = 1

    while 3 * h + 1 < n:
        h = 3 * h + 1
        G.append(h)

    G.reverse()
    m = len(G)

    for i in range(m):
        count = insertion_sort(A, n, G[i])
        cnt += count

    return m, G, cnt, A


def main():
    n: int = int(input())
    A: List[int] = []
    for _ in range(n):
        A.append(int(input()))
    m, G, cnt, A_sorted = shell_sort(A[:], n)

    print(m)
    print(*G, sep=" ")
    print(cnt)
    print(*A_sorted, sep="\n")


if __name__ == "__main__":
    main()
 from typing import List, Tuple def insertion_sort(A: List[int], n: int, g: int) -> int:
    count: int = 0
    for i in range(g, n):
        j = i - g
        while j >= 0 and A[j] > A[j + g]:
            A[j], A[j + g] = A[j + g], A[j]
            j -= g
            count += 1
    return count insertion_sort count: int = 0 count 0 for i in range(g, n):
        j = i - g
        while j >= 0 and A[j] > A[j + g]:
            A[j], A[j + g] = A[j + g], A[j]
            j -= g
            count += 1
     i range(g, n) range g n j = i - g j i - g i g while j >= 0 and A[j] > A[j + g]:
            A[j], A[j + g] = A[j + g], A[j]
            j -= g
            count += 1
     j >= 0 and A[j] > A[j + g] j >= 0 j 0 A[j] > A[j + g] A[j] A j A[j + g] A j + g j g A[j], A[j + g] = A[j + g], A[j] A[j] A j A[j + g] A j + g j g A[j + g] A j + g j g A[j] A j j -= g j g count += 1 count 1 return count count A: List[int] A n: int n g: int g def shell_sort(A: List[int], n: int) -> Tuple[int, List[int], int, List[int]]:
    cnt: int = 0
    G: List[int] = [1]
    h: int = 1

    while 3 * h + 1 < n:
        h = 3 * h + 1
        G.append(h)

    G.reverse()
    m = len(G)

    for i in range(m):
        count = insertion_sort(A, n, G[i])
        cnt += count

    return m, G, cnt, A shell_sort cnt: int = 0 cnt 0 G: List[int] = [1] G [1] 1 h: int = 1 h 1 while 3 * h + 1 < n:
        h = 3 * h + 1
        G.append(h)

     3 * h + 1 < n 3 * h + 1 3 * h 3 h 1 n h = 3 * h + 1 h 3 * h + 1 3 * h 3 h 1 G.append(h) G.append G append h G.reverse() G.reverse G reverse m = len(G) m len(G) len G for i in range(m):
        count = insertion_sort(A, n, G[i])
        cnt += count

     i range(m) range m count = insertion_sort(A, n, G[i]) count insertion_sort(A, n, G[i]) insertion_sort A n G[i] G i cnt += count cnt count return m, G, cnt, A return m, G, cnt, A m G cnt A A: List[int] A n: int n def main():
    n: int = int(input())
    A: List[int] = []
    for _ in range(n):
        A.append(int(input()))
    m, G, cnt, A_sorted = shell_sort(A[:], n)

    print(m)
    print(*G, sep=" ")
    print(cnt)
    print(*A_sorted, sep="\n") main n: int = int(input()) n int(input()) int input() input A: List[int] = [] A [] for _ in range(n):
        A.append(int(input()))
     _ range(n) range n A.append(int(input())) A.append A append int(input()) int input() input m, G, cnt, A_sorted = shell_sort(A[:], n) m shell_sort(A[:], n) shell_sort A[:] A : n G cnt A_sorted print(m) print m print(*G, sep=" ") print *G G sep=" " sep " " print(cnt) print cnt print(*A_sorted, sep="\n") print *A_sorted A_sorted sep="\n" sep "\n" if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def shell_sort(A: List[int], n: int) -> Tuple[int, List[int], int, List[int]]:
    cnt: int = 0
    G: List[int] = [1]
    h: int = 1

    while 3 * h + 1 < n:
        h = 3 * h + 1
        G.append(h)

    G.reverse()
    m = len(G)

    for i in range(m):
        count = insertion_sort(A, n, G[i])
        cnt += count

    return m, G, cnt, A def shell_sort(A: List[int], n: int) -> Tuple[int, List[int], int, List[int]]:
    cnt: int = 0
    G: List[int] = [1]
    h: int = 1

    while 3 * h + 1 < n:
        h = 3 * h + 1
        G.append(h)

    G.reverse()
    m = len(G)

    for i in range(m):
        count = insertion_sort(A, n, G[i])
        cnt += count

    return m, G, cnt, A shell_sort def main():
    n: int = int(input())
    A: List[int] = []
    for _ in range(n):
        A.append(int(input()))
    m, G, cnt, A_sorted = shell_sort(A[:], n)

    print(m)
    print(*G, sep=" ")
    print(cnt)
    print(*A_sorted, sep="\n") def main():
    n: int = int(input())
    A: List[int] = []
    for _ in range(n):
        A.append(int(input()))
    m, G, cnt, A_sorted = shell_sort(A[:], n)

    print(m)
    print(*G, sep=" ")
    print(cnt)
    print(*A_sorted, sep="\n") main def insertion_sort(A: List[int], n: int, g: int) -> int:
    count: int = 0
    for i in range(g, n):
        j = i - g
        while j >= 0 and A[j] > A[j + g]:
            A[j], A[j + g] = A[j + g], A[j]
            j -= g
            count += 1
    return count def insertion_sort(A: List[int], n: int, g: int) -> int:
    count: int = 0
    for i in range(g, n):
        j = i - g
        while j >= 0 and A[j] > A[j + g]:
            A[j], A[j + g] = A[j + g], A[j]
            j -= g
            count += 1
    return count insertion_sort
from typing import List, Tuple


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


def shell_sort(A: List[int], n: int) -> Tuple[int, List[int], int, List[int]]:
    cnt: int = 0
    G: List[int] = [1]
    h: int = 1

    while 3 * h + 1 < n:
        h = 3 * h + 1
        G.append(h)

    G.reverse()
    m = len(G)

    for i in range(m):
        count = insertion_sort(A, n, G[i])
        cnt += count

    return m, G, cnt, A


def main():
    n: int = int(input())
    A: List[int] = []
    for _ in range(n):
        A.append(int(input()))
    m, G, cnt, A_sorted = shell_sort(A[:], n)

    print(m)
    print(*G, sep=" ")
    print(cnt)
    print(*A_sorted, sep="\n")


if __name__ == "__main__":
    main()

