Problem p03061 (python)

Fixed submission:
 
#from functools import reduce
def gcd(m,n):
  x=max(m,n)
  y=min(m,n)
  while y!=0:
    x,y=y,x%y
  return x
 
a=int(input())
li=list(map(int,input().split()))
left_gcd=[0]
#left_gcd.append(li[0])
right_gcd=[0]
#right_gcd.append(li[a-1])

for i in range(a):
    left_gcd.append(gcd(li[i],left_gcd[i]))
    right_gcd.append(gcd(li[a-1-i],right_gcd[i]))
    #k=k+1
# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)
#print(right_gcd)
#print(left_gcd)
num_li=[]
#num_li.append(right_gcd[a-2])
#num_li.append(left_gcd[a-2])
#s=2
for i in range(a):
    ans=gcd(left_gcd[(a-1)-i],right_gcd[i])
    #print(left_gcd[(a-3-i)],right_gcd[i])
  
    #print(ans)
    num_li.append(ans)
    

print(max(num_li))

Buggy submission (verdict: Runtime Error):
from fractions import gcd
#from functools import reduce
a=int(input())
li=list(map(int,input().split()))
left_gcd=[]
left_gcd.append(li[0])
right_gcd=[]
right_gcd.append(li[a-1])

for i in range(a-1):
    left_gcd.append(gcd(left_gcd[i],li[i+1]))
k=0
for i in range(a-1,0,-1):
    right_gcd.append(gcd(right_gcd[k],li[i-1]))
    k=k+1
# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)
#print(right_gcd)
#print(left_gcd)
num_li=[]
num_li.append(right_gcd[a-2])
num_li.append(left_gcd[a-2])
#s=2
for i in range(a):
    ans=math.gcd(left_gcd[(a-3)-i],right_gcd[i])
    #print(left_gcd[(a-3-i)],right_gcd[i])
  
    #print(ans)
    num_li.append(ans)
    

print(max(num_li))

Buggy submission (verdict: Runtime Error):
from fractions import gcd
#from functools import reduce
a=int(input())
li=list(map(int,input().split()))
left_gcd=[]
left_gcd.append(li[0])
right_gcd=[]
right_gcd.append(li[a-1])

for i in range(a-1):
    left_gcd.append(math.gcd(left_gcd[i],li[i+1]))
k=0
for i in range(a-1,0,-1):
    right_gcd.append(math.gcd(right_gcd[k],li[i-1]))
    k=k+1
# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)
#print(right_gcd)
#print(left_gcd)
num_li=[]
num_li.append(right_gcd[a-2])
num_li.append(left_gcd[a-2])
#s=2
for i in range(a):
    ans=math.gcd(left_gcd[(a-3)-i],right_gcd[i])
    #print(left_gcd[(a-3-i)],right_gcd[i])
  
    #print(ans)
    num_li.append(ans)
    

print(max(num_li))

Buggy submission (verdict: Runtime Error):
import math
#from functools import reduce
a=int(input())
li=list(map(int,input().split()))
left_gcd=[]
left_gcd.append(li[0])
right_gcd=[]
right_gcd.append(li[a-1])

for i in range(a-1):
    left_gcd.append(math.gcd(left_gcd[i],li[i+1]))
k=0
for i in range(a-1,0,-1):
    right_gcd.append(math.gcd(right_gcd[k],li[i-1]))
    k=k+1
# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)
#print(right_gcd)
#print(left_gcd)
num_li=[]
num_li.append(right_gcd[a-2])
num_li.append(left_gcd[a-2])
#s=2
for i in range(a):
    ans=math.gcd(left_gcd[(a-3)-i],right_gcd[i])
    #print(left_gcd[(a-3-i)],right_gcd[i])
  
    #print(ans)
    num_li.append(ans)
    

print(max(num_li))

Buggy submission (verdict: Runtime Error):
def gcd(x,y):
    if y == 0:
        #print(x)
        return x
    else:
        return gcd(y, x%y)

# def lcm(x,y):
#     return x/gcd(x,y)*y
#ans=1

a=int(input())
li=list(map(int,input().split()))
#li_same=li
num=0
num_li=[]
for i in range(a):
    #li=li_same
    b=li.pop(i)
    k=len(li)
    for j in range(1,k):
        ans=gcd(li[j-1],li[j])
        #print(ans)
    #print('hoge')
    num_li.append(ans)
    li.insert(i,b)

print(int(max(num_li)))

Buggy submission (verdict: Runtime Error):
def gcd(x,y):
    if y == 0:
        print(x)
        return x
    else:
        return gcd(y, x%y)

# def lcm(x,y):
#     return x/gcd(x,y)*y
#ans=1

a=int(input())
li=list(map(int,input().split()))
#li_same=li
num=0
num_li=[]
for i in range(a):
    #li=li_same
    b=li.pop(i)
    k=len(li)
    for j in range(1,k):
        ans=gcd(li[j-1],li[j])
        print(ans)
    print('hoge')
    num_li.append(ans)
    li.insert(i,b)

print(int(max(num_li)))

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
a=int(input())
li=list(map(int,input().split()))
#li_same=li
num=0
num_li=[]
for i in range(a):
    #li=li_same
    b=li.pop(i)
    num=gcd_list(li)
    num_li.append(num)
    li.insert(i,b)
   
print(max(num_li))