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:
N = int(input())
l = [int(i) for i in input().split()]

def make_divisors(n,m):
    divisors = []
    for i in range(1, n):
        if n % i == 0:
            if m % i == 0:
                divisors.append(i)
    return divisors

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

if N == 2:
    print(max(l))
elif N == 3:
    print(max(gcd(l[0],l[1]),gcd(l[0],l[2]),gcd(l[1],l[2])))
else:
    p = make_divisors(l[0],l[1])
    p.extend(make_divisors(l[2],l[3]))
    p = set(p)
    ans = 1
    for i in p:
        flag = 0
        for j in range(N):
            if l[j]%i != 0:
                if flag != 0:
                    break
                flag = 1
        ans = max(ans,i)
    print(ans)

Submission status: Wrong Answer

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

import fractions
from functools import reduce

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

keep = 0
score = 1
for i in range(N):
    B = A
    if keep % score != 0:
        continue
    keep = B.pop(0)
    n = gcd_list(B)
    if n > score:
        score = n
    A.append(keep)


print(score)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
def gcd(x, y):
    if x<y:x,y=y,x
    while x % y != 0:
        x, y = y, x % y
    return y
left=[]
right=[]
for i in range(n):
    if i==0:
        left.append(a[i])
        right.append(a[-i-1])
    else:
        left.append(gcd(a[i],left[i-1]))
        right.append(gcd(a[-i-1],right[i-1]))
ans=max(left[n-2],right[n-2])
for i in range(n-2):
    ans=max(ans,gcd(left[i],right[n-i-2]))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from functools import reduce


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))

def SUM(x):return sum([abs(x) for x in a ])



sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()

a = LIST()

g=[]

for i in range(n):
    for j in range(i, n):
        g = gcd(a[i], a[j])
        if [x % g for x in a].count(0) == n - 1:
            print(g)

Submission status: Wrong Answer

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

this_gcd = max(a)
gcd_list = []
R = [a[-1]]
L = [a[0]]
for i in range(1, n - 1):
    L.append(fractions.gcd(a[i], L[i - 1]))
    R.append(fractions.gcd(a[n - i - 1], R[i - 1]))
    #print(L, R)

ans = R[-1]
for i in range(1, n - 1):
    ans = max(ans, fractions.gcd(L[i - 1], R[i - 1]))

ans = max(ans, L[-1])

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

input = sys.stdin.readline
n = int(input())
a_list = list(map(int, input().split()))
ans = 1
for i in range(n):
    if i == 0 or i == n-1:
        gcd_tmp = 0
        tmp_list = a_list[i+1:]
        for tmp in tmp_list:
            if gcd_tmp == 0:
                gcd_tmp = tmp
            else:
                gcd_tmp = gcd(gcd_tmp, tmp)
        m = gcd_tmp
    else:
        gcd_l, gcd_r = 0, 0
        l_list = a_list[:i]
        r_list = a_list[i+1:]
        for l in l_list:
            if gcd_l == 0:
                gcd_l = l
            else:
                gcd_l = gcd(gcd_l, l)
        for r in r_list:
            if gcd_r == 0:
                gcd_r = r
            else:
                gcd_r = gcd(gcd_r, r)
        m = gcd(gcd_l, gcd_r)
    ans = max(ans, m)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
N = int(input())
A = [int(i) for i in input().split()]
L = [A[0]] * N
R = [A[-1]] * N
for i, a in enumerate(A[1:]):
    L[i+1] = gcd(a, L[i])
for i, a in enumerate(A[::-1][1:]):
    R[i+1] = gcd(a, R[i])
L = [0] + L
R = R + [0]
ans = 0
for i in range(N):
    ans = max(ans, gcd(L[i], R[i+1]))
print(ans)

Submission status: Wrong Answer

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

this_gcd = max(a)
gcd_list = []
R = [a[-1]]
L = [a[0]]
for i in range(1, n - 1):
    L.append(fractions.gcd(a[i], L[i - 1]))
    R.append(fractions.gcd(a[n - i - 1], R[i - 1]))
    #print(L, R)

ans = L[-1]
for i in range(1, n - 1):
    ans = max(ans, fractions.gcd(L[i - 1], R[i - 1]))

ans = max(ans, L[-1])

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

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

for i in range(n):
  temp = fractions.gcd(ans,a[i])
  if temp != ans:
    ans = max(temp,x)
    x= fractions.gcd(temp,x)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

