Buggy python submission (verdict: Time Limit Exceeded):

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


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

if N == 2:
  print(max(A))
else:
  m = -1
  for i in range(N):
    G = 0
    for j in range(0, i):
      G = gcd(G, A[j])
    for j in range(i+1, N):
      G = gcd(G, A[j])

    m = max(m, G)
  print(m)

Fixed submission:

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


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

if N == 2:
  print(max(A))
else:

  L = [0 for j in range(N+1)]
  R = [0 for j in range(N+1)]
  
  for j in range(N):
    L[j+1] = gcd(L[j], A[j])
  for j in reversed(range(N)):
    R[j] = gcd(R[j+1], A[j])

    m = -1
  for j in range(N):
    m = max(m, gcd(L[j], R[j+1]))
  print(m)

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

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

def list_gcd(l):
    if len(l) == 0:
      return 0
    elif len(l) == 1:
      return l[0]
    elif len(l) == 2:
      return gcd(l[0], l[1])
    else:
      m = l[1:]
      return gcd(l[0], list_gcd(m))

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

if N == 2:
  print(max(A))
else:
  m = -1
  for i in range(N):
    L = [A[j] for j in range(0, i)]
    R = [A[j] for j in range(i+1, N)]
    m = max(m, gcd(list_gcd(L),list_gcd(R)))
  print(m)

Fixed submission:

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


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

if N == 2:
  print(max(A))
else:

  L = [0 for j in range(N+1)]
  R = [0 for j in range(N+1)]
  
  for j in range(N):
    L[j+1] = gcd(L[j], A[j])
  for j in reversed(range(N)):
    R[j] = gcd(R[j+1], A[j])

    m = -1
  for j in range(N):
    m = max(m, gcd(L[j], R[j+1]))
  print(m)

Buggy python submission (verdict: Runtime Error):
import fractions

def list_gcd(l):
    if len(l) == 0:
      return 0
    elif len(l) == 1:
      return l[0]
    elif len(l) == 2:
      return fractions.gcd(l[0], l[1])
    else:
      m = l[1:]
      return fractions.gcd(l[0],list_gcd(m))

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

if N == 2:
  print(max(A))
else:
  m = -1
  for i in range(N):
    L = [A[j] for j in range(0, i)]
    R = [A[j] for j in range(i+1, N)]
    m = max(m, fractions.gcd(list_gcd(L),list_gcd(R)))
  print(m)

Fixed submission:

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


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

if N == 2:
  print(max(A))
else:

  L = [0 for j in range(N+1)]
  R = [0 for j in range(N+1)]
  
  for j in range(N):
    L[j+1] = gcd(L[j], A[j])
  for j in reversed(range(N)):
    R[j] = gcd(R[j+1], A[j])

    m = -1
  for j in range(N):
    m = max(m, gcd(L[j], R[j+1]))
  print(m)

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

def gcd(l):
    if len(l) == 0:
      return 0
    elif len(l) == 1:
      return l[0]
    elif len(l) == 2:
      return math.gcd(l[0], l[1])
    else:
      m = l[1:]
      return math.gcd(l[0],gcd(m))

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

if N == 2:
  print(max(A))
else:
  m = -1
  for i in range(N):
    L = [A[j] for j in range(0, i)]
    R = [A[j] for j in range(i+1, N)]
    m = max(m, math.gcd(gcd(L),gcd(R)))
  print(m)

Fixed submission:

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


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

if N == 2:
  print(max(A))
else:

  L = [0 for j in range(N+1)]
  R = [0 for j in range(N+1)]
  
  for j in range(N):
    L[j+1] = gcd(L[j], A[j])
  for j in reversed(range(N)):
    R[j] = gcd(R[j+1], A[j])

    m = -1
  for j in range(N):
    m = max(m, gcd(L[j], R[j+1]))
  print(m)

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

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

if N == 2:
  print(max(A))
else:
  G = math.gcd(A[0], A[1])
  H = math.gcd(A[1], A[2])
  I = math.gcd(A[2], A[0])

  print(max(G, H, I))

Fixed submission:

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


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

if N == 2:
  print(max(A))
else:

  L = [0 for j in range(N+1)]
  R = [0 for j in range(N+1)]
  
  for j in range(N):
    L[j+1] = gcd(L[j], A[j])
  for j in reversed(range(N)):
    R[j] = gcd(R[j+1], A[j])

    m = -1
  for j in range(N):
    m = max(m, gcd(L[j], R[j+1]))
  print(m)

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

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

if N == 2:
  print(max(A))
  exit()

G = math.gcd(A[0], A[1])
H = math.gcd(A[1], A[2])
I = math.gcd(A[2], A[0])

print(max(G, H, I))

Fixed submission:

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


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

if N == 2:
  print(max(A))
else:

  L = [0 for j in range(N+1)]
  R = [0 for j in range(N+1)]
  
  for j in range(N):
    L[j+1] = gcd(L[j], A[j])
  for j in reversed(range(N)):
    R[j] = gcd(R[j+1], A[j])

    m = -1
  for j in range(N):
    m = max(m, gcd(L[j], R[j+1]))
  print(m)

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

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

M = max(A)
ans = 1

G = math.gcd(A[0], A[1])
for i in range(2, N):
  G = math.gcd(G, A[i])

for i in reversed(range(G, M+1, G)):
  l = 0
  for j in range(N):
    if A[j] % i > 0:
      l += 1
  
  if l <= 1:
    ans = i
    break

print(ans)

Fixed submission:

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


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

if N == 2:
  print(max(A))
else:

  L = [0 for j in range(N+1)]
  R = [0 for j in range(N+1)]
  
  for j in range(N):
    L[j+1] = gcd(L[j], A[j])
  for j in reversed(range(N)):
    R[j] = gcd(R[j+1], A[j])

    m = -1
  for j in range(N):
    m = max(m, gcd(L[j], R[j+1]))
  print(m)

Buggy python submission (verdict: Time Limit Exceeded):
import math

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

M = max(A)
ans = 1

for i in reversed(range(2, M+1)):
  l = 0
  for j in range(N):
    if A[j] % i > 0:
      l += 1
  
  if l <= 1:
    ans = i
    break

print(ans)

Fixed submission:

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


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

if N == 2:
  print(max(A))
else:

  L = [0 for j in range(N+1)]
  R = [0 for j in range(N+1)]
  
  for j in range(N):
    L[j+1] = gcd(L[j], A[j])
  for j in reversed(range(N)):
    R[j] = gcd(R[j+1], A[j])

    m = -1
  for j in range(N):
    m = max(m, gcd(L[j], R[j+1]))
  print(m)