Buggy python submission (verdict: Runtime Error):
#! python
# shell_sort.py

import copy
import math

count = 0

def insertion_sort(A, N, g):
    global count
    A_ = copy.copy(A)
    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
            count += 1
        A_[j + g] = v
    return A_

# h_(i+1) = 3h_i + 1 が最良の間隔
def shell_sort(A, N):
    A_ = copy.copy(A)

    h = 1
    G = []
    while True:
        G.append(h)
        h = 3*h + 1
        if h > N:
            break
    G = G[::-1]
    m = len(G)

    for i in range(m):
        A_ = insertion_sort(A_, N, G[i])
    return A_, m, G

n = int(input())
A = [int(input()) for i in range(n)]

A, m, G = shell_sort(A, n)

print(m)
print(' '.join([str(h) for h in G]))
print(count)
for x in A:
    print(x)


Fixed submission:
import math
import sys

count = 0
m = 0
G = []

def insertion_sort(A, N, g):
    global count
    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
            count += 1
        A[j + g] = v

# h_(i+1) = 3h_i + 1 が最良の間隔 (らしい)
def shell_sort(A, N):
    global m, G
    m = math.floor(math.log(2*N+1, 3))
    G = [int((pow(3, i)-1)/2) for i in range(m, 0, -1)]

    for i in range(m):
        insertion_sort(A, N, G[i])


n = int(input())
A = list(map(int, sys.stdin.readlines()))
shell_sort(A, n)

print(m)
print(' '.join([str(h) for h in G]))
print(count)
for x in A:
    print(x)

Buggy python submission (verdict: Runtime Error):
#! python
# shell_sort.py

import copy
import math

count = 0

def insertion_sort(A, N, g):
    global count
    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
            count += 1
        A[j + g] = v

# h_(i+1) = 3h_i + 1 が最良の間隔
def shell_sort(A, N):
    h = 1
    G = []
    while True:
        G.append(h)
        h = 3*h + 1
        if h > N:
            break
    G = G[::-1]
    m = len(G)

    for i in range(m):
        insertion_sort(A, N, G[i])
    return m, G

n = int(input())
A = [int(input()) for i in range(n)]

m, G = shell_sort(A, n)

print(m)
print(' '.join([str(h) for h in G]))
print(count)
for x in A:
    print(x)


Fixed submission:
import math
import sys

count = 0
m = 0
G = []

def insertion_sort(A, N, g):
    global count
    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
            count += 1
        A[j + g] = v

# h_(i+1) = 3h_i + 1 が最良の間隔 (らしい)
def shell_sort(A, N):
    global m, G
    m = math.floor(math.log(2*N+1, 3))
    G = [int((pow(3, i)-1)/2) for i in range(m, 0, -1)]

    for i in range(m):
        insertion_sort(A, N, G[i])


n = int(input())
A = list(map(int, sys.stdin.readlines()))
shell_sort(A, n)

print(m)
print(' '.join([str(h) for h in G]))
print(count)
for x in A:
    print(x)

Buggy python submission (verdict: Runtime Error):
import math

count = 0
m = 0
G = []

def insertion_sort(A, N, g):
    global count
    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
            count += 1
        A[j + g] = v

# h_(i+1) = 3h_i + 1 が最良の間隔 (らしい)
def shell_sort(A, N):
    global m, G
    m = math.floor(math.log(2*N+1, 3))
    G = [int((pow(3, i)-1)/2) for i in range(m, 0, -1)]

    for i in range(m):
        insertion_sort(A, N, G[i])


n = int(input())
A = [int(input()) for i in range(n)]
shell_sort(A, n)

print(m)
print(' '.join([str(h) for h in G]))
print(count)
for x in A:
    print(x)



Fixed submission:
import math
import sys

count = 0
m = 0
G = []

def insertion_sort(A, N, g):
    global count
    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
            count += 1
        A[j + g] = v

# h_(i+1) = 3h_i + 1 が最良の間隔 (らしい)
def shell_sort(A, N):
    global m, G
    m = math.floor(math.log(2*N+1, 3))
    G = [int((pow(3, i)-1)/2) for i in range(m, 0, -1)]

    for i in range(m):
        insertion_sort(A, N, G[i])


n = int(input())
A = list(map(int, sys.stdin.readlines()))
shell_sort(A, n)

print(m)
print(' '.join([str(h) for h in G]))
print(count)
for x in A:
    print(x)