input = sys.stdin.readline
n = int(input())
a_list = list(map(int, input().split()))
m_list = []
for i in range(n):
    if i == 0 or i == n-1:
        gcd_tmp = 0
        tmp_list = a_list[i+1:]
        for tmp in tmp_list:
            gcd_tmp = gcd(gcd_tmp, tmp)
        m = gcd_tmp
    else:
        gcd_l, gcd_r = 0, 0
        l_list = a_list[:i]
        r_list = a_list[i+1:]
        for l in l_list:
            gcd_l = gcd(gcd_l, l)
        for r in r_list:
            gcd_r = gcd(gcd_r, r)
        m = gcd(gcd_l, gcd_r)
    m_list.append(m)
print(max(m_list))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
def gcd(x, y):
    if x<y:x,y=y,x
    while x % y != 0:
        x, y = y, x % y
    return y
left=[]
right=[]
for i in range(n):
    if i==0:
        left.append(a[i])
        right.append(a[-i-1])
    else:
        left.append(gcd(a[i],left[i-1]))
        right.append(gcd(a[-i-1],right[i-1]))
ans=max(left[n-2],right[n-2])
for i in range(n-2):
    ans=max(ans,gcd(left[i],right[i]))
print(ans)

Submission status: Wrong Answer

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

this_gcd = max(a)
gcd_list = []
R = [a[0]]
L = [a[-1]]
for i in range(1, n - 1):
    L.append(fractions.gcd(a[i], L[i - 1]))
    R.append(fractions.gcd(a[n - i - 1], R[i - 1]))

ans = L[-1]
for i in range(1, n - 1):
    ans = max(ans, fractions.gcd(L[i - 1], R[i - 1]))

ans = max(ans, L[-1])

print(ans)

Submission status: Wrong Answer

Solution code:
import functools
import copy

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

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

gcds = []
if N == 2:
    gcds.append(max(A))
else:
    for i in range(N-1):
        if i == 0:
            continue
        l = A[0:i]
        r = A[i+1:N]

        l_gcd = functools.reduce(lambda x, y: gcd(x, y), l)
        r_gcd = functools.reduce(lambda x, y: gcd(x, y), r)
        gcds.append(gcd(l_gcd, r_gcd))

print(max(gcds))

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=1
a=list(map(int,input().split()))
def gcd(x, y):
    if x<y:x,y=y,x
    while x % y != 0:
        x, y = y, x % y
    return y
left=[]
right=[]
for i in range(n):
    if i==0:
        left.append(a[i])
        right.append(a[-i-1])
    else:
        left.append(gcd(a[i],left[i-1]))
        right.append(gcd(a[-i-1],right[i-1]))
ans=max(left[n-2],right[n-2])
for i in range(1,n-1):
    ans=max(ans,gcd(left[i-1],right[i-1]))
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
# import math
from functools import reduce
 
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
 
n = int(input())
a = [int(value) for value in input().split(" ")]

from_right_gcd = []
from_left_gcd = []

# 左から
for index in range(len(a)):
    if index == 0:
        from_left_gcd.append(a[index])
        continue
    from_left_gcd.append(fractions.gcd(from_left_gcd[index - 1], a[index]))

# 右から
for index in range(len(a) - 1, -1, -1):
    if index == len(a) - 1:
        from_right_gcd.append(a[index])
        continue
    from_right_gcd.append(fractions.gcd(from_right_gcd[len(a) - index - 1 - 1], a[index]))

maybe_answer_list = []

for index in range(len(a)):
    if index == 0:
        maybe_answer_list.append(from_right_gcd[len(a) - 1 - 1])
        continue
    if index == len(a) - 1:
        maybe_answer_list.append(from_left_gcd[index - 1])
        continue
    maybe_answer_list.append(fractions.gcd(from_left_gcd[index - 1], from_right_gcd[index - 1]))

print(max(maybe_answer_list))

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  a,b=max(a,b),min(a,b)
  if b==0:
    return a
  else:
    return gcd(b,a%b)
  
n=int(input())
arr=list(map(int,input().split()))
if n==2:
  print(max(arr[0],arr[1]))
elif n==3:
  print(max(gcd(arr[0],arr[1]),gcd(arr[1],arr[2]),gcd(arr[2],arr[0])))
