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:
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m


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

"順方向累積GCD"
forward_gcd = [0]

for i in range(0, N):
    forward_gcd.append(gcd(forward_gcd[-1], A[i]))

"逆方向累積GCD"
reverse_gcd = [0]
for i in range(N-1, -1, -1):
    reverse_gcd.append(gcd(reverse_gcd[-1], A[i]))

reverse_gcd.reverse()

ans = 0
for i in range(N-1):
    ans = max(ans, gcd(forward_gcd[i], reverse_gcd[i+1]))

print(ans)

Submission status: Wrong Answer

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


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

"順方向累積GCD"
forward_gcd = [max(A)]

for i in range(0, N):
    forward_gcd.append(gcd(forward_gcd[-1], A[i]))

"逆方向累積GCD"
reverse_gcd = [max(A)]
for i in range(N-1, -1, -1):
    reverse_gcd.append(gcd(reverse_gcd[-1], A[i]))

reverse_gcd.reverse()

ans = 0
for i in range(N-1):
    ans = max(ans, gcd(forward_gcd[i], reverse_gcd[i+1]))

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
import numpy as np
nums = list(set([int(i) for i in input().split()]))
for i in reversed(range(2,max(nums)+1)):
    if np.count_nonzero((np.array(nums) % i) != 0) <= 1:
        print(i)
        break

Submission status: Wrong Answer

Solution code:

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A_reverse = list(reversed(A))
    left = [0]
    right = [0]
    answer = []
    for n in range(N):
        left.append(gcd(left[n], A[n]))
        right.append(gcd(right[n], A_reverse[n]))
    del left[N]
    del right[N]
    right.reverse()
    for n in range(N-1):
        answer.append(gcd(left[n], right[n]))
    print(max(answer))


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A_reverse = list(reversed(A))
    left = [0]
    right = [0]
    answer = []
    for n in range(N-1):
        left.append(gcd(left[n], A[n]))
        right.append(gcd(right[n], A_reverse[n]))
    right.reverse()
    for n in range(N-1):
        answer.append(gcd(left[n], right[n]))
    print(max(answer))


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
n = int(input())
a = list(map(int,input().split()))
gcds = 0
r = [0]
l = [0]
for N in range(n):
	r.append(fractions.gcd(r[N],a[N]))
	l.append(fractions.gcd(l[N],a[n - N - 1]))
for i in range(n + 1):
	gcds = max(gcds,(fractions.gcd(r[i],l[n - i])))
print(gcds)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [x for x in A]
A.sort(reverse=True)
k = 2

while len(B) > 1:
    B = [x for x in B if x % k != 0]
    k += 1

if len(B) == 1:
    del A[A.index(B[0])]

ans = A[0]

