Problem p03061 (python)

Fixed submission:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


n = int(input())
a = list(map(int, input().split()))

l = [0]*(n+2)
r = [0]*(n+2)
m = [0]*(n+2)

for i in range(n+1):
    j = n-i
    if i == 0:  # j = n
        l[i] = 0
        r[j+1] = 0
    else:
        l[i] = gcd(l[i-1], a[i-1])
        r[j] = gcd(r[j+1], a[j])

m = [gcd(l[i], r[i+1]) for i in range(n+1)]

print(max(m))

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
a = list(map(int, input().split()))

l = [0]*(n+2)
r = [0]*(n+2)
m = [0]*(n+2)

for i in range(n+1):
    j = n-i
    if i == 0:  # j = n
        l[i] = 0
        r[j+1] = 0
    else:
        l[i] = math.gcd(l[i-1], a[i-1])
        r[j] = math.gcd(r[j+1], a[j])

m = [math.gcd(l[i], r[i+1]) for i in range(n+1)]

print(max(m))

Buggy submission (verdict: Runtime Error):
import math
import random


n = int(input())
a = list(map(int, input().split()))

l = [0]*(n+2)
r = [0]*(n+2)
m = [0]*(n+2)

for i in range(n+1):
    j = n-i
    if i == 0:  # j = n
        l[i] = 0
        r[j+1] = 0
    else:
        l[i] = math.gcd(l[i-1], a[i-1])
        r[j] = math.gcd(r[j+1], a[j])

m = [math.gcd(l[i], r[i+1]) for i in range(n+1)]

print(max(m))




#
# tmpgcd = list()
#
# for i in range(2):
#     sample = random.choices(a, k=2)
#     tmpgcd.append(computeGCD(sample[0], sample[1]))
# tmpgcd = sorted(tmpgcd)
#
# # print('hey')
#
# mini = tmpgcd[1]
#
#
# def computeGCD(x, y):
#     if x > y:
#         small = y
#     else:
#         small = x
#     for i in range(1, small + 1):
#         if ((x % i == 0) and (y % i == 0)):
#             gcd = i
#
#     return gcd
# # print(mini, tmpgcd)
# result = 0
# for i in range(mini, -1, -1):
#     tmp = [x % i for x in a]
#     tmp = [x for x in tmp if x != 0]
#     if len(tmp) <= 1:
#         result = i
#         break
#
# print(result)
#
#
#
#
#
#

Buggy submission (verdict: Runtime Error):
import math
import random

def computeGCD(x, y):
    if x > y:
        small = y
    else:
        small = x
    for i in range(1, small + 1):
        if ((x % i == 0) and (y % i == 0)):
            gcd = i

    return gcd


n = int(input())
a = list(map(int, input().split()))

tmpgcd = list()
for i in range(2):
    sample = random.choices(a, k=2)
    tmpgcd.append(computeGCD(sample[0], sample[1]))

# print('hey')

tmpgcd = sorted(tmpgcd)
mini = tmpgcd[1]
# print(mini, tmpgcd)
result = 0
for i in range(mini, -1, -1):
    tmp = [x % i for x in a]
    tmp = [x for x in tmp if x != 0]
    if len(tmp) <= 1:
        result = i
        break

print(result)

Buggy submission (verdict: Runtime Error):
import math
import random

n = int(input())
a = list(map(int, input().split()))

tmpgcd = list()
for i in range(2):
    sample = random.choices(a, k=2)
    tmpgcd.append(math.gcd(sample[0], sample[1]))

# print('hey')

tmpgcd = sorted(tmpgcd)
mini = tmpgcd[1]
# print(mini, tmpgcd)
result = 0
for i in range(mini, -1, -1):
    tmp = [x % i for x in a]
    tmp = [x for x in tmp if x != 0]
    if len(tmp) <= 1:
        result = i
        break

print(result)

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


n = int(input())
a = list(map(int, input().split()))

tmpgcd = list()
for i in range(2):
    sample = random.choices(a, k=2)
    tmpgcd.append(math.gcd(sample[0], sample[1]))

# print('hey')

tmpgcd = sorted(tmpgcd)
mini = tmpgcd[1]
# print(mini, tmpgcd)
result = 0
for i in range(mini, -1, -1):
    tmp = [x % i for x in a]
    tmp = [x for x in tmp if x != 0]
    if len(tmp) <= 1:
        result = i
        break

print(result)

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


n = int(input())
a = list(map(int, input().split()))

result = 0
for i in range(n):
    withoutI = a[:i]+a[i+1:]
    tmp = reduce(math.gcd, withoutI)
    if tmp > result:
        result = tmp

print(result)

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


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


n = int(input())
a = list(map(int, input().split()))

result = 0
for i in range(n):
    withoutI = a[:i]+a[i+1:]
    tmp = gcd_list(withoutI)
    if tmp > result:
        result = tmp

print(result)