Problem p03394 (python)

Fixed submission:
# import math
# from functools import reduce

# def gcd(*numbers):
#     return reduce(math.gcd, numbers)

N = int(input())
if N <= 5:
    if N == 3: print('2 5 63')
    elif N == 4: print('2 5 20 63')
    elif N == 5: print('2 5 20 30 63')
else:
    flag = 0
    S = 0
    k = 0
    retList = list()
    Q = N // 4
    R = N % 4
    for q in range(Q):
        S += 4*6*q + 15
        retList.append(str(6*q+2))
        retList.append(str(6*q+3))
        retList.append(str(6*q+4))
        retList.append(str(6*q+6))
    if R == 0:
        pass
    elif R == 1:
        S += 6*Q + 2
        retList.append(str(6*Q + 2))
    elif R == 2:
        S += 2*6*Q + 5
        retList.append(str(6*Q + 2))
        retList.append(str(6*Q + 3))
    elif R == 3:
        S += 3*6*Q + 9
        retList.append(str(6*Q + 2))
        retList.append(str(6*Q + 3))
        retList.append(str(6*Q + 4))

    if S%6 == 0:
        pass
    elif S%6 == 2:
        retList.remove('8')
        S -= 8
        S += 6*(Q+1) + 6
        retList.append(str(6*Q + 6))
    elif S%6 == 3:
        retList.remove('9')
        S -= 9
        S += 6*(Q+1) + 6
        retList.append(str(6*Q + 6))
    elif S%6 == 5:
        retList.remove('9')
        S -= 9
        S += 6*(Q+1) + 4
        retList.append(str(6*Q + 4))
    # print(S%6)
    # print(len(retList))
    # retIntList = list(map(int, retList))
    # for a in retIntList:
    #     if gcd(S, a) <= 1:
    #         print(S)
    #         print(a)
    print(' '.join(retList))
    # print(gcd(*retIntList))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

N = int(input())
if N <= 5:
    if N == 3: print('2 5 63')
    elif N == 4: print('2 5 20 63')
    elif N == 5: print('2 5 20 30 63')
else:
    flag = 0
    S = 0
    k = 0
    retList = list()
    Q = N // 4
    R = N % 4
    for q in range(Q):
        S += 4*6*q + 15
        retList.append(str(6*q+2))
        retList.append(str(6*q+3))
        retList.append(str(6*q+4))
        retList.append(str(6*q+6))
    if R == 0:
        pass
    elif R == 1:
        S += 6*Q + 2
        retList.append(str(6*Q + 2))
    elif R == 2:
        S += 2*6*Q + 5
        retList.append(str(6*Q + 2))
        retList.append(str(6*Q + 3))
    elif R == 3:
        S += 3*6*Q + 9
        retList.append(str(6*Q + 2))
        retList.append(str(6*Q + 3))
        retList.append(str(6*Q + 4))

    if S%6 == 0:
        pass
    elif S%6 == 2:
        retList.remove('8')
        S -= 8
        S += 6*(Q+1) + 6
        retList.append(str(6*Q + 6))
    elif S%6 == 3:
        retList.remove('9')
        S -= 9
        S += 6*(Q+1) + 6
        if 6*
        retList.append(str(6*Q + 6))
    elif S%6 == 5:
        retList.remove('9')
        S -= 9
        S += 6*(Q+1) + 4
        retList.append(str(6*Q + 4))
    # print(S%6)
    # print(len(retList))
    # retIntList = list(map(int, retList))
    # for a in retIntList:
    #     if gcd(S, a) <= 1:
    #         print(S)
    #         print(a)
    print(' '.join(retList))
    # print(gcd(*retIntList))

Buggy submission (verdict: Runtime Error):
N = int(input())
if N <= 5:
    if N == 3: print('2 5 63')
    elif N == 4: print('2 5 20 63')
    elif N == 5: print('2 5 20 30 63')