else:
  ans1=[]
  for i in range(n):
    ans1.append(gcd(gcd(arr[0],arr[1]),arr[i]))
  finans1pos=ans1.index(min(ans1))
  if finans1pos==1:
    finans1=ans1[0]
  else:
    finans1=ans1[1]
  for i in range(n):
    if i!=finans1pos:
      finans1=gcd(finans1,ans1[i])
  ans2=[]
  for i in range(n):
    ans2.append(gcd(gcd(arr[2],arr[3]),arr[i]))
  finans2pos=ans2.index(min(ans2))
  if finans2pos==1:
    finans2=ans2[0]
  else:
    finans2=ans2[1]
  for i in range(n):
    if i!=finans2pos:
      finans2=gcd(ans2[1],ans2[i])
  finalans=max(finans1,finans2)
  print(finalans)

Submission status: Wrong Answer

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

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

ans = 0
L = [0]*(n+1)
R = [0]*(n+1)
for i in range(n):
    L[i+1] = gcd(L[i], A[i])
    R[i+1] = gcd(R[i], A[-i])
for l, r in zip(L,R[::-1]):
    ans = max(ans, gcd(l, r))
print(ans)

Submission status: Wrong Answer

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

ma1 = [1]
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) 
    
for i in range(1,N):
    err = 8
    f = gcd(a[0],a[i])
    for j in range(1,N):
        if a[j]%f != 0:
            err = err + 1
        if err == 10:
            break
    if err < 10:
        ma1.append(f)

ma2 = [1]

tmp = a[N-1]
a[N-1]=a[0]
a[0]=tmp


for i in range(1,N):
    arr = 8
    f = gcd(a[0],a[i])
    for j in range(1,N):
        if a[j]%f != 0:
            arr = arr + 1
        if arr == 10:
            break
    if arr < 10:
        ma2.append(f)



if max(ma2) > max(ma1):
    print(max(ma2))
else:
    print(max(ma1))

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
def gcd(a,b):
    while b != 0:
        a, b = b, a % b
    return(a)

def factors(n):
    Ret = []
    for i in range(2, int( n**(1/2))+1):
        if n%i == 0:
            Ret.append([])
            t = i
            while n%i == 0:
                Ret[-1].append(t)
                n //= i
                t *= i
    return Ret
    
N = int( input())
A = list( map( int, input().split()))
ans = A[1]
for i in range(1,N):
    ans = gcd(ans, A[i])
Fact = factors(A[0])
C = [1]
for F in Fact:
    D = deepcopy(C)
    for f in F:
        for d in D:
            C.append(d*f)
for g in C[::-1]:
    check = 0
    for i in range(N):
        if A[i]%g != 0:
            check += 1
    if check <= 1:
        if ans < g:
            ans = g
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    input = sys.stdin.readline
    try:
        n = int(input())
        a = list(map(int, input().split()))
        def gcd(a,b):
            while b:
                a,b = b,a%b
            return a
        from itertools import accumulate
        arrL = list(accumulate(a, gcd))
        arrR = list(accumulate(reversed(a), gcd))
        print(max(gcd(arrL[0], arrR[0]), max(arrL[1:]), max(arrR[1:])))
        
    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#C
N = int(input())
A = list(map(int, input().split()))
def gcd(a, b):
    if a == b:
        return a
    else:
        if a < b:
            a, b = b, a #so, a > b
        if b == 0:
            return a
        return gcd(b, a % b)

def calcgcd(L, ind):
    if len(L) == 1:
        return L[0]
    elif len(L) == 2:
        return max(L[0], L[1])
    else:
        l, r = L[0], L[-1]
        for i in range(0, ind):
            l = gcd(l, L[i])
        for i in range(ind + 1, N):
            r = gcd(r, L[i])
        return gcd(l,r)
M = []
for i in range(N):
    M.append(calcgcd(A,i))
print(max(M))

Submission status: Wrong Answer

Solution code:
from fractions import*
def update(k,x):
    k+=N0-1
    data[k]=x
    while k+1:
        k=~-k//2
        data[k]=gcd(data[2*k+1],data[2*k+2])
def query(l,r):
    L,R=l+N0,r+N0
    s=0
    while L<R:
        if R&1:
            R-=1
            s=gcd(s,data[R-1])
        if L&1:
            s=gcd(s,data[L-1])
            L+=1
        L>>=1
        R>>=1
    return s
