Problem p03061 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100001)

def gcd(b, s):
    return s if b % s == 0 else gcd(s, b % s)

# 一人消してgcd
n = int(input())
nl = sorted(list(map(int, input().split(' '))))
rl = nl[::-1]
sumnl = [nl[0]]
sumrl = [rl[0]]
for i in range(1, len(nl)):
    sumnl.append(gcd(sumnl[-1], nl[i]))
    sumrl.append(gcd(sumrl[-1], rl[i]))
sumrl = sumrl[::-1]
if len(sumnl) == 1:
    print(sumnl[0])
else:
    print(max([sumnl[-2]] + [gcd(sumnl[i],sumrl[i+2]) for i in range(len(sumrl) - 2)] + [sumrl[1]]))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100001)

def gcd(b, s):
    return s if b % s == 0 else gcd(s, b % s)

# 一人消してgcd
n = int(input())
nl = sorted(list(map(int, input().split(' '))))
rl = nl[::-1]
sumnl = [nl[0]]
sumrl = [rl[0]]
for i in range(1, len(nl)):
    sumnl.append(gcd(sumnl[-1], nl[i]))
    sumrl.append(gcd(sumrl[-1], rl[i]))
sumrl = sumrl[::-1]
if len(sumnl) == 1:
    print(sumnl[0])
else:
    print(max([gcd(sumnl[i],sumrl[i+2]) for i in range(len(sumrl) - 2)]))

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

# 一人消してgcd
n = int(input())
nl = sorted(list(map(int, input().split(' '))))
rl = nl[::-1]
sumnl = [nl[0]]
sumrl = [rl[0]]
for i in range(1, len(nl)):
    sumnl.append(gcd(sumnl[-1], nl[i]))
    sumrl.append(gcd(sumrl[-1], rl[i]))
sumrl = sumrl[::-1]
print(max([gcd(sumnl[i],sumrl[i+2]) for i in range(len(sumrl) - 2)]))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100001)
 
# 一人消してgcd
n = int(input())
l = sorted(list(map(int, input().split(' '))))
def gcd(b, s):
  return s if b % s == 0 else gcd(s, b % s)
 
memo = {}
mmm = 0
def ggcd(l, i, skip, current):
  global mmm
  if i == len(l) or current == 1 or current <= mmm:
    if mmm < current:
      mmm = current
    return current
  key = (i, skip)
  if key not in memo:
    if i == skip:
      memo[key] = ggcd(l, i+1, skip, current)
    else:
      memo[key] = ggcd(l, i+1, skip, gcd(l[i], current))
  return memo[key]
if len(l) == 1:
  print(l[0])
else:
  [ggcd(l, 0, skip, l[1] if skip == 0 else l[0]) for skip in range(len(l))]
  print(mmm)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100001)
 
# 一人消してgcd
n = int(input())
l = sorted(list(map(int, input().split(' '))))
def gcd(b, s):
  return s if b % s == 0 else gcd(s, b % s)
 
memo = {}
mmm = 0
def ggcd(l, i, skip, current):
  global mmm
  if i == len(l) or current == 1 or current <= mmm:
    if mmm < current:
      mmm = current
    return current
  key = (i, skip)
  if key not in memo:
    if i == skip:
      memo[key] = ggcd(l, i+1, skip, current)
    else:
      memo[key] = ggcd(l, i+1, skip, gcd(l[i], current))
  return memo[key]
[ggcd(l, 0, skip, l[1] if skip == 0 else l[0]) for skip in range(len(l))]
print(mmm)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100001)

# 一人消してgcd
n = int(input())
l = sorted(list(map(int, input().split(' '))))
def gcd(b, s):
  return s if b % s == 0 else gcd(s, b % s)

memo = {}
mmm = 0
def ggcd(l, i, skip, current):
  global mmm
  if i == len(l) or current == 1 or current <= mmm:
    if mmm < current:
      mmm = current
    return current
  key = (i, skip, current)
  if key not in memo:
    if i == skip:
      memo[key] = ggcd(l, i+1, skip, current)
    else:
      memo[key] = ggcd(l, i+1, skip, gcd(l[i], current))
  return memo[key]
[ggcd(l, 0, skip, l[1] if skip == 0 else l[0]) for skip in range(len(l))]
print(mmm)