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: Wrong Answer

Solution code:
from fractions import gcd
import numpy as np
import copy as copy
N=int(input())
A_i=list(map(int,input().split()))

def GCD(N,A_i):
  for i in range(N):
    A=A_i.copy()
    ind=[1]*N
    ind[i]=0
    A=np.array(A)
    if len(A)==2:
      ans=[max(A)]
    else:
      A[ind==0]=np.random.choice(A[ind==1],1)
      ans=A[0]
      ans=[gcd(ans,A[j]) for j in range(1,N)]
  return max(ans)

print("{}".format(GCD(N,A_i)))

Submission status: Wrong Answer

Solution code:
import fractions, itertools, functools

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

if n == 2 :
    m = max(a)
else :
    for coml in list(itertools.combinations(a,2)) :
        g = fractions.gcd(coml[0], coml[1])
        if g > m :
            m = g

print(m)

Submission status: Wrong Answer

Solution code:
from fractions import*
a=int(input())
b=list(map(int,input().split()))
alis=[b[0]]
blis=[b[-1]]
for i in range(a-1):
  alis.extend([gcd(alis[-1],b[i+1])])
  blis.extend([gcd(blis[-1],b[-i-2])])
blis=list(reversed(blis))+[0]
alis=[0]+alis
ans=[]
for i in range(a):
	ans+=[gcd(alis[i],blis[i+1])]
print(max(ans),alis,blis,ans)

Submission status: Wrong Answer

Solution code:
import fractions, itertools

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

gcdl = []
coml = list(itertools.combinations(a,2))

for x in range(len(coml)) :
    gcdl.append(fractions.gcd(coml[x][0], coml[x][1])) 

gcdl.sort()
min = gcdl[0]
for x in range(1, len(coml)) :
    if min != gcdl[x] :
        break

print(gcdl[x])

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import numpy as np
N=int(input())
A=list(map(int,input().split()))

def GCD(N,A):
  GCD=[]
  for i in range(N):
    ind = [True]*N
    ind[i]=False
    A=np.array(A)[ind]
    ans=A[0]
    for j in range(len(A)):
    	ans=gcd(ans,A[j])
    GCD.append(ans)
  return max(GCD)

print("{}".format(GCD(N,A)))

Submission status: Wrong Answer

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

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

ans = []
lst_l = [lst[0]]
lst_r = [lst[n-1]]
for i in range(n-1):
  lst_l.append(gcd(lst_l[-1], lst[i + 1]))
  lst_r.insert(0, gcd(lst_r[0], lst[n-2-i]))

ans = 0
for i in range(n-2):
  if ans < gcd(lst_l[i], lst_r[i+2]):
    ans = gcd(lst_l[i], lst_r[i+2])

print(ans)

Submission status: Wrong Answer

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

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a%b)
def gcd_array(a):#aは配列
  return reduce(gcd, a)

ans = []
lst_l = [lst[0]]
lst_r = [lst[n-1]]
for i in range(n-1):
  lst_l.append(gcd(lst_l[-1], lst[i + 1]))
  lst_r.insert(0, gcd(lst_r[0], lst[n-2-i]))

ans.append(lst_r[0])
for i in range(n-2):
  ans.append(gcd(lst_l[i], lst_r[i+2]))
ans.append(lst_l[-1])

