Problem p03061 (python)

Fixed submission:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter
#from heapq import heappush, heappop
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ni()
A = na()
b = [0] * N
c = [0] * N
b[0] = A[0]
c[-1] = A[-1]
for i in range(N-1):
    b[i+1] = math.gcd(b[i], A[i+1])
    c[-(i+2)] = math.gcd(c[-(i+1)], A[-(i+2)])

ans = 1
ans = max(c[1], ans)
ans = max(b[-2], ans)
for i in range(1, N-1):
    ans = max(math.gcd(b[i-1], c[i+1]), ans)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import fractions

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n = ni()
li = na()
li2 = []
kouho = []
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    a = fractions.gcd(li[0], li[1])
    b = fractions.gcd(li[1], li[2])
    c = fractions.gcd(li[2], li[0])
    li2.append(a)
    li2.append(b)
    li2.append(c)
    li2.extend(make_divisors(a))
    li2.extend(make_divisors(b))
    li2.extend(make_divisors(c))
    kouho = set(li2)
    for i in range(3,n):
        if len(kouho) == 0:
            break
        for num in kouho:
            if li[i] % num != 0:
                kouho.remove(num)
    if len(kouho) == 0:
        print(1)
    else:
        print(max(kouho))

Buggy submission (verdict: Runtime Error):
import sys
import fractions

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

kouho = []
n = ni()
li = na()
flag = 0
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    kouho.append(fractions.gcd(li[0], li[1]))
    kouho.append(fractions.gcd(li[1], li[2]))
    kouho.append(fractions.gcd(li[2], li[0]))
    for i in range(3,n):
        if len(kouho) == 0:
            print(i)
            break
        for num in kouho:
            if li[i] % num != 0:
                kouho.remove(num)
    print(max(kouho))

Buggy submission (verdict: Runtime Error):
import sys
import fractions

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

kouho = []
n = ni()
li = na()
flag = 0
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    kouho.append(fractions.gcd(li[0], li[1]))
    kouho.append(fractions.gcd(li[1], li[2]))
    kouho.append(fractions.gcd(li[2], li[0]))
    for i in range(3,n):
        if len(kouho) == 0:
            print(i)
            break
        for num in kouho:
            if li[i] % num != 0:
                kouho.remove(num)
print(max(kouho))