Problem p03061 (python)

Fixed submission:
import sys

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

n=int(input())
al=input().split()
al_i = [int(s) for s in al]

if (n == 2):
   print(max(al_i[0],al_i[1]))
   sys.exit()

fg = [0] * n
bg = [0] * n

for x in range(n):
   if (x == 0):
       fg[0] = al_i[0]
       y = 1
   else:
      while y <= x:
         fg[y] = gcd(fg[y-1], al_i[y])
         y += 1

for x in range(n):
   if (x == 0):
      bg[0] = al_i[n-1]
      y = 1
   else:
      while y <= x:
         bg[y] = gcd(bg[y-1], al_i[n-1-y])
         y += 1

m = 0
gm = 0

for x in range(n):
   if (x == 0):
      g = bg[n-2]
   elif (x == n-1):
      g = fg[n-2]
   else:
      g = gcd(fg[x-1],bg[n-2-x])
   if (g > gm):
      gm = g

print(gm)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
import sys
sys.setrecursionlimit(10**6)

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

N = int(input())
A = []
A = list(map(int, input().split()))
len = len(A)
gcd = 1

if N==2:
    print(max(A[0],A[1]))
    sys.exit()

for i in range(len):
    x = A.pop(i)
    print(i)
    if gcd_list(A) > gcd:
        gcd = gcd_list(A)
    A.insert(i, x)
print(gcd)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
import sys
sys.setrecursionlimit(10**6)

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

N = int(input())
A = []
A = list(map(int, input().split()))
len = len(A)
gcd = 1

if gcd_list(A) > gcd:
    gcd = gcd_list(A)

if len > 2:
    for i in range(len):
        x = A.pop(i)
        if gcd_list(A) > gcd:
            gcd = gcd_list(A)
        A.insert(i, x)
print(gcd)

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

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

N = int(input())
A = []
A = list(map(int, input().split()))
len = len(A)
gcd = 1

if gcd_list(A) > gcd:
    gcd = gcd_list(A)

if len > 2:
    for i in range(len):
        x = A.pop(i)
        if gcd_list(A) > gcd:
            gcd = gcd_list(A)
        A.insert(i, x)
print(gcd)

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

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

N = int(input())
A = []
A = list(map(int, input().split()))
len = len(A)
gcd = 1

if gcd_list(A) > gcd:
    gcd = gcd_list(A)

if len > 2:
    for i in range(len):
        x = A.pop(i)
        if gcd_list(A) > gcd:
            gcd = gcd_list(A)
        A.insert(i, x)
print(gcd)

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

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

N=int(input())
A=[]
A=list(map(int,input().split()))
len=len(A)
gcd=1
new=A[0]

if gcd_list(A)>gcd:
    gcd=gcd_list(A)

if(len>2):
    for i in range(len):
        x=A.pop(i)
        if gcd_list(A)>gcd:
            gcd=gcd_list(A)
            new=gcd
            j=i
        A.insert(i,x)
A.pop(j)
A.insert(j,gcd)
print(gcd)

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

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

N=int(input())
A=[]
A=list(map(int,input().split(" ",N)))
len=len(A)
gcd=1
new=A[0]

if gcd_list(A)>gcd:
    gcd=gcd_list(A)

if(len>2):
    for i in range(len):
        x=A.pop(i)
        if gcd_list(A)>gcd:
            gcd=gcd_list(A)
            new=gcd
            j=i
        A.insert(i,x)
A.pop(j)
A.insert(j,gcd)
print(gcd)

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

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

N=int(input())
A=[]
A=list(map(int,input().split(" ",N)))
len=len(A)
gcd=1

if gcd_list(A)>gcd:
    gcd=gcd_list(A)

if(len>2):
    for i in range(len):
        x=A.pop(i)
        if gcd_list(A)>gcd:
            gcd=gcd_list(A)
        A.insert(i,x)

print(gcd)

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

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

N=int(input())
A=[]
A=list(map(int,input().split(" ",N)))
len=len(A)
gcd=1

for i in range(len):
    x=A.pop(i)
    if gcd_list(A)>gcd:
        gcd=gcd_list(A)
    A.insert(i,x)

print(gcd)