else:
    flag = 0
    S = 0
    k = 0
    retList = list()
    Q = N // 4
    R = N % 4
    for q in range(Q):
        S += 4*6*q + 15
        retList.append(str(6*q+2))
        retList.append(str(6*q+3))
        retList.append(str(6*q+4))
        retList.append(str(6*q+6))
    if R == 0:
        pass
    elif R == 1:
        S += 6*Q + 2
        retList.append(6*Q + 2)
    elif R == 2:
        S += 2*6*Q + 5
        retList.append(6*Q + 2)
        retList.append(6*Q + 3)
    elif R == 3:
        S += 3*6*Q + 12
        retList.append(6*Q + 2)
        retList.append(6*Q + 3)
        retList.append(6*Q + 5)

    # for i in range(len(N)):
    #     if flag%4 == 0: 
    #         S += 6*k + 2
    #         retList.append(str(6*k + 2))
    #     elif flag%4 == 1:
    #         S += 6*k + 3
    #         retList.append(str(6*k + 3))
    #     elif flag%4 == 2: 
    #         S += 6*k + 4
    #         retList.append(str(6*k + 4))
    #     elif flag%4 == 3: 
    #         S += 6*k + 6
    #         retList.append(str(6*k + 6))
    #         k += 1
        
    #     if flag == 4: flag = 0
    #     else: flag += 1

    if S%6 == 0:
        pass
    elif S%6 == 2:
        retList.remove('8')
        retList.append(str(6*k + 6))
    elif S%6 == 3:
        retList.remove('9')
        retList.append(str(6*(k+1) + 6))
    elif S%6 == 5:
        retList.remove('9')
        retList.append(str(6*(k+1) + 4))
    print(' '.join(retList))

Buggy submission (verdict: Runtime Error):
N = int(input())
if N <= 5:
    if N == 3: print('2 5 63')
    elif N == 4: print('2 5 20 63')
    elif N == 5: print('2 5 20 30 63')
else:
    flag = 0
    S = 0
    k = 0
    retList = list()
    Q = N // 4
    R = N % 4
    for q in range(len(Q)):
        S += 4*6*q + 15
        retList.append(str(6*q+2))
        retList.append(str(6*q+3))
        retList.append(str(6*q+4))
        retList.append(str(6*q+6))
    if R == 0:
        pass
    elif R == 1:
        S += 6*Q + 2
        retList.append(6*Q + 2)
    elif R == 2:
        S += 2*6*Q + 5
        retList.append(6*Q + 2)
        retList.append(6*Q + 3)
    elif R == 3:
        S += 3*6*Q + 12
        retList.append(6*Q + 2)
        retList.append(6*Q + 3)
        retList.append(6*Q + 5)

    # for i in range(len(N)):
    #     if flag%4 == 0: 
    #         S += 6*k + 2
    #         retList.append(str(6*k + 2))
    #     elif flag%4 == 1:
    #         S += 6*k + 3
    #         retList.append(str(6*k + 3))
    #     elif flag%4 == 2: 
    #         S += 6*k + 4
    #         retList.append(str(6*k + 4))
    #     elif flag%4 == 3: 
    #         S += 6*k + 6
    #         retList.append(str(6*k + 6))
    #         k += 1
        
    #     if flag == 4: flag = 0
    #     else: flag += 1

    if S%6 == 0:
        pass
    elif S%6 == 2:
        retList.remove('8')
        retList.append(str(6*k + 6))
    elif S%6 == 3:
        retList.remove('9')
        retList.append(str(6*(k+1) + 6))
    elif S%6 == 5:
        retList.remove('9')
        retList.append(str(6*(k+1) + 4))
    print(' '.join(retList))

Buggy submission (verdict: Runtime Error):
N = int(input())
if N <= 5:
    if N == 3: print('2 5 63')
    elif N == 4: print('2 5 20 63')
    elif N == 5: print('2 5 20 30 63')
else:
    flag = 0
    S = 0
    k = 0
    retList = list()
    for i in range(len(N)):
        if flag%4 == 0: 
            S += 6*k + 2
            retList.append(str(6*k + 2))
        elif flag%4 == 1:
            S += 6*k + 3
            retList.append(str(6*k + 3))
        elif flag%4 == 2: 
            S += 6*k + 4
            retList.append(str(6*k + 4))
        elif flag%4 == 3: 
            S += 6*k + 6
            retList.append(str(6*k + 6))
            k += 1
        
        if flag == 4: flag = 0
        else: flag += 1

    if S%6 == 0:
        pass
    elif S%6 == 2:
        retList.remove('8')
        retList.append(str(6*k + 6))
    elif S%6 == 3:
        retList.remove('9')
        retList.append(str(6*(k+1) + 6))
    elif S%6 == 5:
        retList.remove('9')
        retList.append(str(6*(k+1) + 4))
    print(' '.join(retList))