n,*a=map(int,open(0).read().split())
N0=2**(n-1).bit_length()
data=[0]*2*N0
for i in range(n):
    update(i,a[i])
print(max(gcd(query(0,i),query(i+1,n))for i in range(n-1)))

Submission status: Wrong Answer

Solution code:
import sys,math,copy
from fractions import gcd
input = sys.stdin.readline

N=int(input().strip())
A=[int(x) for x in input().strip().split()]
# def gcd(a,b):
#     if b==0:
#         return a
    
#     return gcd(b,a%b)

ANS=[]
L=[0]
R=[0]
for i in range(len(A)):
    L.append(gcd(A[i],L[i]))
    R=[gcd(A[-1-i],R[-i])]+R

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

print(max(ANS))

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  a,b=max(a,b),min(a,b)
  if b==0:
    return a
  else:
    return gcd(b,a%b)
  
n=int(input())
arr=list(map(int,input().split()))
if n==2:
  print(max(arr[0],arr[1]))
elif n==3:
  print(max(gcd(arr[0],arr[1]),gcd(arr[1],arr[2]),gcd(arr[2],arr[0])))
else:
  ans1=[]
  for i in range(n):
    ans1.append(gcd(gcd(arr[0],arr[1]),arr[i]))
  ans1=sorted(ans1)
  finans1=ans1[1]
  for i in range(1,n):
    finans1=gcd(ans1[1],ans1[i])
  ans2=[]
  for i in range(n):
    ans2.append(gcd(gcd(arr[2],arr[3]),arr[i]))
  ans2=sorted(ans2) 
  for i in range(1,n):
    finans2=gcd(ans2[1],ans2[i])
  finalans=max(finans1,finans2)
  print(finalans)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
a = raw_input().split()

cnt = 0
for i in a:
    a[cnt] = int(i)
    cnt += 1

