Problem p03061 (python)

Fixed submission:
N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))


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

list1=[0]
L=0
for a in A:
    L=gcd(L,a)
    list1.append(L)

list2=[0]
R=0
for a in reversed(A):
    R=gcd(R,a)
    list2.append(R)

list2.reverse()

ans=[]

for i in range(N):
    ans.append(gcd(list1[i],list2[i+1]))

print(max(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))
C=A[:]
C=list(set(C))

#print(A)
#print(C)
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

anslist=[]

if len(C)==1:
  ans=C[0]

elif len(C)==2:
  sol=max(C[0],C[1])

else:
  for i in range(3):
    B=A[:]
    B.remove(C[i])
    sol=0
    for b in B:
        sol=gcd(sol,b)
    anslist.append(sol)
    ans=max(anslist)

#print(anslist)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))
C=list(set(A))

#print(A)
#print(C)
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

anslist=[]

if len(C)==1:
  ans=C[0]

elif len(C)==2:
  sol=max(A[0],A[1])

else:
  for i in range(3):
    B=A[:]
    B.remove(C[i])
    sol=0
    for b in B:
        sol=gcd(sol,b)
    anslist.append(sol)
    ans=max(anslist)

#print(anslist)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))
C=list(set(A))

#print(A)
print(C)
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

anslist=[]

if len(C)==1:
  ans=C[0]

elif len(C)==2:
  sol=max(A[0],A[1])

else:
  for i in range(3):
    B=A[:]
    B.remove(C[i])
    sol=0
    for b in B:
        sol=gcd(sol,b)
    anslist.append(sol)
    ans=max(anslist)

print(anslist)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))


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

ans=[]

for i in range(3):
    B=A[:]
    del B[i]
    sol=0
    for b in B:
        sol=gcd(sol,b)
    ans.append(sol)

print(max(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))


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

ans=[]

for i in range(3):
    B=A[:]
    del B[i]
    sol=0
    for b in B:
        sol=gcd(sol,b)
    ans.append(sol)

print(ans)
print(max(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))
A=list(set(A))

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

l1=[]
l2=[]
l3=[]

if len(A)==1:
    ans=A[0]

elif len(A)==2:
    ans=max(A)

elif len(A)==2:
    a=gcd(A[0],A[1])
    b=gcd(A[0],A[2])
    c=gcd(A[2],A[1])
    ans=max([a,b,c])

else:
    a=A[0]
    b=A[1]
    if gcd(a,b)==1:
        a=A[2]
        b=A[4]
    
    for x in A:
        l1.append(gcd(gcd(x,a),b))

print(max(l1))

Buggy submission (verdict: Runtime Error):
N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))
A=list(set(A))

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

l1=[]
l2=[]
l3=[]


if len(A)==2:
    ans=max(A)

else:
    a=A[0]
    b=A[1]
    if gcd(a,b)==1:
        a=A[2]
        b=A[4]
    
    for x in A:
        l1.append(gcd(gcd(x,a),b))

print(max(l1))

Buggy submission (verdict: Runtime Error):
N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))


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

list1=[0]
L=0
for a in A:
    L=gcd(L,a)
    list1.append(L)

list2=[0]
R=0
for a in reversed(A):
    R=gcd(R,a)
    list2.append(R)

list2.reverse()

ans=[]

for i in range(N+1):
    ans.append(gcd(list1[i],list2[i+1]))

print(max(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))
A.sorted()

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

list_koyaku1=[]
list_koyaku11=[]       
         
if N==2:
    ans=max(A)

else:
    b=min(A)
    c=max(A)
    if gcd(c,b)==1:
        b=A[-2]
    
    for a in A:
        list_koyaku1.append(gcd(a,b))

    for a in list_koyaku1:
        list_koyaku11.append(gcd(a,c))
    
    number_prime=list_koyaku11.count(1)
    
    if number_prime>1:
        ans=1
    else:
        ans=max(list_koyaku11)

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))
A.argsort()

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

list_koyaku1=[]
list_koyaku11=[]       
         
if N==2:
    ans=max(A)

else:
    b=min(A)
    c=max(A)
    if gcd(c,b)==1:
        b=A[-2]
    
    for a in A:
        list_koyaku1.append(gcd(a,b))

    for a in list_koyaku1:
        list_koyaku11.append(gcd(a,c))
    
    number_prime=list_koyaku11.count(1)
    
    if number_prime>1:
        ans=1
    else:
        ans=max(list_koyaku11)

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))

list_koyaku1=[]
list_koyaku11=[]       
         
if N==2:
    ans=max(A)

else:
    b=min(A)
    c=max(A)
    for a in A:
        list_koyaku1.append(gcd(a,b))

    for a in list_koyaku1:
        list_koyaku11.append(gcd(a,c))
    ans=max(list_koyaku11)