print(max(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

s = []
a = max(A)
b = min(A)
while b != 0:
  a,b = b,a%b
s.append(a)

print(max(s))

Submission status: Wrong Answer

Solution code:
import itertools
a=int(input())
b=list(map(int,input().split()))
aak=list(itertools.combinations(b,a-1))
ans=[]
def gud(a,b):
  if a%b==0:
    return b
  else:
    return gud(b,a%b)
for i in aak:
  for v in range(a-2):
    i+=(gud(i[v],i[v+1]),)
  ans+=[i[-1]]
print(max(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

s = []
for i in range(N):
  B = [elem for idx,elem in enumerate(A) if idx != i]
  a = max(B)
  b = min(B)
  while b != 0:
    a,b = b,a%b
  s.append(a)

print(max(s))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import fractions
import math


def solve(N: int, A: "List[int]"):
    L = []
    last = A[0]
    for i in range(N):
        last = fractions.gcd(last, A[i])
        L.append(last)
    last = A[-1]
    R = []
    for i in range(1, N+1):
        last = fractions.gcd(last, A[-i])
        R.append(last)
    R.reverse()
    if N == 2:
        print(max(A[0], A[1]))
        return
    maxGCD = max(L[-2], R[-2])
    for i in range(1, N-1):
        maxGCD = max(fractions.gcd(L[i-1], R[i+1]), maxGCD)
    print(maxGCD)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import fractions
import math


def solve(N: int, A: "List[int]"):
    L = []
    last = A[0]
    for i in range(N):
        last = fractions.gcd(last, A[i])
        L.append(last)
    last = A[-1]
    R = []
    for i in range(1, N+1):
        last = fractions.gcd(last, A[-i])
        R.append(last)
    R.reverse()
    maxGCD = max(L[-2], R[-2])
    for i in range(1, N-1):
        maxGCD = max(fractions.gcd(L[i-1], R[i+1]), maxGCD)
    print(maxGCD)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import fractions


def solve(N: int, A: "List[int]"):
    L = []
    last = A[0]
    for i in range(N):
        last = fractions.gcd(last, A[i])
        L.append(last)
    last = A[-1]
    R = []
    for i in range(1, N+1):
        last = fractions.gcd(last, A[-i])
        R.append(last)
    maxGCD = max(L[-2], R[-2])
    for i in range(0, N-1):
        maxGCD = max(fractions.gcd(L[i], R[i]), maxGCD)
    print(maxGCD)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#Coding: Utf-8

#ランダムな数字に置換
num=0
a=[]
N= int(input())
a=list(map(str, input().split()))
import random
b=random.choice(a)
a=map(str,a)
a=",".join(a)
if random.randint(1,2)==1:
    a=a.replace(str(b),str(random.randint(1,100000000)),1)
a=a.split(",")
a=list(map(int,a))
a.sort(reverse=True)

#最大公約数の計算
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

c= gcd(a[0],a[1])
if len(a)>2:
    for i in range(2,N-2):
        c=gcd(c,a[i])

print(c)

Submission status: Wrong Answer

Solution code:
#Coding: Utf-8

#ランダムな数字に置換
num=0
a=[]
N= int(input())
a=list(map(str, input().split()))
import random
b=random.choice(a)
a=map(str,a)
a=",".join(a)
a=a.replace(str(b),str(random.randint(1,100000000)),1)
a=a.split(",")
a=list(map(int,a))
a.sort(reverse=True)

#最大公約数の計算
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

c= gcd(a[0],a[1])
if len(a)>2:
    for i in range(2,N-2):
        c=gcd(c,a[i])

print(c)

Submission status: Wrong Answer

Solution code:
#Coding: Utf-8

#ランダムな数字に置換
num=0
a=[]
N= int(input())
a=list(map(str, input().split()))
import random
b=random.choice(a)
a=map(str,a)
a=",".join(a)
a=a.replace(str(b),str(random.randint(1,10**9)),1)
a=a.split(",")
a=list(map(int,a))
a.sort(reverse=True)

#最大公約数の計算
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

c= gcd(a[0],a[1])
if len(a)>2:
    for i in range(2,N-2):
        c=gcd(c,a[i])

print(c)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
L = [A[0]]
R = [A[-1]]
for i in range(N-1):
    L.append(gcd(L[i],A[i+1]))
    R.append(gcd(R[-(i+1)],A[-(i+2)]))

ans = []

for i in range(N):
    if i == 0:
        ans.append(R[N - 2])
    elif i <= N - 2:
        ans.append(gcd(L[i - 1],R[N - i - 2]))
    else:
        ans.append(L[N - 2])
print(max(ans))

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
values = ([int(x) for x in input().split()])

gcd_from_the_left = []
gcd_from_the_left.append(values[0])
for i in range(N):
	gcd_from_the_left.append(fractions.gcd(gcd_from_the_left[i],values[i]))
gcd_from_the_left.pop(0)

gcd_from_the_right = []
gcd_from_the_right.append(values[-1])
for i in range(N):
	gcd_from_the_right.append(fractions.gcd(gcd_from_the_right[i],values[-i-1]))

gcd_from_the_right.pop(0)

ans = 0
gcd = 0

for i in range(N):
  gcd = fractions.gcd(gcd_from_the_left[i],gcd_from_the_right[-N])
  if gcd > ans:
    ans = gcd
    
gcd = gcd_from_the_left[-2]
if gcd > ans:
  ans = gcd
gcd = gcd_from_the_right[-2]
if gcd > ans:
  ans = gcd
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
values = ([int(x) for x in input().split()])

gcd_from_the_left = []
gcd_from_the_left.append(values[0])
for i in range(N):
	gcd_from_the_left.append(fractions.gcd(gcd_from_the_left[i],values[i]))
gcd_from_the_left.pop(0)

gcd_from_the_right = []
gcd_from_the_right.append(values[-1])
for i in range(N):
	gcd_from_the_right.append(fractions.gcd(gcd_from_the_right[i],values[-i-1]))

gcd_from_the_right.pop(0)

ans = 0
gcd = 0

for i in range(N):
  if i==0:
    gcd = gcd_from_the_right[-2]
  if i==len(gcd_from_the_left):
    gcd = gcd_from_the_left[i]
  if 0<i<N:
    gcd = fractions.gcd(gcd_from_the_left[i],gcd_from_the_right[N-i-2])
  if gcd > ans:
    ans = gcd
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
values = ([int(x) for x in input().split()])

gcd_from_the_left = []
gcd_from_the_left.append(values[0])
for i in range(len(values)):
	gcd_from_the_left.append(fractions.gcd(gcd_from_the_left[i],values[i]))
gcd_from_the_left.pop(0)

gcd_from_the_right = []
gcd_from_the_right.append(values[-1])
for i in range(len(values)):
	gcd_from_the_right.append(fractions.gcd(gcd_from_the_right[i],values[-i-1]))

gcd_from_the_right.pop(0)

ans = 0
gcd = 0

for i in range(len(gcd_from_the_left)):
  if i==0:
    gcd = gcd_from_the_right[-2]
  if i==len(gcd_from_the_left):
    gcd = gcd_from_the_left[i]
  if 0<i<len(gcd_from_the_left):
    gcd = fractions.gcd(gcd_from_the_left[i],gcd_from_the_right[len(gcd_from_the_left)-i-2])
  if gcd > ans:
    ans = gcd
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
values = ([int(x) for x in input().split()])

gcd_from_the_left = []
gcd_from_the_left.append(values[0])
for i in range(len(values)):
	gcd_from_the_left.append(fractions.gcd(gcd_from_the_left[i],values[i]))
gcd_from_the_left.pop(0)
print(gcd_from_the_left)

gcd_from_the_right = []
gcd_from_the_right.append(values[-1])
for i in range(len(values)):
	gcd_from_the_right.append(fractions.gcd(gcd_from_the_right[i],values[-i-1]))

gcd_from_the_right.pop(0)
print(gcd_from_the_right)

ans = 0
gcd = 0

for i in range(len(gcd_from_the_left)):
  if i==0:
    gcd = gcd_from_the_right[-2]
  if i==len(gcd_from_the_left):
    gcd = gcd_from_the_left[i]
  if 0<i<len(gcd_from_the_left):
    gcd = fractions.gcd(gcd_from_the_left[i],gcd_from_the_right[len(gcd_from_the_left)-i-2])
  if gcd > ans:
    ans = gcd
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding utf-8 -*-
N = int(input())
AN = list(map(int, input().split()))

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

LN = [0] * (N)
LN[0] = AN[0]
for i in range(N - 1):
    LN[i + 1] = gcd(LN[i], AN[i + 1])

RN = [0] * (N)
RN[N - 1] = AN[N - 1]
for i in range(N - 1, 0, -1):
    RN[i - 1] = gcd(RN[i], AN[i - 1])

LN = [0] + LN + [0]
RN = [0] + RN + [0]
ans = 0
for i in range(1, N):
    ans = max(ans, gcd(LN[i - 1], RN[i + 1]))
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions                                                                                                                                             
                                                                                                                                                             
if __name__ == '__main__':                                                                                                                                   
    N = int(input())                                                                                                                                         
    A = list(map(int,input().split()))                                                                                                                       
                                                                                                                                                             
    L = [0] * N                                                                                                                                              
    R = [0] * N                                                                                                                                              
                                                                                                                                                             
    L[0] = A[0]                                                                                                                                              
    for i in range(1,N):                                                                                                                                     
        L[i] = fractions.gcd(L[i-1],A[i])                                                                                                                    
                                                                                                                                                             
    R[-1] = A[-1]                                                                                                                                            
    for i in range(N-2,-1,-1):                                                                                                                               
        R[i] = fractions.gcd(R[i+1],A[i])                                                                                                                    
                                                                                                                                                             
    res = max(R[1],L[-1])                                                                                                                                    
    for i in range(1,N-1):                                                                                                                                   
        res = max(res,fractions.gcd(R[i-1],L[i+1]))                                                                                                          
                                                                                                                                                             
    print(res)

Submission status: Wrong Answer

Solution code:
import copy 

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

N = int(input())
T = list(map(int,input().split()))
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
F = LIS.index(min(LIS))
if len(T) == 2:
    ANS = max(T[0],T[1])
elif F == 0:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(1)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANSP = max(ANSU,ANSV)
    ANS = max(ANSP,LIS[N-1])
    
else:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(F)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANSP = max(ANSU,ANSV)
    ANS = max(ANSP,LIS[N-1])
        
print(ANS)

Submission status: Wrong Answer

Solution code:
import copy 

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

N = int(input())
T = list(map(int,input().split()))
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
F = LIS.index(min(LIS))

if F == 0 or F == 1:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(1)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANSP = max(ANSU,ANSV)
    ANS = max(ANSP,LIS[N-1])
else:
    S = copy.copy(T)
    S.pop(F)
    LS = [0]*(N-1)
    LS[0] += S[0]
    for i in range(N-2):
        LS[i+1] += gcd(LS[i],S[i+1])
        ANS = max(LIS[N-1],LS[N-2])
        

print(ANS)

Submission status: Wrong Answer

Solution code:
import copy 

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

N = int(input())
T = list(map(int,input().split()))
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
F = LIS.index(min(LIS))
if N == 2:
    ANS = max(T[0],T[1])
elif F == 0 or F == 1:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(1)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANSP = max(ANSU,ANSV)
    ANS = max(ANSP,LIS[N-1])
else:
    S = copy.copy(T)
    S.pop(F)
    LS = [0]*(N-1)
    LS[0] += S[0]
    for i in range(N-2):
        LS[i+1] += gcd(LS[i],S[i+1])
        ANS = max(LIS[N-1],LS[N-2])
        

print(ANS)

Submission status: Wrong Answer

Solution code:
import copy 

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

N = int(input())
T = list(map(int,input().split()))
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
F = LIS.index(min(LIS))
if F == 0:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(1)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANSP = max(ANSU,ANSV)
    ANS = max(ANSP,LIS[N-1])
    
else:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(F)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANSP = max(ANSU,ANSV)
    ANS = max(ANSP,LIS[N-1])
        
print(ANS)

Submission status: Wrong Answer

Solution code:
import copy 

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

N = int(input())
T = list(map(int,input().split()))
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
F = LIS.index(min(LIS))
if F == 0 or F == 1:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(1)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANSP = max(ANSU,ANSV)
    ANS = max(ANSP,LIS[N-1])
else:
    S = copy.copy(T)
    S.pop(F)
    LS = [0]*(N-1)
    LS[0] += S[0]
    for i in range(N-2):
        LS[i+1] += gcd(LS[i],S[i+1])
        ANS = max(LIS[N-1],LS[N-2])
        

print(ANS)

Submission status: Wrong Answer

Solution code:
import copy 

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

N = int(input())
T = list(map(int,input().split()))
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
F = LIS.index(min(LIS))
if F == 0:
    ANS = LIS[0]
elif F == 1:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(1)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANSP = max(ANSU,ANSV)
    ANS = max(ANSP,LIS[N-1])
else:
    S = copy.copy(T)
    S.pop(F)
    LS = [0]*(N-1)
    LS[0] += S[0]
    for i in range(N-2):
        LS[i+1] += gcd(LS[i],S[i+1])
        ANS = max(LIS[N-1],LS[N-2])
        

print(ANS)

Submission status: Wrong Answer

Solution code:
import copy 

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

N = int(input())
T = list(map(int,input().split()))
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
F = LIS.index(min(LIS))
if F == 0:
    ANS = LIS[0]
elif F == 1:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(1)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANS = max(ANSU,ANSV)
else:
    S = copy.copy(T)
    S.pop(F)
    LS = [0]*(N-1)
    LS[0] += S[0]
    for i in range(N-2):
        LS[i+1] += gcd(LS[i],S[i+1])
        ANS = LS[N-2]

print(ANS)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from copy import deepcopy


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


input()
n = list(map(int, input().split()))
if len(n) == 1:
    print(n[0])
elif len(n) == 2:
    print(max(n))
else:
    g = [gcd(i, j) for i, j in zip(n[1:], n[:-1])]
    m = g.index(min(g))
    g1 = deepcopy(n)
    g1.pop(m)
    g2 = deepcopy(n)
    g2.pop(m + 1)
    r1 = reduce(gcd, g1)
    r2 = reduce(gcd, g2)
    print(max(r1, r2))

Submission status: Wrong Answer

Solution code:
# coding:UTF-8

"""
最大公約数を求める
"""
def CalcGCD(num1, num2):
    # 計算用の領域にコピー
    calc1 = num1
    calc2 = num2
    # 終了条件を考慮して、初期値は1
    remainder = 1

    while True:
        remainder = calc1 % calc2

        if remainder == 0:
            break

        calc1 = calc2
        calc2 = remainder

    return calc2

# 値の個数を取得
num_count = int(input())

# 最大公約数を求める対象の値群を取得
target_num = list(map(int, input().split()))

# 最大公約数格納用
cgd = 0

for i in range(num_count - 1):
    for j in range(i + 1, num_count):
        compare_work = CalcGCD(target_num[i], target_num[j])
    if cgd < compare_work:
        cgd = compare_work

print(cgd)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

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

max_gcd = 1
i_gcd = gcd_list(A[1:])
for i in range(1, N):
    if max_gcd < i_gcd:
        max_gcd = i_gcd
    i_gcd =  gcd_list(A[:(i-1)] + A[i:])

print(max_gcd)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

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

max_gcd = 1
for i in range(N):
    i_gcd =  gcd_list(A[:(i-1)] + A[i:])
    if max_gcd < i_gcd:
        max_gcd = i_gcd

print(max_gcd)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd


def checkN(num):
    try:
        if(2 <= num <= 10**5):
            return True
        else:
            return False

    except TypeError:
        return False


def checkAi(numList, N):
    try:
        isValid = True
        if(len(numList) != N):
            return False

        for num in numList:
            if(not 1 <= num <= 10**9):
                isValid = False
        return isValid

    except TypeError:
        return False


def getValidN():
    n = 0
    while True:
        n = int(input("N: "))
        if(checkN(n)):
            break
        print("2以上、10^5以下の数字を入力してください")
    return n


def getValidA(n):
    numList = []
    while True:
        strList = input("A: ")
        numList = [int(num) for num in strList.split()]
        if(checkAi(numList, n)):
            break
        print("1以上、10^9以下の数の並びを、Nと一緒の数だけスペースで区切って入力してください")
    return numList


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


if __name__ == "__main__":
    n = getValidN()
    numList = getValidA(n)

    ans = 0
    for i in range(n):
        li = numList[:i] + numList[i + 1:]
        tmp = gcd_list(li)
        if tmp > ans:
            ans = tmp

    print("ans= " + str(ans))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import copy
from functools import reduce
import fractions
 
def gcd2(n,a):
    i = 1
    array_front = []
    array_front.append(a[0])
    
    while i < n:
        array_front.append(fractions.gcd(array_front[i-1],a[i]))
        i = i + 1
    
    
    j = 1
    array_rev = []
    array_rev.append(a[n-1])
    
    while j < n:
        array_rev.append(fractions.gcd(array_rev[j-1],a[n-(j+1)]))
        j = j + 1
        
    del(array_front[0])
    del(array_rev[0])
    
    min_front = array_front.index(min(array_front))
    min_rev = array_rev.index(min(array_rev))
    
    if a[min_front+1] >= a[n-(min_rev+2)]:
        del(a[n-(min_rev+2)])
    else:
        del(a[min_front+1])
    
    k = 1
    num = a[0]
    
    while k < n-1:
        num = fractions.gcd(num,a[k])
        k = k +1
    
    return num
 
def gcd(n,a):
    array = []
    for i in range(n):
        change_list = copy.copy(a)
        del change_list[i]
        array.append((reduce(fractions.gcd,change_list)))
    return max(array)
 
 
n = int(input())    
a = list(map(int, input().strip().split()))
 
if n < 5:
    print(gcd(n,a))
else:
    print(gcd2(n,a))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import copy
from functools import reduce
import fractions
 
 
n = int(input())    
a = list(map(int, input().strip().split()))

i = 1
array_front = []
array_front.append(a[0])

while i < n:
    array_front.append(fractions.gcd(array_front[i-1],a[i]))
    i = i + 1


j = 1
array_rev = []
array_rev.append(a[n-1])

while j < n:
    array_rev.append(fractions.gcd(array_rev[j-1],a[n-(j+1)]))
    j = j + 1
    
del(array_front[0])
del(array_rev[0])

min_front = array_front.index(min(array_front))
min_rev = array_rev.index(min(array_rev))

if a[min_front+1] >= a[n-(min_rev+2)]:
    del(a[n-(min_rev+2)])
else:
    del(a[min_front+1])

k = 1
num = a[0]

while k < n-1:
    num = fractions.gcd(num,a[k])
    k = k +1

print(num)

Submission status: Wrong Answer

Solution code:
def gcd(x, y): 
    while(y): 
        x, y = y, x % y 
    return x 

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

  

for i in range(n):
    L[i] = gcd(L[i], L[i-1])

print(max(L))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
import fractions
d=a[0]
kari=[]
for i in range(n-1):
  e=a[i+1]-a[i]
  a[i]+=e
  for s in range(n):
   d=fractions.gcd(a[s],d)
  a[i]-=e
  kari.append(d)
  d=a[0]
 
for s in range(n-1):
 d=fractions.gcd(a[s],d)
kari.append(d)
 
print(max(kari))

Submission status: Wrong Answer

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

def gcd(a,b):
    m=max(a,b)
    n=min(a,b)
    while n!=0:
        l=m%n
        m=n
        n=l
    return m

def all_gcd(*args):
    n=len(args)
    g=args[0]
    for i in range(n):
        g=gcd(g,args[i])
    return g

l=[i for i in lis]
while len(l)>1:
    j=[l[i] for i in range(len(l)//2)]
    k=[l[i] for i in range(len(l)//2,len(l))]
    g_1=all_gcd(*j)
    g_2=all_gcd(*k)
    if g_1>=g_2:
        l=k
    else:
        l=j
        
lis.remove(l[0])
        
print(all_gcd(*lis))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
import fractions
d=a[0]
kari=[]
for i in range(n-1):
  e=a[i+1]-a[i]
  a[i]+=e
  for s in range(n):
   d=fractions.gcd(a[s],d)
  a[i]-=e
  kari.append(d)
  d=a[0]
 
for s in range(n-1):
 d=fractions.gcd(a[s],d)
kari.append(d)
 
print(kari)

Submission status: Wrong Answer

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

def gcd(a,b):
    m=max(a,b)
    n=min(a,b)
    while n!=0:
        l=m%n
        m=n
        n=l
    return m

def all_gcd(*args):
    n=len(args)
    g=args[0]
    for i in range(n):
        g=gcd(g,args[i])
    return g

l=[i for i in lis]
while len(l)>1:
    j=[l[i] for i in range(len(l)//2)]
    k=[l[i] for i in range(len(l)//2,len(l))]
    g_1=all_gcd(*j)
    g_2=all_gcd(*k)
    if g_1>=g_2:
        l=k
    else:
        l=j
    print(l)
    
print(lis)    
lis.remove(l[0])
print(lis)
        
print(all_gcd(*lis))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
ans = 0
ans_tmp1 = 0
ans_tmp2 = 0
for i in range(N):
    tmp_arr1 = A[:i]
    tmp_arr2 = A[i+1:]
    if tmp_arr1:
        ans_tmp1 = reduce(gcd,tmp_arr1)
    if tmp_arr2:
        ans_tmp2 = reduce(gcd,tmp_arr2)
    ans_tmp = gcd(ans_tmp1,ans_tmp2)
    if ans < ans_tmp:
        ans = ans_tmp
print(ans)