for l in A:
    ans = fractions.gcd(l, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

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

def gcd_pop(L,I,N):
  L1=L[0:I]
  L2=L[I:N]
  L1.extend(L2)
  return gcd_list(L1)

l=[gcd_pop(a,i,n) for i in range(n)]

print(max(l))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

count=0
ans=0

for i in range(N):
    if a[i]<0:
        count+=1
        a[i]=abs(a[i])

if count%2==0:
    ans=sum(a)

else:
    a.sort()
    ans=sum(a)-a[0]*2

print(ans)

Submission status: Wrong Answer

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

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

gcd_all = reduce(gcd, A)

for i in range(N-1):
    #gcd_1 = reduce(gcd, (A[:i]+A[i+1:]))
    gcd_1 = gcd(A[i],A[i+1])

    if gcd_1 >= gcd_all:
        gcd_all = gcd_1

print(gcd_all)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

def check(n, ary):
    ln = len(ary)
    ins = 0
    for i in ary:
        if i % n == 0:
            ins += 1
    if ins >= ln - 1:
        return True
    else:
        return False

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    
    a.sort()
    for i in a:
        if check(i, a):
            print(i)
            break
        num = i // 2
        for j in range(num, 1, -1):
            if i % j == 0:
                if check(j, a):
                    print(j)
                    exit();

Submission status: Wrong Answer

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

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

g_l = [1 for i in range(N)]
g_r = [1 for i in range(N)]

g_l[0] = A[0]
g_r[-1] = A[-1]

for i in range(1, N):
    g_l[i] = gcd(A[i], g_l[i-1])
    g_r[-i-1] = gcd(A[-i-1], g_r[-i])

ans = max(g_r[1], g_l[-2])
for i in range(1, N-1):
    ans = max(ans, gcd(A[i-1], A[i+1]))

print(ans)

Submission status: Wrong Answer

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

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

g_l = [1 for i in range(N)]
g_r = [1 for i in range(N)]

g_l[0] = A[0]
g_r[-1] = A[-1]

for i in range(1, N):
    g_l[i] = gcd(A[i], g_l[i-1])
    g_r[-i-1] = gcd(A[-i-1], g_r[-i])

ans = max(g_r[1], g_l[-2])
for i in range(1, N-1):
    ans = max(ans, gcd(A[i-1], A[i+1]))

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

def check(n, ary):
    ln = len(ary)
    ins = 0
    for i in ary:
        if i % n == 0:
            ins += 1
    if ins >= ln - 1:
        return True
    else:
        return False

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    
    a.sort()
    n = 0
    for i in a:
        for j in range(1, i+1):
            if i % j == 0:
                n = i // j
                if check(n, a):
                    print(n)
                    exit();

Submission status: Wrong Answer

Solution code:
N = int(input())

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

print(max(A) - min(A))

Submission status: Wrong Answer

Solution code:
import fractions

N = int(input())
A = [int(i) for i in input().split()]
B = []
C = []
if N > 3:
  i = A[0]
  for j in A[1:]:
    B.append(fractions.gcd(i, j))
  B.sort()

  i = A[1]
  for j in [A[0]]+A[2:]:
    C.append(fractions.gcd(i, j))
  C.sort()
  print(max(fractions.gcd(B[1], B[2]),fractions.gcd(C[1], C[2])))
elif N == 3:
  print(max(fractions.gcd(A[0], A[1]), fractions.gcd(A[1], A[2]), fractions.gcd(A[0], A[2])))
else:
  print(max(A))

Submission status: Wrong Answer

Solution code:
import fractions

N = int(input())
A = [int(i) for i in input().split()]
B = []
C = []
if N > 3:
  i = A[0]
  for j in A[1:]:
    B.append(fractions.gcd(i, j))
  B.sort()

  i = A[1]
  for j in [A[0]]+A[2:]:
    C.append(fractions.gcd(i, j))
  C.sort()

  print(max(fractions.gcd(B[1], B[2]),fractions.gcd(B[1], B[2])))
elif N == 3:
  print(max(fractions.gcd(A[0], A[1]), fractions.gcd(A[1], A[2]), fractions.gcd(A[0], A[2])))
else:
  print(max(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]

def gcd(x, y):
    #print('gcd({0},{1})'.format(x,y))
    if (y==0):
        return x
    else:
        return gcd(y, x%y)

def gcd_left(i):
    #print('gcd_left({0})'.format(i))

    if i<=-1:
        return 0
    else:
        if l[i]:
            return gcd(gcd_left(i-1), a[i])
        else:
            l[i] = gcd( gcd_left(i-1), gcd_right(i+1))


def gcd_right(i):
    #print('gcd_left({0})'.format(i))
    
    if i>=n:
        return 0
    else:
        return gcd( a[i], gcd_right(i+1))

def gcd_left_update(ls, i):
    print('gcd_left({0})'.format(i))

    if i<0:
        return 0
    elif i==0:
        return a[i]
    else:        
        return gcd(ls[i-1], a[i])


def gcd_right_update(ls, i):
    print('gcd_right({0})'.format(i))
    
    if i>=n:
        return 0
    elif i==n-1:
        return a[i]
    else:
        return gcd( a[i], ls[i+1])

def gcd_excepts(i):
    #print('gcd_excepts({0})'.format(i))
    return gcd( gcd_left(i-1), gcd_right(i+1))

def gcd_excepts2(i):
    print('gcd_excepts({0})'.format(i))
    left = 0
    right = 0
    if i-1<0:
        left = 0
    else:
        left = l[i-1]
    
    if i+1>=n:
        right = 0
    else:
        right = r[i]
        
    return gcd( left, right )

l = [None for i in range(n)]
for i in range(n):
    l[i] = gcd_left_update(l,i)

r = [None for i in range(n)]
for i in reversed(range(n)):
    r [i] = gcd_right_update(r,i)
    
m = [gcd_excepts2(i) for i in range(n)]

print(max(m))

Submission status: Wrong Answer

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

for i in range(N):
  for j in range(i+1,N):
    if A[i]>A[j]:
      r=A[i]%A[j]
      while r!=0:
        A[i]=A[j]
        A[j]=r
        r=A[i]%A[j]
      memo=A[j]
      if max<memo:
        max=memo
        
    elif A[j]>=A[i]:
      r=A[j]%A[i]
      while r!=0:
        A[j]=A[i]
        A[i]=r
        r=A[j]%A[i]
      memo=A[i]
      if max<memo:
        max=memo

print(max)

Submission status: Wrong Answer

Solution code:
def euclid(a, b):
    mod = a % b
    if mod != 0:
        b = euclid(b, mod)
    return b
N = int(input())
A = [int(a) for a in input().split()]
gcd_lis = []
inv_gcd_lis = []
gcd = A[0]
for a in A[1:]:
    gcd = euclid(gcd, a)
    gcd_lis.append(gcd)
gcd = A[-1]
for a in A[-2::-1]:
    gcd = euclid(gcd, a)
    inv_gcd_lis.append(gcd)
print(gcd_lis)
print(inv_gcd_lis[::-1])

Submission status: Wrong Answer

Solution code:
import fractions
import copy
n = int(input())
a = list(map(int, input().split()))
a_r = copy.copy(a)
a_r.reverse()
cumsum_gcd = [0]
cumsum_gcd_r = [0]
for i in range(n-1):
    cumsum_gcd.append(fractions.gcd(cumsum_gcd[i], a[i]))
    cumsum_gcd_r.append(fractions.gcd(cumsum_gcd_r[i], a_r[i]))
cumsum_gcd_r.reverse()
print(cumsum_gcd, cumsum_gcd_r)
ans = []
for i in range(n):
    ans.append(fractions.gcd(cumsum_gcd[i], cumsum_gcd_r[i]))
print(max(ans))

Submission status: Wrong Answer

Solution code:
import fractions
import copy
n = int(input())
a = list(map(int, input().split()))
a_r = copy.copy(a)
a_r.reverse()
cumsum_gcd = [0]
cumsum_gcd_r = [0]
for i in range(n-1):
    cumsum_gcd.append(fractions.gcd(cumsum_gcd[i], a[i]))
    cumsum_gcd_r.append(fractions.gcd(cumsum_gcd_r[i], a_r[i]))
print(cumsum_gcd, cumsum_gcd_r)
ans = []
for i in range(n-1):
    ans.append(fractions.gcd(cumsum_gcd[i], cumsum_gcd_r[i]))
print(max(ans))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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



# L[0] = 0
# L[i] (i=1, ..., N)にはA_1, ..., A_iの最大公約数が格納されている

L = []
L.append(A[0])

for i in range(N):
    L.append(gcd(L[i], A[i]))

#  for i in range(N+1):
    #  print(L[i])


# R[N+1] = 0
# R[i] (i=N, N-1, ..., 1)にはA_i, ..., A_Nの最大公約数が格納されている

R = [0] * (N+2)
# R = [0, 0, 0, ... , 0] (0がN+2個)
R[N+1] = A[N-1]

for i in range(N, 0, -1):
    R[i] = gcd(A[i-1], R[i+1])

#  for i in range(N+1, -1, -1):
    #  print(R[i])



# M[i] (i=0, ..., N-1)にはA_(i+1)を除いた整数の最大公約数が格納されている

M = []
for i in range(N):
    M.append(gcd(L[i], R[i+2]))

print(max(M))

Submission status: Wrong Answer

Solution code:
import fractions
import copy
n = int(input())
a = list(map(int, input().split()))
a_r = copy.copy(a)
a_r.reverse()
cumsum_gcd = [0]
cumsum_gcd_r = [0]
for i in range(n-1):
    cumsum_gcd.append(fractions.gcd(cumsum_gcd[i], a[i]))
    cumsum_gcd_r.append(fractions.gcd(cumsum_gcd_r[i], a_r[i]))
cumsum_gcd_r.reverse()
ans = []
for i in range(n-1):
    ans.append(fractions.gcd(cumsum_gcd[i], cumsum_gcd_r[i]))
print(max(ans))

Submission status: Wrong Answer

Solution code:
import fractions
import copy
n = int(input())
a = list(map(int, input().split()))
a_r = copy.copy(a)
a_r.reverse()
cumsum_gcd = [0]
cumsum_gcd_r = [0]
for i in range(n):
    cumsum_gcd.append(fractions.gcd(cumsum_gcd[i], a[i]))
    cumsum_gcd_r.append(fractions.gcd(cumsum_gcd_r[i], a_r[i]))
cumsum_gcd_r.reverse()
ans = []
for i in range(n):
    ans.append(fractions.gcd(cumsum_gcd[i], cumsum_gcd_r[i]))
print(max(ans))

Submission status: Wrong Answer

Solution code:
import fractions
import copy
n = int(input())
a = list(map(int, input().split()))
a_r = copy.copy(a)
a_r.reverse()
cumsum_gcd = [0]
cumsum_gcd_r = [0]
for i in range(n-1):
    l_gcd = fractions.gcd(cumsum_gcd[i], a[i])
    r_gcd = fractions.gcd(cumsum_gcd_r[i], a_r[i])
    cumsum_gcd.append(l_gcd)
    cumsum_gcd_r.append(r_gcd)
cumsum_gcd_r.reverse()
ans = []
for i in range(n-1):
    ans.append(fractions.gcd(cumsum_gcd[i], cumsum_gcd_r[i]))
print(max(ans))

Submission status: Wrong Answer

Solution code:
import fractions
import copy
n = int(input())
a = list(map(int, input().split()))
a_r = copy.copy(a)
a_r.reverse()
cumsum_gcd = [0]
cumsum_gcd_r = [0]
for i in range(n):
    l_gcd = fractions.gcd(cumsum_gcd[i], a[i])
    r_gcd = fractions.gcd(cumsum_gcd_r[i], a_r[i])
    cumsum_gcd.append(l_gcd)
    cumsum_gcd_r.append(r_gcd)
cumsum_gcd_r.reverse()
ans = []
for i in range(n):
    ans.append(fractions.gcd(cumsum_gcd[i], cumsum_gcd_r[i]))
print(max(ans))

Submission status: Wrong Answer

Solution code:
import fractions
import copy
n = int(input())
a = list(map(int, input().split()))
a_r = copy.copy(a)
a_r.reverse()
cumsum_gcd = [0]
cumsum_gcd_r = [0]
l_gcd = a[0]
r_gcd = a_r[0]
for i in range(n):
    l_gcd = fractions.gcd(l_gcd, a[i])
    r_gcd = fractions.gcd(r_gcd, a_r[i])
    cumsum_gcd.append(l_gcd)
    cumsum_gcd_r.append(r_gcd)
cumsum_gcd_r.reverse()
ans = []
for i in range(n):
    ans.append(fractions.gcd(cumsum_gcd[i], cumsum_gcd_r[i]))
print(max(ans))

Submission status: Wrong Answer

Solution code:
import fractions
import copy
n = int(input())
a = list(map(int, input().split()))
a_r = copy.copy(a)
a_r.reverse()
cumsum_gcd = [0]
cumsum_gcd_r = [0]
l_gcd = a[0]
r_gcd = a_r[0]
for i in range(n-1):
    l_gcd = fractions.gcd(l_gcd, a[i])
    r_gcd = fractions.gcd(r_gcd, a_r[i])
    cumsum_gcd.append(l_gcd)
    cumsum_gcd_r.append(r_gcd)
cumsum_gcd_r.reverse()
ans = []
for i in range(n-1):
    ans.append(fractions.gcd(cumsum_gcd[i], cumsum_gcd_r[i]))
print(max(ans))

Submission status: Wrong Answer

Solution code:
import fractions
import copy
n = int(input())
a = list(map(int, input().split()))
a_r = copy.copy(a)
a_r.reverse()
cumsum_gcd = [0]
cumsum_gcd_r = [0]
l_gcd = a[0]
r_gcd = a_r[0]
for i in range(n-1):
    l_gcd = fractions.gcd(l_gcd, a[i])
    r_gcd = fractions.gcd(r_gcd, a_r[i])
    cumsum_gcd.append(l_gcd)
    cumsum_gcd_r.append(r_gcd)
cumsum_gcd_r.reverse()
maxgcd = 0
for i in range(n-1):
    val = fractions.gcd(cumsum_gcd[i], cumsum_gcd_r[i])
    if val > maxgcd:
        maxgcd = val
print(maxgcd)

Submission status: Wrong Answer

Solution code:
#2つの値の最大公約数
def gcd(a,b):
    if(b==0):
        return a
    return gcd(b,a%b)

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

M=max(A)
num=A[0]
#print(M)
for i  in  range(N-1):
    num=gcd(num,A[i+1])
    if(num==1):
        break

print(num)

Submission status: Wrong Answer

Solution code:
#1を一つ含む場合はflag3
#二つ含む場合はflag4
A=[]
n=int(input())
A=input().split()
A=[int(i) for i in A]
A.sort()
flag=False
flag2=False
flag3=False
flag4=False
key=0
Temp=False
 
if len(A)!=1 and A[1]!=1 and A[0]!=1:
    for i in range(n-1,0,-1):
        if A[i]%A[0]!=0: break
        if i==1: flag2=True

if A[0]==1 and A[1]!=1 and len(list(set(A)))!=2:#1が一つ
    del A[0]
    if len(A)!=1 and A[1]!=1 and A[0]!=1:
        for i in range(n-2,0,-1):
            if A[i]%A[0]!=0: break
            if i==1: Temp=True
        if Temp==True:
            flag3=True
            key=A[0]
        else:
            flag3=True
            key=1
        
if A[0]==1 and A[1]==1 and len(list(set(A)))!=2:#1が二つ
    key=1
    flag4=True
    
    
if flag4!=True and flag3!=True:
    if flag2==True: key=A[1]
    elif A.count(A[0])==n: key=A[0]
    elif len(list(set(A)))==2:
        if A[0]==A[1]: key=A[0]
        else: key=A[n-1]
    else:
        for i in range(A[0],1,-1):
            cnt=0
            for j in range(n):
                if A[j]%i!=0: cnt+=1
                if 2<=cnt: break
                if j==n-1:
                    key=i
                    flag=True
                    break
            if flag==True:
                break
print(key)

Submission status: Wrong Answer

Solution code:
A=[]
n=int(input())
A=input().split()
A=[int(i) for i in A]
A.sort()
flag=False
flag2=False
key=0
 
if len(A)!=1 and A[1]!=1 and A[0]!=1:
    for i in range(n-1,0,-1):
        if A[i]%A[0]!=0: break
        if i==1: flag2=True

if flag2==True: key=A[1]
elif A.count(A[0])==n: key=A[0]
elif len(list(set(A)))==2:
    if A[0]==A[1]: key=A[0]
    else: key=A[n-1]
else:
    for i in range(A[0],1,-1):
        cnt=0
        for j in range(n):
            if A[j]%i!=0: cnt+=1
            if 2<=cnt: break
            if j==n-1:
                key=i
                flag=True
                break
        if flag==True:
            break
print(key)

Submission status: Wrong Answer

Solution code:
from functools import reduce
import fractions
N=int(input())
a = list(map(int, input().split()))
key=[]

Copy=a[:]

flag=False

a.sort()
if len(a)!=1 and a[1]!=1:
    for i in range(N-1,0,-1):
        if a[i]%a[0]!=0: break
        if i==1: flag=True
s=a[:]

a=list(set(a))
n=len(a)

if len(a)==len(Copy):
    for j in range(len(a)):
        tmp=a[:]
        del tmp[j]
        for i in range(len(a)):
            ans=reduce(fractions.gcd, tmp)
        key.append(ans)
elif len(a)==1: key.append(a[0])
elif len(a)==2:
    Copy.sort()
    if a[0]==a[1]: key.append(Copy[0])
    else: key.append(Copy[1])
elif flag==False:
    for i in range(len(a)):
        ans=reduce(fractions.gcd,a)
    key.append(ans)
else: key.append(s[1])

print(max(key))

Submission status: Wrong Answer

Solution code:
from functools import reduce
import fractions
N=int(input())
a = list(map(int, input().split()))
key=[]

Copy=a[:]
a=list(set(a))

if len(a)!=1 and len(a)!=2:
    for j in range(len(a)):
        tmp=a[:]
        del tmp[j]
        for i in range(len(a)):
            ans=reduce(fractions.gcd, tmp)
        key.append(ans)
    
elif len(a)==1: key.append(a[0])
else:
    Copy.sort()
    if a[0]==a[1]: key.append(Copy[0])
    else: key.append(Copy[1])
print(max(key))

Submission status: Wrong Answer

Solution code:
from functools import reduce
import fractions
N=int(input())
a = list(map(int, input().split()))
key=[]

a=list(set(a))

if len(a)!=1 and len(a)!=2:
    for j in range(len(a)):
        tmp=a[:]
        del tmp[j]
        for i in range(len(a)):
            ans=reduce(fractions.gcd, tmp)
        key.append(ans)
    
elif len(a)==1: key.append(a[0])
else:
    a.sort()
    if a[0]==a[1]: key.append(a[0])
    else: key.append(a[1])
print(max(key))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

L = [A[0]]
R = [A[-1]]

for i in range(1, N):
    L.append(gcd(A[i], L[i-1]))
    R.append(gcd(A[-(i+1)], R[i-1]))

def it(i):
    if i == 0:
        return R[N-2]
    if i == N-1:
        return L[N-2]
    return gcd(L[i-1], R[i-1])

print(max(it(i) for i in range(N)))

Submission status: Wrong Answer

Solution code:
import fractions as math



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

L = [0]
R = [0]
#Find GCD from right and left
for i in range(1,N+1):
    gcdL = math.gcd(L[i-1],A[i-1])
    L.append(gcdL)
    gcdR = math.gcd(R[i-1],A[N-i])
    R.append(gcdR)

#reverse R
R = R[::-1]

#find GCD of N-1 elements
GCD = []
for i in range(N-1):
    gcdcombination = math.gcd(L[i],R[i+1])
    GCD.append(gcdcombination)


#the answer
print(max(GCD))

Submission status: Wrong Answer

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

g=0
n=int(input())
a=list(map(int, input().split()))
for i in range(n):
	for j in range(n):
		if i == j: continue
		g=max(g, gcd(max(a[i],a[j]), min(a[i],a[j])))
print(g)

Submission status: Wrong Answer

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

g=0
n=int(input())
a=sorted(list(map(int, input().split())))
a_max=a[-1]
for i in range(len(a)-1):
	g = max(g, gcd(a_max,a[i]))
print(g)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n=int(input())
a=input().split(" ")
a=[int(j) for j in a]
a.sort()
count=0
divisor=0
divised=0
for divisor in range(1,(max(a[0:2])+1)//2):
    for i in range(n):
        if a[i]%divisor!=0:
            count=count+1
    if count<2:
        divised=divisor
    count=0
divisor=max(a[0:2])
for i in range(n):
    if a[i]%divisor!=0:
        count=count+1
if count<2:
    divised=divisor
print(divised)

Submission status: Wrong Answer

Solution code:
A=[]
n=int(input())
A=input().split()
A=[int(i) for i in A]
A.sort()
flag=False
flag2=False
key=0


if len(A)!=1 and A[1]!=1:
    for i in range(n-1,0,-1):
        if A[i]%A[0]!=0: break
        if i==1: flag2=True
        
if len(A)!=1 and A[1]!=1:
    for i in range(n-1,0,-1):
        if A[i]%A[1]!=0: break
        if i==1: flag2=True

if A[0]==1 and A[1]!=1 and i==-1:
    del A[0]

if A.count(A[0])==len(A): key=A[0] #一文字だけ
elif len(list(set(A)))==2:   #二文字だけ
    if A[0]==A[1]: key=A[0]
    else: key=A[len(A)-1]
elif flag2==True: key=A[1]  

else:
    for i in range(A[0],1,-1):
        cnt=0
        for j in range(len(A)):
            if A[j]%i!=0: cnt+=1
            if 2<=cnt: break
            if j==len(A)-1:
                key=i
                flag=True
                break
        if flag==True:
            break
print(key)

Submission status: Wrong Answer

Solution code:
A=[]
n=int(input())
A=input().split()
A=[int(i) for i in A]
A.sort()
flag=False
flag2=False
key=0


if len(A)!=1 and A[1]!=1:
    for i in range(n-1,0,-1):
        if A[i]%A[0]!=0: break
        if i==1: flag2=True

if A[0]==1 and A[1]!=1 and i==-1:
    del A[0]

if A.count(A[0])==len(A): key=A[0] #一文字だけ
elif len(list(set(A)))==2:   #二文字だけ
    if A[0]==A[1]: key=A[0]
    else: key=A[len(A)-1]
elif flag2==True: key=A[1]  

else:
    for i in range(A[0],1,-1):
        cnt=0
        for j in range(len(A)):
            if A[j]%i!=0: cnt+=1
            if 2<=cnt: break
            if j==len(A)-1:
                key=i
                flag=True
                break
        if flag==True:
            break
print(key)

Submission status: Wrong Answer

Solution code:
A=[]
n=int(input())
A=input().split()
A=[int(i) for i in A]
A.sort()
flag=False
flag2=False
key=0

if len(A)!=1 and A[1]!=1:
    for i in range(n-1,-1,-1):
        if A[i]%A[1]!=0: break
        if i==n-1: flag2=True

if A.count(A[0])==n: key=A[0]
elif len(list(set(A)))==2:
    if A[0]==A[1]: key=A[0]
    else: key=A[n-1]
elif flag2==True: key=A[1]
else:
    for i in range(A[0],1,-1):
        cnt=0
        for j in range(n):
            if A[j]%i!=0: cnt+=1
            if 2<=cnt: break
            if j==n-1:
                key=i
                flag=True
                break
        if flag==True:
            break
print(key)

Submission status: Wrong Answer

Solution code:
A=[]
n=int(input())
A=input().split()
A=[int(i) for i in A]
A.sort()
flag=False
key=0


if A.count(A[0])==n: key=A[0]
elif len(list(set(A)))==2:
    if A[0]==A[1]: key=A[0]
    else: key=A[n-1]
else:
    for i in range(A[0],1,-1):
        cnt=0
        for j in range(n):
            if A[j]%i!=0: cnt+=1
            if 2<=cnt: break
            if j==n-1:
                key=i
                flag=True
                break
        if flag==True:
            break
print(key)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

A[0] = 1

print(A[0])

Submission status: Wrong Answer

Solution code:
from fractions import gcd

N = int(input())
A = input().split()
a = [int(A[i]) for i in range(len(A))]
b = [gcd(a[x], a[0 if (x+1) == N else x+1]) for x in range(N)]
c = 0

for i in range(len(b)):
    if(min(a) < max(b)):
        c = min(a)
    else:
        c = max(b)
print(c)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

N = int(input())
A = input().split()
a = [int(A[i]) for i in range(len(A))]
b = []
c = 0
for i in range(N):
    b.append(gcd(a[i], a[0 if (i+1) == N else i+1]))
for i in range(len(b)):
    if(min(a) < max(b)):
        c = min(a)
    else:
        c = max(b)
print(c)

Submission status: Wrong Answer

Solution code:
from functools import reduce


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


def lcm(a, b):
    return a * b // gcd(a, b)


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

l = [0 for i in range(n)]
for i in range(0, n - 2, 1):
    l[i + 1] = gcd(l[i], a[i])

r = [0 for i in range(n)]
for i in range(n - 2, 0, -1):
    r[i] = gcd(r[i + 1], a[i + 1])

m = [gcd(l[i], r[i]) for i in range(n)]

print(reduce(max, m))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

N = int(input())
A = input().split()
a = [int(A[i]) for i in range(len(A))]
b = []
for i in range(N):
    b.append(gcd(a[i], a[0 if (i+1) == N else i+1]))

print(max(b))

Submission status: Wrong Answer

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

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

ans = 1
tmp = 0
for i in range(n):
    _a = a[:]
    _a.pop(i)
    tmp = _a[0]
    for j in range(1,n-1):
        tmp = gcd(tmp,_a[j])
        if tmp > ans:
            ans = tmp

if min(a) == max(a):
    print(max(a))
else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
N=int(input())
A=set(map(int,input().split()))
l=[]
for i in A:
    if len(A-{i})>1:
        l.append(reduce(fractions.gcd,A-{i}))
    else:
        l.append(i)
print(max(l))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
N=int(input())
A=set(map(int,input().split()))
l=[]
for i in A:
    if A-{i}!=set():
        l.append(reduce(fractions.gcd,A-{i}))
    else:
        l.append(i)
print(max(l))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
N=int(input())
A=set(map(int,input().split()))
l=[]
for i in A:
    l.append(reduce(fractions.gcd,A-{i},i))
print(max(l))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
N=int(input())
A=set(map(int,input().split()))
l=[]
for i in A:
    l.append(reduce(fractions.gcd,A-{i},0))
print(max(l))

Submission status: Wrong Answer

Solution code:
import fractions
import itertools
n = int(input())
x = list(map(int,input().split()))
p = list(itertools.combinations(x,2))
# ar = 0
tx = []
p = list(itertools.combinations(x,2))
# ar = 0
def ar_gen(pn0,pn1,ar):
    # ar =0
    ar=max(fractions.gcd(pn0,pn1),ar)
    yield ar
    tx.append(ar)
#print(len(p))

# gen = ar_gen()

for n in range(0,len(p)):
    pn0= p[n][0]
    pn1 =p[n][1]
    for _ in ar_gen(pn0,pn1,ar=0): 
        pass
        
print(max(tx))

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    l = max(a,b)
    s = min(a,b)
    if s == 0:
        return l
    else:
        return gcd(s, l%s)

n = int(input())
a = [0] + list(map(int, input().split())) + [0]
max_gcd = 1
L = [0] * (n+2)
R = [0] * (n+2)

for i in range(1,n+2):
    L[i] = gcd(a[i],L[i-1])
    R[n+1-i] = gcd(a[n+1-i], R[n+2-i])
for i in range(1,n+1):
    max_gcd = max(L[i-1], R[i+1])

print(max_gcd)

Submission status: Wrong Answer

Solution code:

import fractions
a = int(input())
num_list = list(map(int, input().split()))
head_gcd_list = [0]
tail_gcd_list = [0]
for i in range(a - 1):
    head_gcd_list.append(fractions.gcd(head_gcd_list[i], num_list[i]))
    tail_gcd_list.append(fractions.gcd(tail_gcd_list[(i*-1) - 1], num_list[(i*-1) - 1]))
max_gcd = 0
for i,j in zip(head_gcd_list, reversed(tail_gcd_list)):
    current_gcd = fractions.gcd(i, j)
    if(current_gcd > max_gcd):
        max_gcd = current_gcd
print(max_gcd)

Submission status: Wrong Answer

Solution code:

import fractions
a = int(input())
num_list = list(map(int, input().split()))
head_gcd_list = [0]
tail_gcd_list = [0]
for i in range(a - 1):
    head_gcd_list.append(fractions.gcd(head_gcd_list[i], num_list[i+1]))
    tail_gcd_list.append(fractions.gcd(tail_gcd_list[(i*-1) - 1], num_list[(i*-1) - 1]))
max_gcd = 0
for i,j in zip(head_gcd_list, reversed(tail_gcd_list)):
    current_gcd = fractions.gcd(i, j)
    if(current_gcd > max_gcd):
        max_gcd = current_gcd
print(max_gcd)

Submission status: Wrong Answer

Solution code:

import fractions
a = int(input())
num_list = list(map(int, input().split()))
head_gcd_list = [num_list[0]]
tail_gcd_list = [num_list[-1]]
for i in range(a - 2):
    head_gcd_list.append(fractions.gcd(head_gcd_list[i], num_list[i+1]))
    tail_gcd_list.append(fractions.gcd(tail_gcd_list[(i*-1) - 1], num_list[(i*-1) - 2]))
max_gcd = max(head_gcd_list.pop(-1), tail_gcd_list.pop(-1))
for i,j in zip(head_gcd_list, reversed(tail_gcd_list)):
    current_gcd = fractions.gcd(i, j)
    if(current_gcd > max_gcd):
        max_gcd = current_gcd
print(max_gcd)

Submission status: Wrong Answer

Solution code:
from functools import reduce
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

n=int(input())
a=list(map(int,input().split()))
#n=2
#a=[1000000000,1000000000]
a=sorted(a)[::-1]
temp_ans=a[0]
ans=a[0]
anslist=[]
if n==2:
    anslist.append(max(a))
else:
    for i in range(1,n-1):
        l=a[0:i]
        r=a[i+1:n]
        temp_ans = gcd(reduce(gcd, l),reduce(gcd,r))
        anslist.append(temp_ans)
print(max(anslist))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
ans=1
l=[a[0]]+[0]*n
r=[0]*n+[a[n-1]]
for i in range(n):
    l[i]=gcd(l[i-1],a[i])
for i in reversed(range(n)):
    r[i]=gcd(r[i+1],a[i])
for i in range(n):
    if gcd(l[i-1],r[i+1])>ans:
        ans=gcd(l[i-1],r[i+1])
print(ans)