Problem p03061 (python)

Fixed submission:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return int(a)
    
n = int(input())
a = list(map(int, input().split()))
if n==2:
  print(max(a))
  sys.exit(0)
elif n==3:
  lis = [gcd(a[0], a[1]), gcd(a[1], a[2]), gcd(a[2], a[0])]
  print(max(lis))
  sys.exit(0)
tmp_unused = gcd(a[0], a[1])
tmp_used = max(a[0], a[1])
#print("used=", tmp_used, "unused=", tmp_unused)
for i in range(2,n):
  #print(a[i])
  tmp_used = max(tmp_unused, gcd(tmp_used, a[i]))
  tmp_unused = gcd(tmp_unused, a[i])
  
  #print("used=", tmp_used, "unused=", tmp_unused)
print(tmp_used)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
def list_euclid(int_list):
    ans = int_list[0]
    for i in range(1,len(int_list)):
        ans = euclid(ans, int_list[i])
        if ans == 1:
            return ans
    return ans
n = int(input())
a = list(map(int, input().split()))
a.sort()
max = 0
b_int = 0
min = 1
if n < 5:
    for i in range(0,n):
        if b_int == a[0]:
            p = a.pop(0)
            a.append(p)
        else:
            p = a.pop(0)
            b_int = p
            x = list_euclid(a)
        if max < x:
            max = x
            a.append(p)
else:
    for i in range(0,n):
        if b_int == a[0]:
            p = a.pop(0)
            # a.append(p)
        else:
            if max == 0:
                p = a.pop(0)
                b_int = p
                k = len(a) // 2
                x = 0
                y = list_euclid(a[0:k])
                if y == 1:
                    x = 1
                else:
                    z = list_euclid(a[k:len(a)])
                    x = euclid(y, z)
                if max < x:
                    max = x
                a.append(p)
                min = p
            elif min <= max:
                break
            else:
                p = a.pop(0)
                b_int = p
                k = len(a) // 2
                x = 0
                y = list_euclid(a[0:k])
                if y == 1:
                    x = 1
                else:
                    z = list_euclid(a[k:len(a)])
                    x = euclid(y, z)
                if max < x:
                    max = x
                a.append(p)
print(max)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
def list_euclid(int_list):
    ans = int_list[0]
    for i in range(1,len(int_list)):
        ans = euclid(ans, int_list[i])
        if ans == 1:
            return ans
    return ans
n = int(input())
a = list(map(int, input().split()))
a.sort()
max = 0
b_int = 0
min = 1
if n < 5:
    for i in range(0,n):
        if b_int == a[0]:
            p = a.pop(0)
            # a.append(p)
        else:
            p = a.pop(0)
            b_int = p
            x = list_euclid(a)
        if max < x:
            max = x
            a.append(p)
else:
    for i in range(0,n):
        if b_int == a[0]:
            p = a.pop(0)
            # a.append(p)
        else:
            if max == 0:
                p = a.pop(0)
                b_int = p
                k = len(a) // 2
                x = 0
                y = list_euclid(a[0:k])
                if y == 1:
                    x = 1
                else:
                    z = list_euclid(a[k:len(a)])
                    x = euclid(y, z)
                if max < x:
                    max = x
                a.append(p)
                min = p
            elif min <= max:
                break
            else:
                p = a.pop(0)
                b_int = p
                k = len(a) // 2
                x = 0
                y = list_euclid(a[0:k])
                if y == 1:
                    x = 1
                else:
                    z = list_euclid(a[k:len(a)])
                    x = euclid(y, z)
                if max < x:
                    max = x
                a.append(p)
print(max)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
def list_euclid(int_list):
    ans = int_list[0]
    for i in range(1,len(int_list)):
        ans = euclid(ans, int_list[i])
        if ans == 1:
            return ans
    return ans
n = int(input())
a = list(map(int, input().split()))
a.sort()
max = 0
b_int = 0
min = 1
if n < 5:
    for i in range(0,n):
        if b_int == a[0]:
            p = a.pop(0)
            # a.append(p)
        else:
            p = a.pop(0)
            b_int = p
            x = list_euclid(a)
        if max < x:
            max = x
            a.append(p)
