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:
import sys
import os
#import math
import fractions
#from functools import reduce
from fractions import gcd

def test(x,k,m):
    #print("i=",k)
    tmp=[0]*len(x)
    for j in range(m):
        tmp[j]=x[j]
    #print('a=',x)
    #print('tmp=',tmp)
    del tmp[k]
    #print('tmp=',tmp)
    #print("a==",x)
    XX=gcd(*tmp)
    ans=0
    for aa in range(len(tmp)):
        ans = fractions.gcd(ans, tmp[aa])
    #print("XX=",XX)
    return ans
#def gcd(*numbers):
#    return reduce(math.gcd, numbers)
#def gcd_list(numbers):
#    return reduce(math.gcd, numbers)
n=int(input())
a= list(map(int,input().split()))

yakusu=[0]*len(a)
for i in range(n):
    yakusu[i]=test(a,i,n)

ans=max(yakusu)
print(ans)

Submission status: Runtime Error

Solution code:
import copy
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a%b)


def gcd_lis(l):
    res = 0
    for i in range(len(l)-1):
        if i == 0:
            res = gcd(l[i],l[i+1])
        else:
            res = gcd(res,l[i+1])
    return res

def gcd_lis2(l):
    tmpd = copy.deepcopy(l)
    if len(l) == 1:
        return l[0]
    else:
        tmpd.append(gcd(tmpd.pop(),tmpd.pop()))
        return gcd_lis2(tmpd)

n = int(input())
lis = list(map(int,input().split()))
lis = list(set(lis))
reslis = []
reslis.append(gcd_lis2(lis))
if len(lis) != 2:
    for i in range(n):
        tmp = copy.deepcopy(lis)
        del tmp[i]
        reslis.append(gcd_lis2(tmp))
print(max(reslis))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
box = [0]*10**5
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
for i in a:
    for j in make_divisors(i):
        box[100000-j]+=1 
if n-1 in box:
    print(100000-box.index(n-1))
else:
  
    print(100000 - box.index(n))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import numpy as np

N = int(input())
As = [int(elm) for elm in input().split(" ")] 


