Problem:


Score : 300 points

Problem Statement

There are N integers, A_1, A_2, ..., A_N, written on the blackboard.

You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.

Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Output

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Sample Input 1

3
7 6 8

Sample Output 1

2

If we replace 7 with 4, the greatest common divisor of the three integers on the blackboard will be 2, which is the maximum possible value.

Sample Input 2

3
12 15 18

Sample Output 2

6

Sample Input 3

2
1000000000 1000000000

Sample Output 3

1000000000

We can replace an integer with itself.



Sample input:
3
7 6 8


Sample output:
2

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

ll GCD(ll a,ll b) {
  if(a > b) swap(a,b);
  while(b % a != 0) {
    b = b % a;
    swap(a,b);
  }
  return a;
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0;
  vector<vector<ll>> dp(n,vector<ll>(n-1));
  rep(i,n) {
    dp[i][0] = a[0];
    if(i == 0) dp[i][0] = a[1];
    rep(j,n) {
      int k = 0;
      if(j == i) continue;
      dp[i][k+1] = GCD(dp[i][k],a[j]);
      if(dp[i][k+1] == 1) break; 
    }
    ans = max(dp[i][n-2],ans);
  }
  cout << ans << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
from functools import reduce
from fractions import gcd
n = int(input())
A = list(map(int,input().split()))
B = A.copy()
ans1 = reduce(gcd, A)
for i in range(n-1):
  A.pop(i)
  ans = reduce(gcd, A)
  A = B
  if ans > ans1: 
    print(ans)
    exit()
print(ans1)

Submission status: Runtime Error

Solution code:

from fractions import gcd


def p_c():
    n = int(input())
    *a, = map(int, input().split())
    L = [0] * n
    R = [0] * n
    for i in range(n - 1):
        L[i] = gcd(L[i - 1], a[i])
        R[n - 1 - i] = gcd(R[(n - i) % n], a[n - 1 - i])
    ans = [gcd(L[i - 1], R[i + 1] % n) for i in range(n)]
    print(max(ans))
    
p_c()

Submission status: Runtime Error

Solution code:

from fractions import gcd


def p_c():
    from sys import stdin
    input = stdin.readline
    n = int(input())
    *a, = map(int, input().split())
    L = [0] * n
    R = [0] * n
    for i in range(1, n):
        L[i] = gcd(L[i - 1], a[i])
        R[n - 1 - i] = gcd(R[(n - i) % n], a[n - 1 - i])
    ans = [gcd(L[i - 1], R[i + 1] % n) for i in range(n)]
    print(max(ans))

p_c()

Submission status: Runtime Error

Solution code:
def gcd(x,y):
    if x<y:
        x,y = y,x
    while y>0:
        x,y = y,x%y
    return x
N = int(input())
A = list(map(int,input().split()))
cmin = 10**9
a = A[0]
for i in range(1,N):
    b = A[i]
    a = gcd(a,b)
    if a<cmin:
        ind = i
        cmin = a
a = A[(ind+1)%N]
cmin = 10**9
for i in range(N):
    if i==ind:continue
    b = A[i]
    a = gcd(a,b)
    cmin = min(cmin,a)
a = A[1]
dmin = 10**9
for i in range(2,N):
    b = A[i]
    a = gcd(a,b)
    dmin = min(dmin,a)
print(max(cmin,dmin))

Submission status: Runtime Error

Solution code:
def gcd(x, y):
    if y == 0:
        return x
    while y != 0:
        x, y = y, x % y
    return x
class segment_gcd():
    def __init__(self,A,n,num):
        #####単位元######
        self.ide_ele = 0
        self.seg = [self.ide_ele] * 2 * num
        self.num = num
        # set_val
        for i in range(n):
            self.seg[i +num -1] = A[i]
            # built
        for i in range(num - 2, -1, -1):
            self.seg[i] = gcd(self.seg[2*i +1], self.seg[2*i +2])

    def update(self,k, x):
        k += num - 1
        self.seg[k] = x
        while k:
            k = (k - 1)//2
            self.seg[k] = gcd(self.seg[k*2 +1], self.seg[k*2 +2])

    def query(self,p, q):
        num = self.num; ide_ele = self.ide_ele
        if q <= p:
            return self.ide_ele
        p += num - 1
        q += num - 2
        res = ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = gcd(res, seg[p])
            if q & 1 == 1:
                res = gcd(res, seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = gcd(res, self.seg[p])
        else:
            res = gcd(gcd(res, self.seg[p]), self.seg[q])
        return res

def examC():
    N = I()
    A = LI()
    # num:n以上の最小の2のべき乗
    num = 2 ** (N - 1).bit_length()
    Seggcd = segment_gcd(A,N,num)
    ans = -1
    for i in range(N):
        ans = max(ans, gcd(Seggcd.query(0, i), Seggcd.query(i + 1, N)))
    print(ans)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Runtime Error

Solution code:
def gcd(x, y):
    if y == 0:
        return x
    while y != 0:
        x, y = y, x % y
    return x
class segment_min():
    def __init__(self,A,n,num):
        #####単位元######
        self.ide_ele = 0
        self.seg = [self.ide_ele] * 2 * num
        self.num = num
        # set_val
        for i in range(n):
            self.seg[i +num -1] = A[i]
            # built
        for i in range(num - 2, -1, -1):
            self.seg[i] = gcd(self.seg[2*i +1], self.seg[2*i +2])

    def update(self,k, x):
        k += num - 1
        self.seg[k] = x
        while k:
            k = (k - 1)//2
            self.seg[k] = gcd(self.seg[k*2 +1], self.seg[k*2 +2])

    def query(self,p, q):
        num = self.num; ide_ele = self.ide_ele
        if q <= p:
            return self.ide_ele
        p += num - 1
        q += num - 2
        res = ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = gcd(res, seg[p])
            if q & 1 == 1:
                res = gcd(res, seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = gcd(res, self.seg[p])
        else:
            res = gcd(gcd(res, self.seg[p]), self.seg[q])
        return res

def examC():
    N = I()
    A = LI()
    # num:n以上の最小の2のべき乗
    num = 2 ** (N - 1).bit_length()
    Segmin = segment_min(A,N,num)
    ans = -1
    for i in range(N):
        ans = max(ans, gcd(Segmin.query(0, i), Segmin.query(i + 1, N)))
    print(ans)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Runtime Error

Solution code:
from itertools import accumulate
import math
import fractions

N = int(input())
A = [int(i) for i in input().split()]

#最大公約数で累積和作る
B = [0] * N
R = [0] * N
for i in range(N):
    B[i+1] = (fractions.gcd(B[i],A[i]))
    #逆向き,とったやつの反対端用   
    R[N-i -1] = (fractions.gcd(R[N-i], A[N-i -1]))
 
ans = 0
for i in range(N):
    ans = max(ans, fractions.gcd(B[i], R[i+1]))
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
import math
import fractions

N = int(input())
A = [int(i) for i in input().split()]

#最大公約数で累積和作る
B = [0] * N
R = [0] * N
for i in range(N):
    B[i+1] = (math.gcd(B[i],A[i]))
    #逆向き,とったやつの反対端用   
    R[N-i -1] = (math.gcd(R[N-i], A[N-i -1]))
 
ans = 0
for i in range(N):
    ans = max(ans, math.gcd(B[i], R[i+1]))
print(ans)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    if (a == b):
        return a
    elif (a == 0):
        return b
    elif (b == 0):
        return a
    elif (a < b):
        return gcd(a, b - a)
    elif (b < a):
        return gcd(b, a - b)


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

for e in a:
    if (len(a) <= 2):
        ans = a[0]
    else:
        a.remove(e)
        rep = a[0]

        for elem in a:
            rep = gcd(rep, elem)

        if (ans < rep):
            ans = rep

        a.append(e)

print(ans)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    if (a == b):
        return a
    elif (a == 0):
        return b
    elif (b == 0):
        return a
    elif (a < b):
        return gcd(a, b - a)
    elif (b < a):
        return gcd(b, a - b)


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

for e in a:
    if (len(a) <= 2):
        ans = a[0]
    else:
        rep = 0
        a.remove(e)

        for i in range((len(a) - 1)):
            rep = gcd(a[i + 1], a[i])
            if (rep <= ans):
                break
            else:
                ans = rep

        a.append(e)

print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

ll gcd(ll a, ll b){
  if(a < b){
    swap(a, b);
  }
  if(b == 0){
    return a;
  }
  return gcd(b, a%b);
}

int N;
vector<int> A;
int main(){
  cin >> N;
  A.resize(N);
  REP(i, N){
    cin >> A[i];
  }
  vector<int> gcd_a(N), gcd_r(N);
  int G = A[0];
  REP(i, N){
    G = gcd(G, A[i]);
    gcd_a[i] = G;
  }
  G = A.back();
  REPR(i, N-1){
    G = gcd(G, A[i]);
    gcd_r[i] = G;
  }
  int ans = 0;
  REP(i, N){
    if(i == 0){
      ans = max(ans, gcd_r[1]);
    }
    else if(i == N-1){
      ans = max(ans, gcd_a[N-2]);
    }
    else{
      ans = max(ans, (int)gcd(gcd_a[i-1], gcd_r[i+1]));
    }
  }
  cout << ans <<endl;

  return 0;
}

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from fractions import gcd
input = sys.stdin.readline
 
class DisjointSparseTable:
    def __init__(self, a):
        # Identity element
        self.e = 0
        self.level = (len(a) - 1).bit_length()
        self.size = 2**self.level
        self.table = [[self.e] * self.size for _ in range(self.level)]
        # Set bottom first
        for i, item in enumerate(a):
            self.table[-1][i] = item
        self.build()
 
    def build(self):
        for i in range(1, self.level):
            step = 2**i
            lv = self.level - 1 - i
            for mid in range(step, self.n + step, step*2):
                # Forward
                val = self.e 
                for j in range(step):
                    val = gcd(self.table[-1][mid + j], val)
                    self.table[lv][mid + j] = val
                # Backward
                val = self.e
                for j in range(step):
                    val = gcd(self.table[-1][mid - 1 - j], val)
                    self.table[lv][mid - 1 - j] = val
 
    # Returns f[l:r)
    def query(self, l, r):
        if l == r:
            return self.e
        elif l == r - 1:
            return self.table[-1][l]
        lv = self.level - (l ^ r-1).bit_length()
        return gcd(self.table[lv][l], self.table[lv][r-1])
 
 
if __name__ == "__main__":
    n = int(input())
    a = [int(item) for item in input().split()]
    DST = DisjointSparseTable(a)
    ans = 0
    for i in range(0, n):
        ans = max(ans, gcd(DST.query(0, i), DST.query(i+1, n)))
    print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from fractions import gcd
input = sys.stdin.readline
 
class DisjointSparseTable:
    def __init__(self, a):
        # Identity element
        self.e = 0
        self.level = (len(a) - 1).bit_length()
        self.size = 2**self.level
        self.table = [[self.e] * self.size for _ in range(self.level)]
        # Set bottom first
        for i, item in enumerate(a):
            self.table[-1][i] = item
        self.build()
 
    def build(self):
        for i in range(1, self.level):
            step = 2**i
            lv = self.level - 1 - i
            for mid in range(step, self.size, step*2):
                if mid - step >= self.n:
                    continue
                # Forward
                val = self.e 
                for j in range(step):
                    val = gcd(self.table[-1][mid + j], val)
                    self.table[lv][mid + j] = val
                # Backward
                val = self.e
                for j in range(step):
                    val = gcd(self.table[-1][mid - 1 - j], val)
                    self.table[lv][mid - 1 - j] = val
 
    # Returns f[l:r)
    def query(self, l, r):
        if l == r:
            return self.e
        elif l == r - 1:
            return self.table[-1][l]
        lv = self.level - (l ^ r-1).bit_length()
        return gcd(self.table[lv][l], self.table[lv][r-1])
 
 
if __name__ == "__main__":
    n = int(input())
    a = [int(item) for item in input().split()]
    DST = DisjointSparseTable(a)
    ans = 0
    for i in range(0, n):
        ans = max(ans, gcd(DST.query(0, i), DST.query(i+1, n)))
    print(ans)

Submission status: Runtime Error

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


def check(num):
	cnt = 0
	cond = True

	for i in range(N):
		if A[i] % num != 0:
			cnt += 1
		if cnt > 1:
			cond = False
			break

	return cond

def BinarySearch(s,l):
	if s == l:
		return s
	if s+1 == l:
		if check(l):
			return l
		elif check(s):
			return s

	center = s + (l-s)//2
	
	if check(center):
		return BinarySearch(center, l)
	else:
		return BinarySearch(s, center-1)

print(BinarySearch(0, max(A))

Submission status: Runtime Error

Solution code:
import fractions
n = int(input())

al = list(map(int,input().split()))

front_gcd = []

a_init = al[0]
for a in al:
    a_init = fractions.gcd(a, a_init)
    front_gcd.append(a_init)
    
back_gcd = []

b_init = al[-1]
for b in al[::-1]:
    b_init = fractions.gcd(b, b_init)
    back_gcd.append(b_init)
    
back_gcd = back_gcd[::-1]

ans = 1
for i in range(n):
    if i == 0:
        x = back_gcd[1]
    elif i == n-1:
        x = front_gcd[-2]
    else:
        x = fractions.gcd(front_gcd[i-1], back_gcd[i+1])
    if gcd > ans:
        ans = x

print(ans)

Submission status: Runtime Error

Solution code:
from fractions import gcd
n = int(input())

al = list(map(int,input().split()))

front_gcd = []

a_init = al[0]
for a in al:
    a_init = gcd(a, a_init)
    front_gcd.append(a_init)
    
back_gcd = []

b_init = al[-1]
for b in al[::-1]:
    b_init = gcd(b, b_init)
    back_gcd.append(b_init)
    
back_gcd = back_gcd[::-1]

ans = 1
for i in range(n):
    if i == 0:
        gcd = back_gcd[1]
    elif i == n-1:
        gcd = front_gcd[-2]
    else:
        gcd = gcd(front_gcd[i-1], back_gcd[i+1])
    if gcd > ans:
        ans = gcd

print(ans)

Submission status: Runtime Error

Solution code:
import math
n = int(input())

al = list(map(int,input().split()))

front_gcd = []

a_init = al[0]
for a in al:
    a_init = math.gcd(a, a_init)
    front_gcd.append(a_init)
    
back_gcd = []

b_init = al[-1]
for b in al[::-1]:
    b_init = math.gcd(b, b_init)
    back_gcd.append(b_init)
    
back_gcd = back_gcd[::-1]

ans = 1
for i in range(n):
    if i == 0:
        gcd = back_gcd[1]
    elif i == n-1:
        gcd = front_gcd[-2]
    else:
        gcd = math.gcd(front_gcd[i-1], back_gcd[i+1])
    if gcd > ans:
        ans = gcd

print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

n = int(input())
a = [int(_) for _ in input().split()]
ans = 0

for i in range(n):
    r = reduce(math.gcd, a[:i] + a[i+1:])
    if ans < r:
        ans = r

print(ans)

Submission status: Runtime Error

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

l=[]
l.append(0)
l.append(0)
r=[]
r.append(a[n-1])
r.append(a[n-1])
g=[]

def gcd(x,y):
  if x%y==0:
    return y
  else:
    return gcd(y,x%y)


for i in range(1,n):
  l.append(gcd(l[i],a[i-1]))
  r.append(gcd(r[i],a[n-1-i]))
  
r[0]=0

for j in range(0,n):
  g.append(gcd(l[j+1],r[n-j-1]))

print(max(g))

Submission status: Runtime Error

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

l=[]
l.append(0)
l.append(0)
r=[]
r.append(0)
r.append(a[n-1])
g=[]

def gcd(x,y):
  if x%y==0:
    return y
  else:
    return gcd(y,x%y)


for i in range(1,n):
  l.append(gcd(l[i],a[i-1]))
  r.append(gcd(r[i],a[n-1-i]))
  
  
for j in range(0,n):
  g.append(gcd(l[j+1],r[n-j-1]))

print(max(g))

Submission status: Runtime Error

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

l=[]
l.append(a[0])
r=[]
r.append(a[n-1])
g=[]

def gcd(x,y):
  if x%y==0:
    return y
  else:
    return gcd(y,x%y)


for i in range(1,n):
  l.append(gcd(l[i-1],a[i]))
  r.append(gcd(r[i-1],b[n-1-i]))
  
  
for j in range(0,n-2):
  g.append(gcd(l[i],r[n-3-i]))
  
g.append(l[n-1])  
g.append(r[n-1])

print(max(g))

Submission status: Runtime Error

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

l=[]
l.append(a[0])
r=[]
r.append(a[n-1])
g=[]

def gcd(x,y):
  if x%y==0:
    return y
  else:
    return gcd(y,x%y)
  
for i in range(1,n-1):
  l.append(gcd(l[i-1],b[i]))
  r.append(gcd(r[i-1],b[n-1-i]))
  
for j in range(0,n):
  g.append(gcd(l[i],r[n-2-i]))
  
print(max(g))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
x=0
def gcd(x,y):
  if x%y==0:
    print(y)
  else:
    return gcd(y,x%y)
  
for i in range(0,n-1):
  for j in range(i+1,n):
    x=gcd(a[i],a[j])
    b.append(x)
    
print(max(b))

Submission status: Runtime Error

Solution code:
import math
def main():
    n=int(input())
    a = list(map(int,input().split()))
    L=[a[0] for _ in range(n)]
    R=[a[n-1] for _ in range(n)]
    for i in range(1,n):
        L[i]=math.gcd(L[i-1],a[i])
    for i in range(1,n):
        R[i]=math.gcd(R[i-1],a[n-1-i])
    R.reverse()
    LR=[]
    for i in range(1,n-1):
        LR.append( math.gcd(L[i-1],R[i+1]) )
    if LR==[]:
        print(max(L[n-2],R[1] ))
    else:
        print(max(max(LR),L[n-2],R[1] ))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math
import copy
import sys
import bisect
input = sys.stdin.readline

def main():
    n=int(input())
    a = list(map(int,input().split()))
    L=[a[0] for _ in range(n)]
    R=[a[n-1] for _ in range(n)]
    for i in range(1,n):
        L[i]=math.gcd(L[i-1],a[i])
    for i in range(1,n):
        R[i]=math.gcd(R[i-1],a[n-1-i])
    R.reverse()
    LR=[]
    for i in range(1,n-1):
        LR.append( math.gcd(L[i-1],R[i+1]) )
    if LR==[]:
        print(max(L[n-2],R[1] ))
    else:
        print(max(max(LR),L[n-2],R[1] ))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#!/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)

Submission status: Runtime Error

Solution code:
#!/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)

Submission status: Runtime Error

Solution code:
#!/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)

Submission status: Runtime Error

Solution code:
import fractions
n=int(input())
a=list(map(int,input().split()))
x=100000
X=0
a.sort()
flag=False

for i in range(0,n-1):
  if fractions.gcd(a[i],a[i+1])==1 and fractions.gcd(a[i+1],a[i+2])==1:
    a.pop(i+1)
    flag=True
    break
if flag!=True:
  for i in range(n-1):
    if x>=fractions.gcd(a[i],a[i+1]):
      x=fractions.gcd(a[i],a[i+1])
      X=a[i]
  if X in a:
    a.remove(X)

ans = a[0]
for i in range(1,n-1):
  ans = fractions.gcd(ans, a[i])
print(ans)

Submission status: Runtime Error

Solution code:
#!/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)

Submission status: Runtime Error

Solution code:
#!/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)

Submission status: Runtime Error

Solution code:
#!/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)

Submission status: Runtime Error

Solution code:
#!/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)

Submission status: Runtime Error

Solution code:
import fractions
N = int(input())
A = list(map(int,input().split()))
minflg = 0
mingcd = A[1]
for i in range(N):
    gcd = fractions.gcd(mingcd,A[i])
    if gcd < mingcd:
        mingcd = gcd
        minflg = i
if minflg == 0 and N > 2:
    if fractions.gcd(A[0],A[2]) > math.fractions(A[1],A[2]):
        minflg = 1
if minflg > 0:
    mingcd = A[minflg-1]
else: mingcd = A[minflg+1]
    
for i in range(N):
    if i != minflg:
        gcd = fractions.gcd(mingcd,A[i])
        if gcd < mingcd:
            mingcd = gcd
print(mingcd)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
  if a%b == 0:
    return b
  else:
    return gcd(b, a%b)
def multi_gcd(l):
  l = sorted(l, reverse=True)
  if len(l) == 1:
    return l[0]
  else:
    new_l = []
    if len(l)%2 == 0:
      for i in range(len(l)//2):
        temp_gcd = gcd(l[2*i], l[2*i+1])
        if temp_gcd == 1:
          return 1
        else:
          if temp_gcd not in new_l:
            new_l.append(temp_gcd)
      return multi_gcd(new_l)
    else:
      for i in range(len(l)//2):
        temp_gcd = gcd(l[2*i], l[2*i+1])
        if temp_gcd == 1:
          return 1
        else:
          if temp_gcd not in new_l:
            new_l.append()
      new_l.append(l[-1])
      return multi_gcd(new_l)
     
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
  a_gcd = multi_gcd(a[:i]+a[i+1:])
  if ans < a_gcd:
    ans = a_gcd
print(ans)