chk = {}
chk2 = {}
def make_divisors(k):
    divisors = []
    for i in range(1, int(k**0.5)+1):
        if k % i == 0:
            divisors.append(i)
            if i in chk:
                chk[i] += 1
            else:
                chk[i] = 1
            if i != k // i:
                key = int(k//i)
                divisors.append(key)
                if key in chk:
                    chk[key] += 1
                else:
                    chk[key] = 1
    chk2[k] = divisors
    return divisors

for i in range(2):
    make_divisors(a[i])
cnt = 1
for i in range(2,len(a)):
    k = a[i]
    if k not in chk2:
        make_divisors(k)
    else:
        continue
    del_list = []
    for j in chk:
        if k % j == 0:
            chk[j] += 1
        if chk[j] < cnt+1:
            del_list.append(j)
    for j in del_list:
        del chk[j]
    cnt += 1

answer = 0
for i in chk:
    if int(chk[i]) >= chk[1] - 1 and i > answer:
        answer = i
print answer

Submission status: Wrong Answer

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


import fractions
from functools import reduce

proc = lambda x: reduce(fractions.gcd, x)

GCD_each=[0 for x in range(N-1)]

for i in range(N-1):
    l=A[i:i+2]
    GCD_each[i]=proc(l)

ans=1

for i in range(N):
    if i == 0:
        for j in range(1, N-1):
            ans=max(ans, GCD_each[j])
    elif i == N-1:
        for j in range(0, N-2):
            ans=max(ans, GCD_each[j])
    else:
        for j in range(0, i-1):
            ans=max(ans, GCD_each[j])

        #ans=max(ans,GCD_skip[i-1])

        for j in range(i+1, N-1):
            ans=max(ans, GCD_each[j])


if N <= 2:
    print(A[0])
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
def gcd(n,m):
  l0=[]
  if n==0:
    return m
  elif m==0:
    return n
  else:
    for i in range(1,n//2):
      if n%i==0:
        l0.append(i)
    l0.append(n)
    g=1
    for i in l0:
      if m%i==0:
        g=i
    return(g)
l1=[]
for i in range(n):
  ll1=gcd(0,l[0])
  ll2=gcd(0,l[n-1])
  if i==0:
    ll1=gcd(0,l[1])
    for j in range(1,n):
      ll1=gcd(ll1,l[j])
    l1.append(ll1)
  elif i==n-1:
    ll2=gcd(0,l[0])
    for j in range(n-1):
      ll2=gcd(ll2,l[j])
    l1.append(ll2)
  else:
      for j in range(i):
        ll1=gcd(ll1,l[j])
      for j in range(n-1,i,-1):
        ll2=gcd(ll2,l[j])
      l1.append(gcd(ll2,ll1))
print(max(l1))

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
a = raw_input().split()

cnt = 0
for i in a:
    a[cnt] = int(i)
    cnt += 1

chk = {}
chk2 = {}
def make_divisors(k):
    divisors = []
    for i in range(1, int(k**0.5)+1):
        if k % i == 0:
            divisors.append(i)
            if i in chk:
                chk[i] += 1
            else:
                chk[i] = 1
            if i != k // i:
                key = int(k//i)
                divisors.append(key)
                if key in chk:
                    chk[key] += 1
                else:
                    chk[key] = 1
    chk2[k] = divisors
    return divisors

for i in range(2):
    make_divisors(a[i])
cnt = 1
for i in range(2,len(a)):
    k = a[i]
    if k not in chk2:
        make_divisors(k)
    else:
        for j in chk2[k]:
            if j not in chk:
                break
            else:
                chk[j] += 1
        cnt += 1
        continue
    del_list = []
    for j in chk:
        if k % j == 0:
            chk[j] += 1
        if chk[j] < cnt+1:
            del_list.append(j)
    for j in del_list:
        del chk[j]
    cnt += 1

answer = 0
for i in chk:
    if int(chk[i]) >= chk[1] - 1 and i > answer:
        answer = i
print answer

Submission status: Wrong Answer

Solution code:
from functools import reduce

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

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

L = [0] * (n + 2)
R = [0] * (n + 2)

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

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

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

print(maxGcd)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
a = raw_input().split()

cnt = 0
for i in a:
    a[cnt] = int(i)
    cnt += 1

chk = {}
chk2 = {}
def make_divisors(k):
    divisors = []
    for i in range(1, int(k**0.5)+1):
        if k % i == 0:
            divisors.append(i)
            if i in chk:
                chk[i] += 1
            else:
                chk[i] = 1
            if i != k // i:
                key = int(k//i)
                divisors.append(key)
                if key in chk:
                    chk[key] += 1
                else:
                    chk[key] = 1
    chk2[k] = divisors
    return divisors

for i in range(2):
    make_divisors(a[i])
cnt = 1
for i in range(2,len(a)):
    k = a[i]
    if k not in chk2:
        make_divisors(k)
    else:
        for j in chk2[k]:
            if j not in chk:
                continue
            else:
                chk[j] += 1
        cnt += 1
        continue
    del_list = []
    for j in chk:
        if k % j == 0:
            chk[j] += 1
        if chk[j] < cnt+1:
            del_list.append(j)
    for j in del_list:
        del chk[j]
    cnt += 1

answer = 0
for i in chk:
    if int(chk[i]) >= chk[1] - 1 and i > answer:
        answer = i
print answer

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 27 20:57:32 2019

@author: Yamazaki Kenichi
"""

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

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

T = [[1,1,1] for i in range(N)]
T[0][0],T[0][1],T[0][2] = A[0], A[0], A[0]
for i in range(1,N):
    T[i][0] = eg(T[i-1][0],A[i])
    T[i][1] = T[i-1][0]
    T[i][2] = max(eg(T[i-1][2],A[i]),eg(T[i-1][1],A[i]))
print(max(T[N-1]))

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  a,b=max(a,b),min(a,b)
  if b==0:
    return a
  else:
    return gcd(b,a%b)
  
n=int(input())
arr=list(map(int,input().split()))
if n==2:
  print(max(arr[0],arr[1]))
elif n==3:
  print(max(gcd(arr[0],arr[1]),gcd(arr[1],arr[2]),gcd(arr[2],arr[0])))
else:
  arr=sorted(arr)
  ans1=[]
  for i in range(n):
    ans1.append(gcd(gcd(arr[0],arr[1]),arr[i]))
  ans1=sorted(ans1)
  ans2=[]
  for i in range(n):
    ans2.append(gcd(gcd(arr[2],arr[3]),arr[i]))
  ans2=sorted(ans2)
  finans1=ans1[1]
  finans2=ans2[1]
  finalans=max(finans1,finans2)
  print(finalans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

kosuu = int(input())
nums = list(map(int,input().split()))

L = []
R = []
for temp in range(kosuu-1):
    if temp == 0:
        L.append(nums[0])
    else:
        L.append(gcd(L[temp-1],nums[temp]))

for temp in range(kosuu-1):
    if temp == 0:
        R.append(nums[kosuu-1])
    else:
        R.append(gcd(R[temp-1],nums[len(nums)-temp-1]))

print(L,R)
saidai=[]
for i in range(kosuu):
    if i == 0:
        saidai.append(L[-1])
    elif i == kosuu-1:
        saidai.append(R[-1])
    else:
        saidai.append(gcd(L[i-1],R[-1-i]))

print(max(saidai))

Submission status: Wrong Answer

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

# GCDの結合則を利用する
# 左端、右端からの累積GCDを求めておくと、Aiを取り除いた場合のGCDがすぐに計算できる。
# つまり、
# L(i): n=0,...,iまでのGCD 
# R(i): n=i,...,N-1までのGCD
# このとき、Aiを除いた全体のGCDは、GCD(L(i-1), R(i+1))で計算できる。

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

L = [0]*N
R = [0]*N

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

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

#残りの N − 1 個の整数の最大公約数
mx = 0
for i in range(N):
	if i == N-1:	#後ろから1個めが抜かれた時
		v = L[N-2]
	elif i == 0:	#前から1個めが抜かれた時
		v = R[1]
	else:		#どれでもない時
		v = gcd(R[i+1], L[i-1])
	mx = max(v, mx)
print(mx)



L = [0] * N
R = [0] * N

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

mx = 0
for i in range(N):
    if i == N-1:
        v = L[N-2]
    elif i == 0:
        v = R[1]
    else:
        v = gcd(R[i+1], L[i-1])
    mx = max(v, mx)
print(mx)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
a = raw_input().split()

cnt = 0
for i in a:
    a[cnt] = int(i)
    cnt += 1

chk = {}
chk2 = {}
def make_divisors(k):
    divisors = []
    for i in range(1, int(k**0.5)+1):
        if k % i == 0:
            if i in chk:
                chk[i] += 1
            else:
                chk[i] = 1
            if i != k // i:
                key = int(k//i)
                if key in chk:
                    chk[key] += 1
                else:
                    chk[key] = 1
    return divisors

for i in range(2):
    make_divisors(a[i])
cnt = 1
for i in range(2,len(a)):
    k = a[i]
    if k in chk:
        make_divisors(k)
        cnt += 1
        continue
    del_list = []
    for j in chk:
        if k % j == 0:
            chk[j] += 1
        if chk[j] < cnt+1:
            del_list.append(j)
    for j in del_list:
        del chk[j]
    cnt += 1

answer = max(chk.keys())
#answer = 0
#for i in chk:
#    if int(chk[i]) >= chk[1] - 1 and i > answer:
#        answer = i
print answer

Submission status: Wrong Answer

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

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

L = [0]*N
R = [0]*N

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

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

#残りの N − 1 個の整数の最大公約数
mx = 0
for i in range(N):
	if i==N-1:	#後ろから1個めが抜かれた時
		v = L[N-2]
	elif i==0:	#前から1個めが抜かれた時
		v = R[1]
	else:		#どれでもない時
		v = gcd(R[i+1], L[i-1])
	mx = max(v, mx)
print(mx)

Submission status: Wrong Answer

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

N=int(input().strip())
A=list(set([int(x) for x in input().strip().split()]))
def gcd(a,b):
    if b==0:
        return a
    
    return gcd(b,a%b)

ANS=[]
for i in range(len(A)):
    B=copy.deepcopy(A)
    if len(B)>1:
        B.pop(i)
    t=0
    for c in range(len(B)):
        t=gcd(B[c],t)
    ANS.append(t)

print(max(ANS))

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
a = raw_input().split()

cnt = 0
for i in a:
    a[cnt] = int(i)
    cnt += 1

chk = {}
chk2 = {}
def make_divisors(k):
    divisors = []
    for i in range(1, int(k**0.5)+1):
        if k % i == 0:
            if i in chk:
                chk[i] += 1
            else:
                chk[i] = 1
            if i != k // i:
                key = int(k//i)
                if key in chk:
                    chk[key] += 1
                else:
                    chk[key] = 1
    return divisors

for i in range(2):
    make_divisors(a[i])
cnt = 1
for i in range(2,len(a)):
    k = a[i]
    if k in chk:
        make_divisors(k)
        continue
    del_list = []
    for j in chk:
        if k % j == 0:
            chk[j] += 1
        if chk[j] < cnt+1:
            del_list.append(j)
    for j in del_list:
        del chk[j]
    cnt += 1

answer = max(chk.keys())
#answer = 0
#for i in chk:
#    if int(chk[i]) >= chk[1] - 1 and i > answer:
#        answer = i
print answer

Submission status: Wrong Answer

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


gcdL = []
gcdR = []

N = int(input())
A = [int(x) for x in input().split()]
gcdL.append(A[0])
length_A = len(A)
for i in range(1,length_A):
    gcdL.append(gcd(A[i-1],A[i]))

gcdR.append(A[length_A-1])
for i in range(1,length_A):
    gcdR.append(gcd(A[length_A-i-1],gcdR[i-1]))


list_gcd = []
for i in range(length_A):
    if i == 0:
        list_gcd.append(gcdR[length_A - 1 -i])
    elif i == length_A -1:
        list_gcd.append(gcdL[i])
    else:
        list_gcd.append(gcd(gcdL[i-1],gcdR[length_A-i-2]))

print(max(list_gcd))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys,fractions
from functools import reduce
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N = int(lines.pop(0))
    A = list(map(int, lines.pop(0).split(' ')))

    _l = 0
    L = []
    for i in range(N-1):
        _l = fractions.gcd(_l, A[i])
        L.append(_l)
    L.insert(0,0)

    _r = 0
    R = []
    for i in range(N-1):
        _r = fractions.gcd(_r, A[N-i-1])
        R.append(_r)
    R.reverse()
    R.append(0)

    print(L,R)
    print(max([fractions.gcd(l,r) for l, r in zip(L,R)]))



lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Submission status: Wrong Answer

Solution code:
#C問題
N=int(input())
A=list(map(int,input().split()))
def gcd(GCD1,GCD2):
    x = min(GCD1,GCD2)
    y = max(GCD1,GCD2)
    if y%x == 0:
        return x
    else:
        return gcd(x,y%x)
def gcdlist(xlist):
    xlen=len(xlist)
    GCD=0
    for i in range(xlen-1):
        GCD=gcd(xlist[i],xlist[i+1])
        xlist[i+1]=GCD
    return GCD
MAX=0
kari=0
gcdf=[]
for i in range(N):
    if i == 0:
        gcdf.append(A[i])
    else:
        gcdf.append(gcd(A[i],gcdf[-1]))
gcdb=[]
for i in range(N):
    if i == 0:
        gcdb.append(A[-1])
    else:
        gcdb.append(gcd(A[-1-i],gcdb[-1]))
MAX=0
gcdb=gcdb[::-1]
for i in range(N):
    if i == 0:
        kari=gcdb[-2]
    elif i == N-1:
        kari=gcdf[-2]
    else:
        f=gcdf[i-1]
        b=gcdb[i+1]
        kari=gcd(f,b)
    MAX=max(kari,MAX)
print(MAX)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

left = [0]*(N+1)
tmp = 0

for i, a in enumerate(A):
    tmp = gcd(tmp,a)
    left[i+1] = tmp

right = [0]*(N+1)
tmp = 0

for i, a in enumerate(A[::-1]):
    tmp = gcd(tmp,a)
    right[i+1] = tmp

ans_list = [gcd(left[i],right[N-i-1]) for i in range(N-1)]

ans = max(ans_list)

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))

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

Submission status: Wrong Answer

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

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

l = [0]*N
r = [0]*N

l[0] = A[0]
r[-1] = A[-1]

for i in range(1, N):
	l[i] = gcd(l[i], A[i])
	idx = N-1-i
	r[i] = gcd(r[idx], A[idx])

#残りの N − 1 個の整数の最大公約数
mx = 0
for i in range(N):
	if i==N-1:	#後ろから1個めが抜かれた時
		val = l[N-2]
	elif i==0:	#前から1個めが抜かれた時
		val = r[1]
	else:		#どれでもない時
		val = gcd(r[i+1], l[i-1])
	mx = max(val, mx)
print(mx)

Submission status: Wrong Answer

Solution code:
from sys import stdin
##  input functions for me
def ria(sep = ''):
    if sep == '' :
        return list(map(int, input().split())) 
    else: return list(map(int, input().split(sep)))
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##

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

## main ##
N = ri()
A = ria()

L = [0] * N
R = [0] * N

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

if N == 2 : ma = max(ma, max(A))
print(ma)