def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            ass.append(n//i)
    return ass

if N >= 3:
    gs = []
    for i in range(N//2):
        g = math.gcd(As[i], As[i+1])
        gs.append(g)
    if N % 2 == 1:
        gs.append(As[N-1])

    while len(gs) != 2:
        new_gs = []
        N1 = len(gs)
        for i in range(N1//2):
            g = math.gcd(gs[i], gs[i+1])
            new_gs.append(g)
        if N1 % 2 == 1:
            new_gs.append(gs[-1])
        gs = new_gs

    g1, g2 = gs
    d1 = divisor(g1) 
    d2 = divisor(g2) 
    ds = sorted(d1 + d2, reverse=True)

    for d in ds:
        count = sum([int(A % d == 0) for A in As])
        if count >= N-1:
            out = d
            break

else:
    out = max(As)

print(out)

Submission status: Runtime Error

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

import math

table = {}  ## (start, end) => gcd

for i in range(0, n):
    if i > 0:
        gcd = aa[0]
        for j in range(0, i):
            gcd = math.gcd(gcd, aa[j])
        table[(0, i)] = gcd

    if i < n - 1:
        gcd = aa[i + 1]
        for j in range(i + 1, n):
            gcd = math.gcd(gcd, aa[j])

        table[(i + 1, n)] = gcd

candidate = 1
for i in range(0, n):
    if i == 0:
        gcd2 = table[(i + 1, n)]
        candidate = max(gcd2, candidate)
    elif i == n - 1:
        gcd1 = table[(0, i)]
        candidate = max(gcd1, candidate)
    else:
        gcd1 = table[(0, i)]
        gcd2 = table[(i + 1, n)]
        candidate = max(math.gcd(gcd1, gcd2), candidate)

print(candidate)

Submission status: Runtime Error

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

n = int(input())
t = list(map(int, input().split()))

if len(t) == 2:
    print(math.gcd(t[1], t[0]))
    exit()

a1 = math.gcd(t[1], t[0])
a2 = math.gcd(t[2], t[1])
a3 = math.gcd(t[2], t[0])


print(max(a1, a2, a3))

Submission status: Runtime Error

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

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

ans = 1
if n == 2:
    print(max(a))
else:
    for i in range(n // 10):
        b = a[:i] + a[i + 1:]
        element = gcd(b[0], b[1])
        if n == 3:
            ans = max(ans, element)
        else:
            for j in range(2, n - 1):
                element = gcd(element, b[j])
            ans = max(ans, element)
    print(ans)

Submission status: Runtime Error

Solution code:
def test(x,k,m):
    #print("i=",k)
    tmp=[0]*len(x)
    for j in range(m):
        tmp[j]=x[j]
    #print('a=',x)
    #print('tmp=',tmp)
    del tmp[k]
    #print('tmp=',tmp)
    #print("a==",x)
    XX=gcd(*tmp)
    ans=0
    for aa in range(len(tmp)):
        ans = fractions.gcd(ans, tmp[aa])
    #print("XX=",XX)
    return ans
#def gcd(*numbers):
#    return reduce(math.gcd, numbers)
#def gcd_list(numbers):
#    return reduce(math.gcd, numbers)
n=int(input())
a= list(map(int,input().split()))

yakusu=[0]*len(a)
for i in range(n):
    yakusu[i]=test(a,i,n)

ans=max(yakusu)
print(ans)

Submission status: Runtime Error

Solution code:
#C - GCD on Blackboard
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

def gcdList(num):
    if len(num) == 1:
        return num[0]
    else:
        return gcd(num[0], gcdList(num[1:]))
    
n = int(input())
a = list(map(int, input().split()))
ans = 0

for i in range(n):
    ans = max(ans, gcdList(a[:i]+a[i+1:]))
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
import numpy as np
import copy

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

if N==2:
    print(max(A))
else:
    gcds = []
    for i in range(len(A)-1):
        if i == 0:
            gcds.append(gcd(A[0],A[1]))
        else:
            gcds.append(gcd(gcds[-1],A[i]))
    gcds = np.asarray(gcds)
    
    index = []
    for idx,n in enumerate(gcds.min() == gcds):
        if n==True:
            index.append(idx)
    a = []
    for i in index:
        if i+1 in index:
            None
        else:
            a.append(i+1)
    for i in a:
        index.append(i)
    gcds = []
    for idx in index:
        A_temp = copy.deepcopy(A)
        A_temp.pop(idx)
        gcds_temp = []
        for i in range(len(A_temp)-1):
            if i ==0:
                gcds_temp.append(gcd(A_temp[0],A_temp[1]))
            else:
                gcds_temp.append(gcd(gcds_temp[-1],A_temp[i]))
        gcds.append(min(gcds_temp))
    print(max(gcds))

Submission status: Runtime Error

Solution code:
n = int(input())
lis = list(map(int,input().split()))
lis.sort(reverse=True)
answer = 0
i = lis[1]
while i >= 1:
  liss = []
  counter = 0
  for j in range(n):
    if lis[j]%i > 0:
      counter += 1
  if count < 2:
    answer = i
    break
  i -= 1
print(answer)

Submission status: Runtime Error

Solution code:
n = int(input())
numbers = tuple(map(int,input().split()))

import math
from functools import reduce

ans = []

if n == 2:
    print(max(numbers))

else:
    for i in range(n):
        a = list(numbers)
        del a[i]
        ans.append(reduce(math.gcd, a))
        print(max(ans))

Submission status: Runtime Error

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

n = int(input())
t = list(map(int, input().split()))

if len(t) == 2:
    print(math.gcd(t[1], t[0]))
    exit()

a1 = math.gcd(t[1], t[0])
a2 = math.gcd(t[2], t[1])
a3 = math.gcd(t[2], t[0])


print(max(a1, a2, a3))

Submission status: Runtime Error

Solution code:
rom collections import defaultdict

data = {}


def gcv(a, b):
    global data
    # if a >= b:
    #     a, b = b, a
    if data.get('{}:{}'.format(a, b), None):
        return data['{}:{}'.format(a, b)]
    elif data.get('{}:{}'.format(b, a), None):
        return data['{}:{}'.format(b, a)]

    if b == 0:
        data['{}:{}'.format(a, b)] = a
        return a
    else:
        # print(a, b)
        data['{}:{}'.format(a, b)] = gcv(b, a % b)

        return data['{}:{}'.format(a, b)]


def solve(n, a):
    if n == 2 and a[0] == a[1]:
        return a[0]
    n_dict = defaultdict(int)
    for i in range(len(a)):
        for j in range(len(list(a)) - i + 1):
            n_dict[gcv(a[i], a[j + i - 1])] += 1
    return sorted(n_dict.items(), key=lambda x: x[0])[1][0]


def input_from_console():
    n = int(input())
    a = list(map(int, input().split()))
    return n, a


def main():
    n, a_list = input_from_console()
    print(solve(n, a_list))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

def gcdl(l):
    res = l[0]
    for i in l:
        res = gcd(res, i)
    return res

n = int(input())
ass = [int(x) for x in input().split()].sort(reverse=True)

m = 1
count = 0
for i in range(n):
    tmp = ass[:]
    pt = tmp.pop(i)

    mm = gcdl(tmp)
    if mm > m:
        m = mm
    if mm >= pt:
        break
    if mm == 1:
        count += 1
        if count == 2:
            break
        
print(m)

Submission status: Runtime Error

Solution code:
import math
import copy 
from functools import reduce
import fractions


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

if __name__ == '__main__':
	N=int(input())
	A=list(map(int,input().split()))

	ans=0
	for i in range(N):
		l=copy.deepcopy(A)
		l.pop(int(i))
		if(N>2):
			tmp_gcd=gcd(l[0],l[1])
			for j in range(2,len(l)):
				tmp_gcd=gcd(l[l],tmp_gcd)
			if(tmp_gcd > ans):
				ans=tmp_gcd
		else:
			ans=gcd(A[0],A[1])
	print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

ans = gcd_list(a)
a_stock = a.copy()
for i in range(n):
    a = a_stock.copy()
    a.pop(i)
    ans2 = gcd_list(a)
    if ans < ans2:
        ans = ans2
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
from collections import deque, defaultdict as ddic
from itertools import combinations, permutations, product
import bisect
import heapq
from math import gcd
from operator import mul
import re


rs = lambda: stdin.readline().strip()
ri = lambda: int(rs())
rsl = lambda: stdin.readline().split()
rim = lambda: map(int, rsl())
ril = lambda: list(rim())


def findGCD(lst):
    ret = 1
    for i in range(len(lst)-1):
        ret = max(ret, gcd(lst[i], lst[i+1]))
    return ret


def findGCD2(lst, k):
    ret = 1
    for i in range(len(lst)-1):
        if i == k:
            continue
        ret = max(ret, gcd(lst[i], lst[i+1]))
    return ret



N = ri()
integers = list(rim())

lowest = [float('-inf'), float('-inf')]
for i in range(len(integers)-1):
    for j in range(i+1, len(integers)):
        temp = gcd(integers[i], integers[j])
        if temp > min(lowest):
            lowest[lowest.index(min(lowest))] = temp

print(max(lowest))

Submission status: Runtime Error

Solution code:
import math
import sys

sys.setrecursionlimit(10**9)
N = int(input())
A = list(map(int, input().split()))
A.sort()
mx = 10 ** 9
idx = 0
g = []
for i in range(N-1):
    tmp = math.gcd(A[i], A[i+1])
    #print(A[i], A[i+1], tmp)
    if tmp < mx:
        mx = tmp
        idx = i
    g.append([tmp, i])
g.sort(key=lambda x:x[0])
print(g)
if N > 2:
    if g[0][1] + 1 == g[1][1]:
        A.remove(A[g[0][1]+1])
    else :
        tmp1 = math.gcd(A[g[0][1]], A[g[0][1]])
        tmp2 = math.gcd(A[g[0][1]+1], A[g[0][1]+1])
        #print(tmp1, tmp2)
        A.remove(A[g[0][1]] if tmp1 > tmp2 else A[g[0][1]+1])
else :
    A = [max(A)]
tmp = A[0]
for i in A:
    tmp = math.gcd(i, tmp)
print(tmp)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
from fractions import Fraction
import numpy as np
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = int(input())
A = list(map(int, input().split()))
ans=0
for i in range(N):
    a = A[0]
    del A[0]
    
    b = gcd_list(A)
    if ans < b:
        ans = b
    A.append(a)

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
lis = list(map(int,input().split()))
lis.sort(reverse=True)
answer = 0
i = lis[1]
while i >= 1:
  liss = []
  for j in range(n):
    if lis[j]%i > 0:
      counter += 1
  if count < 2:
    answer = i
    break
  i -= 1
print(answer)

Submission status: Runtime Error

Solution code:
# coding: utf-8

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

max_value = max(A)
num_divisor = [0] * max_value
for a in A:
    for i in range(max_value // 2):
        if a % (i + 1) == 0:
            num_divisor[i] += 1
    num_divisor[max_value - 1] += 1
answer = 1
for i in reversed(range(max_value)):
    if num_divisor[i] == N - 1:
        answer = i + 1
        break
print(answer)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def get(lists, index):
    base = lists[index]
    lists.pop(index)

    lists = filter(lambda x: x > 1, [gcd(base, i) for i in lists])
    if not lists:
        return None
    elif len(lists) == 1:
        return lists[0]
    return sorted(lists)[1]


raw_input()
al = [int(i) for i in raw_input().split()]

gcds = sorted([al[0], al[1], gcd(al[0], al[1])])[:2]

for i in al[2:]:
    gcds += [gcd(i, j) for j in gcds]
    gcds = sorted(list(set(gcds)))[:2]

print(max(*gcds))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = int(input())
A = [int(x) for x in input().split()]
AA = []
for i in A:
    if(not i in AA):
        AA+=[i]
AA.sort()
cand = -1
mingcd = gcd_list(AA)
if(N==2):
    print(max(AA))
else:
    for i in range(len(AA)-1):
        if(mingcd==gcd(AA[i],AA[i+1])):
            if(i<len(AA)-2):
                if(mingcd==gcd(AA[i],AA[i+2])):
                    cand = i
                else:
                    cand = i+1
                break
            else:
                cand = i+1
    if(cand==-1):
        cand = len(AA)-1
    print(gcd_list(AA[:cand]+AA[cand+1:]))

Submission status: Runtime Error

Solution code:
import sys
import os
import math
import fractions
from functools import reduce
from fractions import gcd

def test(x,k,m):
    #print("i=",k)
    tmp=[0]*len(x)
    for j in range(m):
        tmp[j]=x[j]
    #print('a=',x)
    #print('tmp=',tmp)
    del tmp[k]
    #print('tmp=',tmp)
    #print("a==",x)
    XX=gcd(*tmp)
    ans=0
    for aa in range(len(tmp)):
        ans = fractions.gcd(ans, tmp[aa])
    #print("XX=",XX)
    return ans
#def gcd(*numbers):
#    return reduce(math.gcd, numbers)
#def gcd_list(numbers):
#    return reduce(math.gcd, numbers)
n=int(input())
a= list(map(int,input().split()))

yakusu=[0]*len(a)
for i in range(n):
    yakusu[i]=test(a,i,n)

ans=max(yakusu)
print(ans)

Submission status: Runtime Error

Solution code:
import fractions

n = int(input())
A = list(map(int, input().split()))
for i in range(0, n):
  for j in range(i + 1, n):
    g = fractions.gcd(A[i], A[j])
print(max(g))

Submission status: Runtime Error

Solution code:
import fractions

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

memo = []
flag = []
for i in range(N*10):
    memo.append([])
    flag.append([])
    for j in range(N*10):
        memo[i].append(0)
        flag[i].append(0)


def gcd2(_a):
    buff = 0
    for n in range(N):
        if flag[buff][_a[n]] > 0:
            buff = memo[buff][_a[n]]
        else:
            flag[buff][_a[n]] = 1
            buff = fractions.gcd(buff, _a[n])
            memo[buff][_a[n]] = buff
    return buff


ans = 0
_ans = 0
for i in range(N):
    buff = A.copy()
    buff[i] = 0
    _ans = gcd2(buff)
    ans = max(_ans, ans)


print(ans)

Submission status: Runtime Error

Solution code:
import fractions

n = int(input().strip())
arrayA = list(map(int, input().strip().split(' ')))
def gcd_all(list):
    return gcd_all([fractions.gcd(*list[:2])] + list[2:]) if len(list) > 1 else list[0]
gcd_check = gcd_all(arrayA)
ans = gcd_check
arrayB = arrayA
for i in range(n):
    remove = arrayA.pop(i)
    gcdRemove = gcd_all(arrayA)
    if gcdRemove > ans:
        ans = gcdRemove
    arrayA.append(remove)
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce

n = int(input())
A = list(map(int, input().split()))
maxGcd = 0

for i in range(n):
    g = reduce(lambda a, b: gcd(a, b), A[:i]+A[i+1:])
    maxGcd = max(maxGcd, g)

print(maxGcd)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
box = [0]*10**5
for i in a:
    for j in make_divisors(i):
        box[100000-j]+=1 
if n-1 in box:
    print(100000-box.index(n-1))
else:
  
    print(100000 - box.index(n))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
#from fractions import gcd
from math import gcd

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

if N == 2:
    print(max(A))
else:
    ans = gcd(A[0], A[1])
    ans2 = max(gcd(A[0], A[2]), gcd(A[1], A[2]))
    for a in A[2:]:
        ans2 = max(gcd(a, ans2), ans)
        ans = gcd(a, ans)
    
    print(ans2)

Submission status: Runtime Error

Solution code:
import functools
import fractions

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = set(list(map(int, input().split())))
  else:
    # N = 3
    # A = [7,6,8]
    # N = 3
    # A = [12,15,18]
    N = 2
    A = [1000000000,1000000000]

  x = 0
  for i in range(N):
    tmp = functools.reduce(fractions.gcd, A[0:i]+A[i+1:])
    if tmp > x:
      x = tmp
  
  print(x)
  
main()

Submission status: Runtime Error

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


import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

res = 0
for i in range(n):
    a = x.copy()
    b = a.pop(i)
    c = gcd_list(a)

    d = x.copy()
    d[i] = c
    if  res < gcd_list(d):
        res = gcd_list(d)
print(2)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
A=list(set(A))
maxi=10**9
for i in range(len(A)):
    divesor=[]
    a=A[i]**0.5+1
    for j in range(1,int(a)):
        if A[i]%j==0:
            divesor.append(j)
            divesor.append(int(A[i]/j))
    A[i]=divesor
    if maxi>int(max(A[i])):
        maxi=max(A[i])
for i in range(maxi,0,-1):
    flag=1
    for j in range(N):
        if i not in A[j]:
            flag-=1
    if flag >=0:
        print(i)
        break

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

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

max_ans = 0
for i in range(len(A)):
    tmp = A[:i] + A[1+i:]
    ans = gcd_list(tmp)
    if max_ans < ans:
        max_ans = ans
print(max_ans)

Submission status: Runtime Error

Solution code:

import fractions
from functools import reduce
 
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
 
n=int(input())
array = list(map(int, input().split())) 
array=list(set(array))
array.sort(reverse=True)
 
 
max=-100
 
for i in range(n):
    copy_array=array.copy()
    if(max>array[i]):
        break
    copy_array.pop(i)
    tmp_gcd=gcd(*copy_array)
    # print(copy_array)
    if(max<tmp_gcd):
        max=tmp_gcd
    
print(max)

Submission status: Runtime Error

Solution code:
# GCD on Blackboard
"""
リストのどの要素を抜いた時に最大公約数が最大値をとるか調べて、
その時の最大公約数を出力する。
"""

from functools import reduce

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


def get_gcd(a, b):
    """
    ユークリッド互除法により最大公約数を求める。
    """
    if a < b:
        a, b = b, a

    elif a % b == 0:
        return b

    return get_gcd(b, a % b)


def get_gcd_l(l):
    """
    リストの要素の最大公約数を求める。
    """
    return reduce(get_gcd, l)


def answer(l):
    """
    どの要素を抜いた時に最大公約数が最大値をとるか調べる。
    """
    len_l = len(l)
    answers = []  # 答えの案

    for i in range(len_l): # 要素を1個ずつ消してみる。
        temp_l = []
        temp_l += l[0 : i]
        temp_l += l[i+1 : len_l]
        answers.append(get_gcd_l(temp_l))
        ans = max(answers)
    return ans


def main():
    """
    答えを出力する。
    """
    print(answer(A))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import copy
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a%b)


def gcd_lis(l):
    res = 0
    for i in range(len(l)-1):
        if i == 0:
            res = gcd(l[i],l[i+1])
        else:
            res = gcd(res,l[i+1])
    return res

def gcd_lis2(l):
    tmpd = copy.deepcopy(l)
    if len(l) == 1:
        return l[0]
    else:
        tmpd.append(gcd(tmpd.pop(),tmpd.pop()))
        return gcd_lis2(tmpd)

n = int(input())
lis = list(map(int,input().split()))

reslis = []
reslis.append(gcd_lis2(lis))
if len(lis) != 2:
    for i in range(n):
        tmp = copy.deepcopy(lis)
        del tmp[i]
        reslis.append(gcd_lis2(tmp))
print(max(reslis))

Submission status: Runtime Error

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

  def gcd(m, n):
    while n:
      m, n = n, m%n
    return m

  res = []
  k = max(A)
  f = False
  ind = A.index(k)
  if k%2 == 0:
    f = True
  for i in range(N):
    if i != ind:
      if f:
        if (k%A[i])%2 == 0:
          res.append(gcd(k, A[i]))
      else:
        if (k%A[i])%2 == 1:
          res.append(gcd(k, A[i]))
  print(max(res))
ans()

Submission status: Runtime Error

Solution code:
def c():
    ans = 0
    N = long(raw_input())
    A = raw_input().split()
    for i in range(N):
        for j in range(i+1, N):
            C = long(A[i])
            D = long(A[j])
            #prlong "C:{}, D:{}".format(C,D)
            if C == D:
                g = C
            elif C > D:
                g = gcd(C, D, ans)
            else:
                g = gcd(D, C, ans)
            if g > ans:
                ans = g
    print ans

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

def main():
    c()
	
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
num_list = list(map(int, input().split()))
num_unique = list(set(num_list))
num_unique.sort()
num_unique.reverse()
max_num = 0
flag = False
for i in range(num_unique[-2], 0, -1):
    if i == 1:
        max_num = 1
        break

    if flag and count < 2:
        break
    else:
        flag = True
        count = 0
        max_num = i
    for num in num_unique:
        if num / max_num < 1 or num % max_num != 0:
            count += 1
            if count > 1:
                break
print(max_num)

Submission status: Runtime Error

Solution code:
import math

l = list(map(int, '7 6 8'.split()))
max_gcd = 0
for n, _ in enumerate(l):
    sub = [v for i, v in enumerate(l) if i != n]
    if not sub:
        continue
    if len(sub) > 1:
        res = sub[0]
        for c in sub[1::]:
            res = math.gcd(res, c)
        sub[0] = res
    max_gcd = max(max_gcd, sub[0])

print(max_gcd)

Submission status: Runtime Error

Solution code:
import sys
import os
import fractions
from fractions import gcd

def test(x,k,m):
    #print("i=",k)
    tmp=[0]*len(x)
    for j in range(m):
        tmp[j]=x[j]
    #print('a=',x)
    #print('tmp=',tmp)
    del tmp[k]
    #print('tmp=',tmp)
    #print("a==",x)
    XX=gcd(*tmp)
    ans=0
    for aa in range(len(tmp)):
        ans = fractions.gcd(ans, tmp[aa])
    #print("XX=",XX)
    return ans

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

yakusu=[0]*len(a)
for i in range(n):
    yakusu[i]=test(a,i,n)

ans=max(yakusu)
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math

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


def gcd(a):
    r = a[0]
    for i in range(len(a) - 1):
        r = math.gcd(r, a[i + 1])
    return r


m = 1
for i in range(N):
    a = A.pop(0)
    g = gcd(A)
    if m < g:
        m = g
    A.append(a)

print(m)

Submission status: Runtime Error

Solution code:
def c():
    ans = 0
    N = long(raw_input())
    A = raw_input().split()
    for i in range(N):
        for j in range(i+1, N):
            C = long(A[i])
            D = long(A[j])
            #prlong "C:{}, D:{}".format(C,D)
            if C == D:
                g = C
            elif C > D:
                g = gcd(C, D)
            else:
                g = gcd(D, C)
            if g > ans:
                ans = g
    print ans

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

def main():
    c()
	
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)

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

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

ans = gcd_list(ls)

ls = [i // ans for i in ls]

tempx = 1


for i in range(N):
	temp = ls[:]
	temp.pop(i)
	a = gcd(temp[0], temp[1])
	if a <= tempx:
		continue
	for j in range(2, N - 1):
		a = gcd(a, temp[j])
		if a <= tempx:
			break
	if a > tempx:
		tempx = a
print(ans * tempx)

Submission status: Runtime Error

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


import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

res = 0
for i in range(n):
    a = x.copy()
    b = a.pop(i)
    c = gcd_list(a)

    d = x.copy()
    d[i] = c
    if  res < gcd_list(d):
        res = gcd_list(d)
print(1)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = np.array([int(x) for x in input().split(' ')])
A.sort()

if N > 2:
    x = []
    for n, m in [tuple(A[0:2]), tuple(A[1:3]), (A[0], A[2])]: 
        while n != 0:
            l = n
            n = m % n
            m = l
        x.append(m)
    x.sort(reverse=True)
else:
    x = [A[-1], 1]

y = x.pop(0)
while True:
    tmp = A % y
    if sum(tmp != 0) < 2:
        break
    for i in range(2, y):
        if y % i == 0:
            y = y / i
            break
    if x[0] > y:
        x.append(y)
        y = x.pop(0)
        x.sort(reverse=True)

print(y)

Submission status: Runtime Error

Solution code:
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq
"""
A,B,T=map(int, input().split())
print(int(math.floor((T+0.5)/(A))*B))
"""
"""
N=int(input())
V=list(map(int, input().split()))
C=list(map(int, input().split()))
print(sum([V[i] - C[i] for i in range(N) if V[i] - C[i] > 0]))
"""

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

if len(A) == 2:
        print(max(A[0][1], A[1][1]))
        exit()

maxX=-1
for i, ai in enumerate(A):
        x=10**20
        l=list(A)
        l0, l1=(l[1][1], l[2][1]) if i == 0 else (l[0][1], l[2][1]) if i == 1 else (l[0][1], l[1][1]) 

        x=math.gcd(l0, l1)
        for (j, lj) in l[3:]:
                if i != j:
                        x=math.gcd(x, lj)
        maxX=max(x, maxX)
print(maxX)
"""
N=int(input())
A=list(map(int, input().split()))
nNeg = len([1 for a in A if a < 0])
minAbs = min(A, key=lambda ai: abs(ai))
if nNeg%2 == 0:
        print(sum([abs(ai) for ai in A]))
else:
        print(-2*abs(minAbs) + sum([abs(ai) for ai in A]))
"""

Submission status: Runtime Error

Solution code:
import collections

def cal_divs(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
  
def check(num, kouho, N, i):
  for val in kouho.keys():
    if num%val == 0:
      kouho[val] += 1
      
  return {k: v for k, v in kouho.items() if v > i-1}
  
  
N = int(input())
A= list(map(int, input().split()))
pri_flag = True

divs = []
for i in range(3):
    divs.extend(cal_divs(A[i]))
kouho = {}
c = collections.Counter(divs)
for div, n in c.most_common():
    kouho[div] = n
    
kouho = {k: v for k, v in kouho.items() if v > 1}

if len(A) >= 4:
  for i,num in enumerate(A[3:]):
      if len(kouho) == 1:
          print(1)
          pri_flag = False
          break
      kouho = check(num, kouho, N, i+3)
    
if pri_flag:
    print(max(kouho))

Submission status: Runtime Error

Solution code:
if N==2:
    print(max(A))
else:
    gcds = []
    for i in range(len(A)-1):
        if i == 0:
            gcds.append(gcd(A[0],A[1]))
        else:
            gcds.append(gcd(gcds[-1],A[i]))
    gcds = np.asarray(gcds)
    
    index = []
    for idx,n in enumerate(gcds.min() == gcds):
        if n==True:
            index.append(idx)
    a = []
    for i in index:
        if i+1 in index:
            None
        else:
            a.append(i+1)
    for i in a:
        index.append(i)
    gcds = []
    for idx in index:
        A_temp = copy.deepcopy(A)
        A_temp.pop(idx)
        gcds_temp = []
        for i in range(len(A_temp)-1):
            if i ==0:
                gcds_temp.append(gcd(A_temp[0],A_temp[1]))
            else:
                gcds_temp.append(gcd(gcds_temp[-1],A_temp[i]))
        gcds.append(min(gcds_temp))
    print(max(gcds))

Submission status: Runtime Error

Solution code:
N = map(int, input().split())
A = list(map(int, input().split()))
A.append(A[-1])
each_GCD = []
for idx in range(len(A)-1):
    each_GCD.append(computeGCD(A[idx], A[idx+1]))
min_idx = each_GCD.index(min(each_GCD))
if min_idx < len(each_GCD)-1:
    pre = each_GCD[min_idx-1]
    nex = each_GCD[min_idx+1]
    if pre - nex >= 0:
        c = computeGCD(A[min_idx], A[min_idx+2])
        if nex > c:
            print(nex)
        else:
            print(c)
    else:
        c = computeGCD(A[min_idx+1], A[min_idx-2])
        if pre > c:
            print(pre)
        else:
            print(c)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n,a,b=int(input()),list(map(int,input().split())),[]
if n==2:print(gcd(a[0],a[1]))
elif n==3:print(max(gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2])))
else:
  for i in range(n-1):b.append(gcd(a[i],a[i+1]))
  b.append(gcd(a[0],a[-1]))
  print(max(no,on),sorted(b)[2])