Problem p03061 (python)

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

    if(a < b):
        a, b = b, a
    r = a % b
    while(r != 0):
        a, b = b, r
        r = a % b
    return b

def L(end_i, A):
    if(end_i == 0):
        return 0
    
    a = 0
    for i in range(end_i):
        a = gcd(a, A[i])
    return a


def R(start_i, A, N):
    if(start_i == N - 1):
        return 0

    a = 0
    for i in range(start_i + 1, N):
        a = gcd(a, A[i])
    return a


N = int(input())
A = list(map(int, input().split(' ')))

left = [0] * N
right = [0] * N

for i in range(1, N):
    left[i] = gcd(left[i - 1], A[i - 1])
#print(left)

for i in reversed(range(0, N - 1)):
    right[i] = gcd(A[i + 1], right[i + 1])
#print(right)

M = []
for i in range(N):
    M.append(gcd(left[i], right[i]))
#print(M)

print(max(M))

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    if(a == 0):
        return b
    if(b == 0):
        return a

    if(a < b):
        a, b = b, a
    r = a % b
    while(r != 0):
        a, b = b, r
        r = a % b
    return b

def L(i, A):
    if(i == -1):
        return 0
    return gcd(L(i - 1, A), A[i])

def R(i, A, N):
    if(i == N):
        return 0
    return gcd(R(i + 1, A, N), A[i])

N = int(input())
A = list(map(int, input().split(' ')))

M = []
for i in range(N):
    M.append(gcd(L(i - 1, A), R(i + 1, A, N)))

print(max(M))

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    if(a == 0):
        return b
    if(b == 0):
        return a

    if(a < b):
        a, b = b, a
    r = a % b
    while(r != 0):
        a, b = b, r
        r = a % b
    return b

def L(i, A):
    if(i == -1):
        return 0
    return gcd(L(i - 1, A), A[i])

def R(i, A, N):
    if(i == N):
        return 0
    return gcd(R(i + 1, A, N), A[i])

N = int(input())
A = list(map(int, input().split(' ')))

M = []
for i in range(N):
    M.append(gcd(L(i - 1, A), R(i + 1, A, N)))

print(max(M))

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    if(a == 0):
        return b
    if(b == 0):
        return a

    if(a < b):
        a, b = b, a
    r = a % b
    while(r != 0):
        a, b = b, r
        r = a % b
    return b

def L(i, A):
    if(i == 0):
        return 0
    return gcd(L(i - 1, A), A[i])

def R(i, A, N):
    if(i == N):
        return 0
    return gcd(R(i + 1, A, N), A[i])

N = int(input())
A = list(map(int, input().split(' ')))

M = []
for i in range(N):
    M.append(gcd(L(i, A), R(i + 1, A, N)))

print(max(M))

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    if(a == 0):
        return b
    if(b == 0):
        return a

    if(a < b):
        a, b = b, a
    r = a % b
    while(r != 0):
        a, b = b, r
        r = a % b
    return b

def L(i, A):
    if(i == 0):
        return 0
    return gcd(L(i - 1, A), A[i - 1])

def R(i, A, N):
    if(i == N):
        return 0
    return gcd(R(i + 1, A, N), A[i])

N = int(input())
A = list(map(int, input().split(' ')))

M = []
for i in range(N):
    M.append(gcd(L(i, A), R(i + 1, A, N)))

print(max(M))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = input().split(' ')

for i in range(N):
    A[i] = int(A[i])

max = A.max

flag = 0
for term in A:

    count = 0

    for i in range(N):
        if(A[i] % term != 0):
            count += 1
        if(count == 2):
            break

    if(count <= 1):
        flag = 1
        break

if(flag == 1):
    print(term)
else:
    for term in reversed(range(0, max)):

        count = 0

        for i in range(N):
            if(A[i] % term != 0):
                count += 1
            if(count == 2):
                break

        if(count <= 1):
            break

    print(term)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = input().split(' ')

for i in range(N):
    A[i] = int(A[i])

A.sort()
A.reverse()

flag = 0
for term in A:

    count = 0

    for i in range(N):
        if(A[i] % term != 0):
            count += 1
        if(count == 2):
            break

    if(count <= 1):
        flag = 1
        break

if(flag == 1):
    print(term)
else:
    for term in reversed(range(0, A[-1])):

        count = 0

        for i in range(N):
           if(A[i] % term !=0):
                count += 1
            if(count == 2):
                break

        if(count <= 1):
            break

    print(term)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = input().split(' ')

for i in range(N):
    A[i] = int(A[i])

A.sort()
A.reverse()

max = A[0]
min = A[-1]

flag = 0
for term in A:

    count = 0

    for i in range(N):
        if(A[i] % term != 0):
            count += 1
        if(count == 2):
            break

    if(count <= 1):
        flag = 1
        break

if(flag == 1):
    print(term)

for term in reversed(range(0, A[-1])):

    count = 0

    for i in range(N):
        if(A[i] % term !=0):
            count += 1
        if(count == 2):
            break

    if(count <= 1):
        break

print(term)