Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce

def main():
    n = int(input())
    A = list(map(int, input().split()))

    gcd_max = 1
    L = A[0]
    for i in range(n):
        if i == 0:
            tempt = reduce(gcd, A[i+1:])
            gcd_max = max(gcd_max, tempt)
        elif i != n-1:
            L = gcd(L,A[i-1])
            tempt = gcd(L,reduce(gcd, A[i+1:]))
            gcd_max = max(gcd_max, tempt)
        else:
            L = gcd(L,A[i-1])
            tempt = L
            gcd_max = max(gcd_max, tempt)
    print(gcd_max)


if __name__ == '__main__':
    main()

Fixed submission:
from fractions import gcd


def main():
    n = int(input())
    A = list(map(int, input().split()))

    L = []
    R = []
    for i in range(n):
        if i == 0:
            L.append(A[0])
            R.append(A[-1])
            continue
        L.append(gcd(L[i-1],A[i]))
        R.append(gcd(R[i-1],A[-i-1]))
    R.reverse()

    for i in range(n):
        if i == 0:
            gcd_max = R[1]
        elif i != n-1:
            gcd_max = max(gcd_max, gcd(L[i-1], R[i+1]))
        else:
            gcd_max = max(gcd_max, L[-2])
    print(gcd_max)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce

def main():
    n = int(input())
    A = list(map(int, input().split()))

    gcd_max = 1
    L = A[0]
    for i in range(n):
        if i == 0:
            tempt = reduce(gcd, A[i+1:])
            gcd_max = max(gcd_max, tempt)
        elif i != n-1:
            L = gcd(L,A[i-1])
            tempt = gcd(L,reduce(gcd, A[i+1:]))
            gcd_max = max(gcd_max, tempt)
        else:
            L = gcd(L,A[i-1])
            tempt = L
            gcd_max = max(gcd_max, tempt)
    print(gcd_max)


if __name__ == '__main__':
    main()

Fixed submission:
from fractions import gcd


def main():
    n = int(input())
    A = list(map(int, input().split()))

    L = []
    R = []
    for i in range(n):
        if i == 0:
            L.append(A[0])
            R.append(A[-1])
            continue
        L.append(gcd(L[i-1],A[i]))
        R.append(gcd(R[i-1],A[-i-1]))
    R.reverse()

    for i in range(n):
        if i == 0:
            gcd_max = R[1]
        elif i != n-1:
            gcd_max = max(gcd_max, gcd(L[i-1], R[i+1]))
        else:
            gcd_max = max(gcd_max, L[-2])
    print(gcd_max)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)

def main():
    n = int(input())
    A = list(map(int, input().split()))

    gcd_max = 1
    for i in range(n):
        if i == n-1:
            temp = A[i]
            A[i] = A[i-1]
            gcd_max = max(gcd_max, gcd_list(A))
            A[i] = temp
            break
        temp = A[i]
        A[i] = A[i+1]
        gcd_max = max(gcd_max, gcd_list(A))
        A[i] = temp
    print(gcd_max)


if __name__ == '__main__':
    main()


Fixed submission:
from fractions import gcd


def main():
    n = int(input())
    A = list(map(int, input().split()))

    L = []
    R = []
    for i in range(n):
        if i == 0:
            L.append(A[0])
            R.append(A[-1])
            continue
        L.append(gcd(L[i-1],A[i]))
        R.append(gcd(R[i-1],A[-i-1]))
    R.reverse()

    for i in range(n):
        if i == 0:
            gcd_max = R[1]
        elif i != n-1:
            gcd_max = max(gcd_max, gcd(L[i-1], R[i+1]))
        else:
            gcd_max = max(gcd_max, L[-2])
    print(gcd_max)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)

def main():
    n = int(input())
    A = list(map(int, input().split()))

    gcd_max = 1
    for i in range(n):
        if i == n-1:
            temp = A[i]
            A[i] = A[i-1]
            gcd_max = max(gcd_max, gcd_list(A))
            A[i] = temp
            break
        temp = A[i]
        A[i] = A[i+1]
        gcd_max = max(gcd_max, gcd_list(A))
        A[i] = temp
    print(gcd_max)


if __name__ == '__main__':
    main()


Fixed submission:
from fractions import gcd


def main():
    n = int(input())
    A = list(map(int, input().split()))

    L = []
    R = []
    for i in range(n):
        if i == 0:
            L.append(A[0])
            R.append(A[-1])
            continue
        L.append(gcd(L[i-1],A[i]))
        R.append(gcd(R[i-1],A[-i-1]))
    R.reverse()

    for i in range(n):
        if i == 0:
            gcd_max = R[1]
        elif i != n-1:
            gcd_max = max(gcd_max, gcd(L[i-1], R[i+1]))
        else:
            gcd_max = max(gcd_max, L[-2])
    print(gcd_max)


if __name__ == '__main__':
    main()