Buggy python submission (verdict: Time Limit Exceeded):
def insertion_sort(a, n, g):
    count = 0
    for i in range(g, n):
        for j in range(i, g-1, -g):
            if a[j-g] > a[j]:
                a[j-g], a[j] = a[j], a[j-g]
                count += 1

    return a, count


if __name__ == "__main__":
    import sys
    n = int(input())
    a = list(map(int, sys.stdin))
    count = 0

    G = [1]
    while n > 3*G[-1] + 1:
        G.append(3*G[-1] + 1)

    for g in G[::-1]:
        a, cnt = insertion_sort(a, n, g)
        count += cnt

    print(len(G))
    print(*G[::-1])
    print(count)
    print(*a, sep="\n")


Fixed submission:
def shellsort(a):
    l = len(a)
    gaps = [1]
    while gaps[0]*3+1 < (l/9 if l>100 else l) and len(gaps) <= 100:
        gaps.insert(0, gaps[0]*3+1)
    count = 0
    for g in gaps:
        for i in range(g, l):
            v = a[i]
            j = i-g
            while j >= 0 and v < a[j]:
                a[j+g] = a[j]
                j -= g
                count += 1
            a[j+g] = v

    print(len(gaps))
    print(" ".join([str(n) for n in gaps]))
    print(count)
    print("\n".join([str(n) for n in a]))

shellsort([int(input()) for _ in [None]*(int(input()))])

Buggy python submission (verdict: Time Limit Exceeded):
def shellsort(a):
    l = len(a)
    intervals = [n for n in (40, 13, 4, 1) if n <= l]
    count = 0
    for interval in intervals:
        for i in range(interval, l):
            j = 0
            while i-interval*(j+1) >= 0:
                n, m = i-interval*j, i-interval*(j+1)
                if a[n] < a[m]:
                    a[n], a[m] = a[m], a[n]
                    j += 1
                    count += 1
                else:
                    break

    print(len(intervals))
    print(" ".join([str(n) for n in intervals]))
    print(count)
    print("\n".join([str(n) for n in a]))

shellsort([int(input()) for _ in range(int(input()))])

Fixed submission:
def shellsort(a):
    l = len(a)
    gaps = [1]
    while gaps[0]*3+1 < (l/9 if l>100 else l) and len(gaps) <= 100:
        gaps.insert(0, gaps[0]*3+1)
    count = 0
    for g in gaps:
        for i in range(g, l):
            v = a[i]
            j = i-g
            while j >= 0 and v < a[j]:
                a[j+g] = a[j]
                j -= g
                count += 1
            a[j+g] = v

    print(len(gaps))
    print(" ".join([str(n) for n in gaps]))
    print(count)
    print("\n".join([str(n) for n in a]))

shellsort([int(input()) for _ in [None]*(int(input()))])

Buggy python submission (verdict: Time Limit Exceeded):
def shellsort(a):
    l = len(a)
    intervals = [n for n in (40, 13, 4, 1) if n <= l]
    count = 0
    for interval in intervals:
        for i in range(interval, l):
            v = a[i]
            j = i-interval
            while j >= 0 and v < a[j]:
                a[j+interval] = a[j]
                j -= interval
                count += 1
            a[j+interval] = v

    print(len(intervals))
    print(" ".join([str(n) for n in intervals]))
    print(count)
    print("\n".join([str(n) for n in a]))

shellsort([int(input()) for _ in range(int(input()))])

Fixed submission:
def shellsort(a):
    l = len(a)
    gaps = [1]
    while gaps[0]*3+1 < (l/9 if l>100 else l) and len(gaps) <= 100:
        gaps.insert(0, gaps[0]*3+1)
    count = 0
    for g in gaps:
        for i in range(g, l):
            v = a[i]
            j = i-g
            while j >= 0 and v < a[j]:
                a[j+g] = a[j]
                j -= g
                count += 1
            a[j+g] = v

    print(len(gaps))
    print(" ".join([str(n) for n in gaps]))
    print(count)
    print("\n".join([str(n) for n in a]))

shellsort([int(input()) for _ in [None]*(int(input()))])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def shellsort(a):
    l = len(a)
    intervals = [n for n in (40, 13, 4, 1) if n <= l]
    count = 0
    for interval in intervals:
        for i in range(interval, l):
            v = a[i]
            j = i-interval
            while j >= 0 and v < a[j]:
                a[j+interval] = a[j]
                j -= interval
                count += 1
            a[j+interval] = v

    print(len(intervals))
    print(" ".join([str(n) for n in intervals]))
    print(count)
    print("\n".join([str(n) for n in a]))

input()
shellsort(list(map(int, sys.stdin.readlines())))

Fixed submission:
def shellsort(a):
    l = len(a)
    gaps = [1]
    while gaps[0]*3+1 < (l/9 if l>100 else l) and len(gaps) <= 100:
        gaps.insert(0, gaps[0]*3+1)
    count = 0
    for g in gaps:
        for i in range(g, l):
            v = a[i]
            j = i-g
            while j >= 0 and v < a[j]:
                a[j+g] = a[j]
                j -= g
                count += 1
            a[j+g] = v

    print(len(gaps))
    print(" ".join([str(n) for n in gaps]))
    print(count)
    print("\n".join([str(n) for n in a]))

shellsort([int(input()) for _ in [None]*(int(input()))])