else:
    for i in range(0,n):
        if b_int == a[0]:
            p = a.pop(0)
            # a.append(p)
        else:
            if max == 0:
                p = a.pop(0)
                b_int = p
                k = len(a) // 2
                x = 0
                y = list_euclid(a[0:k])
                if y == 1:
                    x = 1
                else:
                    z = list_euclid(a[k:len(a)])
                    x = euclid(y, z)
                if max < x:
                    max = x
                a.append(p)
                print(a)
                min = p
            elif min <= max:
                break
            else:
                p = a.pop(0)
                b_int = p
                k = len(a) // 2
                x = 0
                y = list_euclid(a[0:k])
                if y == 1:
                    x = 1
                else:
                    z = list_euclid(a[k:len(a)])
                    x = euclid(y, z)
                if max < x:
                    max = x
                a.append(p)
print(max)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
def list_euclid(int_list):
    ans = int_list[0]
    for i in range(1,len(int_list)):
        ans = euclid(ans, int_list[i])
        if ans == 1:
            return ans
    return ans
n = int(input())
a = list(map(int, input().split()))
a.sort()
max = 0
b_int = 0
if n < 5:
  for i in range(0,n):
    if b_int == a[0]:
      p = a.pop(0)
      a.append(p)
    else:
      p = a.pop(0)
      b_int = p
      x = list_euclid(a)
      if max < x:
        max = x
      a.append(p)
else:
  for i in range(0,n):
    if b_int == a[0]:
      p = a.pop(0)
      # a.append(p)
    else:
      p = a.pop(0)
      b_int = p
      k = len(a) // 2
      x = 0
      y = list_euclid(a[0:k])
      if y == 1:
        x = 1
      else:
        z = list_euclid(a[k:n-1])
        x = euclid(y, z)
      if max < x:
        max = x
      a.append(p)
print(max)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
def list_euclid(int_list):
    ans = int_list[0]
    for i in range(1,len(int_list)):
        ans = euclid(ans, int_list[i])
        if ans == 1:
            return ans
    return ans
n = int(input())
a = list(map(int, input().split()))
a.sort()
max = 0
b_int = 0
if n < 10:
  for i in range(0,n):
    if b_int == a[0]:
      p = a.pop(0)
      # a.append(p)
    else:
      p = a.pop(0)
      b_int = p
      x = list_euclid(a)
      if max < x:
        max = x
      a.append(p)
else:
  for i in range(0,n):
    if b_int == a[0]:
      p = a.pop(0)
      # a.append(p)
    else:
      p = a.pop(0)
      b_int = p
      k = len(a) // 2
      x = 0
      y = list_euclid(a[0:k])
      if y == 1:
        x = 1
      else:
        z = list_euclid(a[k:n-1])
        x = euclid(y, z)
      if max < x:
        max = x
      a.append(p)
print(max)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
def list_euclid(int_list):
    ans = int_list[0]
    for i in range(1,len(int_list)):
        ans = euclid(ans, int_list[i])
        if ans == 1:
            return ans
    return ans
n = int(input())
a = list(map(int, input().split()))
a.sort()
max = 0
b_int = 0
if n < 5:
  for i in range(0,n):
    if b_int == a[0]:
      p = a.pop(0)
      # a.append(p)
    else:
      p = a.pop(0)
      b_int = p
      x = list_euclid(a)
      if max < x:
        max = x
      a.append(p)
else:
  for i in range(0,n):
    if b_int == a[0]:
      p = a.pop(0)
      # a.append(p)
    else:
      p = a.pop(0)
      b_int = p
      k = len(a) // 2
      x = 0
      y = list_euclid(a[0:k])
      if y == 1:
        x = 1
      else:
        z = list_euclid(a[k:n-1])
        x = euclid(y, z)
      if max < x:
        max = x
      a.append(p)
print(max)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
def list_euclid(int_list):
    ans = int_list[0]
    for i in range(1,len(int_list)):
        ans = euclid(ans, int_list[i])
        if ans == 1:
            return ans
    return ans
n = int(input())
a = list(map(int, input().split()))
a.sort()
max = 0
b_int = 0
if n < 5:
  for i in range(0,n):
    if b_int == a[0]:
      p = a.pop(0)
      a.append(p)
    else:
      p = a.pop(0)
      b_int = p
      x = list_euclid(a)
      if max < x:
        max = x
      a.append(p)
else:
  for i in range(0,n):
    if b_int == a[0]:
      p = a.pop(0)
      a.append(p)
    else:
      p = a.pop(0)
      b_int = p
      k = n // 2
      x = 0
      y = list_euclid(a[0:k])
      if y == 1:
        x = 1
      else:
        z = list_euclid(a[k:n-1])
        x = euclid(y, z)
      if max < x:
        max = x
        a.append(p)
print(max)