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 euclid(x, y):
    while x % y != 0:
        temp = x
        x = y
        y = temp % y
    return y

n = int(input())
data = list(map(int, input().split()))
array = data
L = []
L.append(data[0])
R = []
R.append(data[n - 1])
m = []
for i in range(n):
    L.append(euclid(L[i], data[i]))
data.reverse()
for i in range(n):
    R.append(euclid(R[i], data[i]))
R.reverse()
for i in range(1,n):
    m.append(euclid(L[i] , R[n - i]))
print(max(m))

Submission status: Wrong Answer

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


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


if (N == 2):
    print(A[0] if A[0] > A[1] else A[1])
else:
    lcmTable = [0 for w in range(N)]
    lcmTmpTable = [0 for w in range(N)]
    lcmTmpTable[N - 1] = A[N - 1]
    for i in range(N - 1, 2, -1):
        lcmTmpTable[i - 1] = lcm(lcmTmpTable[i], A[i - 1])
    lcmTable[0] = lcmTmpTable[1]
    for i in range(0, N - 1):
        for j in range(2, N):
            lcmTmpTable[j - 1] = lcm(lcmTmpTable[j], A[0])
        lcmTable[i + 1] = lcmTmpTable[1]
        T = A.pop(0)
        A.append(T)
    print(max(lcmTable))

Submission status: Wrong Answer

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

ans = 0

A.sort()
if N > 2:
    for i in range(N):
        div = 2
        B = A[:i:] + A[i+1::]
        while True:
            flag = True
            if div*2 > B[0]:
                break
            for i in B:
                if i%div != 0:
                    flag = False
                    break
            if flag and div > ans:
                ans = div
            div += 1
else:
    ans = max(A)

print(ans)

Submission status: Wrong Answer

Solution code:
#ユークリッド互除法！
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())
hoge=list(map(int,input().split()))
L=[]
L.append(hoge[0])
R=[]
R.append(hoge[-1])
for i in range(n-1):
  L.append(gcd(L[0],hoge[i+1]))
  R.append(gcd(R[0],hoge[-(i+2)]))

ans=[]
ans.append(R[-2])
ans.append(L[-2])
for i in range(n-2):
  ans.append(gcd(L[i],R[n-3-i]))
  
print(max(ans))

Submission status: Wrong Answer

Solution code:
#ユークリッド互除法！
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())
hoge=list(map(int,input().split()))
L=[]
L.append(hoge[0])
R=[]
R.append(hoge[-1])
for i in range(n-1):
  L.append(gcd(L[0],hoge[i+1]))
  R.append(gcd(R[0],hoge[-(i+2)]))

ans=[]
ans.append(R[-2])
ans.append(L[-2])
for i in range(n-2):
  ans.append(gcd(L[i],R[n-3-i]))
  
print(L)
print(R)
print(ans)
print(max(ans))

Submission status: Wrong Answer

Solution code:
#ユークリッド互除法！
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())
hoge=list(map(int,input().split()))
L=[]
L.append(hoge[0])
R=[]
R.append(hoge[-1])
for i in range(n-1):
  L.append(gcd(L[0],hoge[i+1]))
  R.append(gcd(R[0],hoge[-(i+2)]))

ans=[]
ans.append(R[-2])
ans.append(L[-2])
for i in range(n-2):
  ans.append(gcd(L[i],R[n-2-i]))
  
print(max(ans))

Submission status: Wrong Answer

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

def process(arr):
    gcd1 = arr[0]
    i1, i2 = -1, -1
    for i in range(1, len(arr)):
        gcd2 = gcd(gcd1, arr[i])
        if gcd2 < gcd1:
            gcd1 = gcd2
            i1 = i - 1
            i2 = i
    return gcd1, i1, i2
    
n = int(raw_input())
arr = map(int, raw_input().split())
if n <= 2:
    print max(arr)
    exit()
mingcd, i1, i2 = process(arr)
arr2 = [arr[i] for i in range(n) if i != i1]
arr3 = [arr[i] for i in range(n) if i != i2]

print max(process(arr2)[0], process(arr3)[0])

Submission status: Wrong Answer

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

def process(arr):
    mingcd = sys.maxint
    i1, i2 = -1, -1
    for i in range(1, len(arr)):
        cgcd = gcd(arr[i], arr[i-1])
        if cgcd < mingcd:
            mingcd = cgcd
            i1 = i - 1
            i2 = i
    return mingcd, i1, i2
    
n = int(raw_input())
arr = map(int, raw_input().split())
if n <= 2:
    print max(arr)
    exit()
mingcd, i1, i2 = process(arr)
arr2 = [arr[i] for i in range(n) if i != i1]
arr3 = [arr[i] for i in range(n) if i != i2]

print max(process(arr2)[0], process(arr3)[0])

Submission status: Wrong Answer

Solution code:
from fractions import gcd


def main():
    N = int(input())
    A = [0] + list(map(int, input().split()))

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


main()

Submission status: Wrong Answer

Solution code:
# ABC125C - GCD on Blackboard
# Accumulative GCD
from fractions import gcd

def main():
    n = int(input())
    a = tuple(map(int, input().rstrip().split()))

    left = [0] * (n + 1)
    right = [0] * (n + 1)
    for i in range(n):
        print(i)
        left[i + 1] = gcd(left[i], a[i])
        right[n - i - 1] = gcd(right[n - i], a[n - i - 1])
        print("left:", left)
        print("right:", right)

    ans = 0
    for i in range(n):
        ans = max(ans, gcd(left[i], right[i + 1]))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# using main() makes code faster from the point of view of "access to variables in global name-space"
# def main():

""" convenient functions
# for i, a in enumerate(iterable)
# q, mod = divmod(a, b)
# divmod(x, y) returns the tuple (x//y, x%y)
# manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
"""

import sys
sys.setrecursionlimit(10**7)
from itertools import accumulate, combinations, permutations, product # https://docs.python.org/ja/3/library/itertools.html
# accumulate() returns iterator! to get list: list(accumulate())
from math import factorial, ceil, floor
def factorize(n):
    """return the factors of the Arg and count of each factor
    
    Args:
        n (long): number to be resolved into factors
    
    Returns:
        list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
    """
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct
def combinations_count(n, r):
    """Return the number of selecting r pieces of items from n kinds of items.
    
    Args:
        n (long): number
        r (long): number
    
    Raises:
        Exception: not defined when n or r is negative
    
    Returns:
        long: number
    """
    # TODO: How should I do when n - r is negative?
    if n < 0 or r < 0:
        raise Exception('combinations_count(n, r) not defined when n or r is negative')
    if n - r < r: r = n - r
    if r < 0: return 0
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
def combinations_with_replacement_count(n, r):
    """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
    
    Args:
        n (long): number
        r (long): number
    
    Raises:
        Exception: not defined when n or r is negative
    
    Returns:
        long: number
    """
    if n < 0 or r < 0:
        raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
    elif n == 0:
        return 1
    else:
        return combinations_count(n + r - 1, r)
from bisect import bisect_left, bisect_right
from collections import deque, Counter, defaultdict # https://docs.python.org/ja/3/library/collections.html#collections.deque
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
from operator import itemgetter
# ex1: List.sort(key=itemgetter(1))
# ex2: sorted(tuples, key=itemgetter(1,2))
from functools import reduce
def chmin(x, y):
    """change minimum
    if x > y, x = y and return (x, True).
    convenient when solving problems of dp[i]
    
    Args:
        x (long): current minimum value
        y (long): potential minimum value
    
    Returns:
        (x, bool): (x, True) when updated, else (x, False)
    """
    if x > y:
        x = y
        return (x, True)
    else:
        return (x, False)
def chmax(x, y):
    """change maximum
    if x < y, x = y and return (x, True).
    convenient when solving problems of dp[i]
    
    Args:
        x (long): current maximum value
        y (long): potential maximum value
    
    Returns:
        (x, bool): (x, True) when updated, else (x, False)
    """
    if x < y:
        x = y
        return (x, True)
    else:
        return (x, False)

from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(x, y):
    return (x * y) // gcd(x, y)
def lcms(numbers):
    return reduce(lcm, numbers, 1)

# first create factorial_list
# fac_list = mod_factorial_list(n)
INF = 10 ** 18
MOD = 10 ** 9 + 7
modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
def modinv(a, p = MOD):
    # evaluate reciprocal using Fermat's little theorem:
    # a**(p-1) is identical to 1 (mod p) when a and p is coprime
    return modpow(a, p-2, p)
def modinv_list(n, p = MOD):
    if n <= 1:
        return [0,1][:n+1]
    else:
        inv_t = [0,1]
        for i in range(2, n+1):
            inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
        return inv_t
def modfactorial_list(n, p = MOD):
    if n == 0:
        return [1]
    else:
        l = [0] * (n+1)
        tmp = 1
        for i in range(1, n+1):
            tmp = tmp * i % p
            l[i] = tmp
        return l
def modcomb(n, k, fac_list = [], p = MOD):
    # fac_list = modfactorial_list(100)
    # print(modcomb(100, 5, modfactorial_list(100)))
    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    if len(fac_list) <= n:
        a = factorial(n) % p
        b = factorial(k) % p
        c = factorial(n-k) % p
    else:
        a = fac_list[n]
        b = fac_list[k]
        c = fac_list[n-k]
    return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
def modadd(a, b, p = MOD):
    return (a + b) % MOD
def modsub(a, b, p = MOD):
    return (a - b) % p
def modmul(a, b, p = MOD):
    return ((a % p) * (b % p)) % p
def moddiv(a, b, p = MOD):
    return modmul(a, modpow(b, p-2, p))

""" initialize variables and set inputs
# initialize variables
    # to initialize list, use [0] * n
    # to initialize two dimentional array, use [[0] * N for _ in range(N)]
# set inputs
    # open(0).read() is a convenient method:
    # ex) n, m, *x = map(int, open(0).read().split())
    #     min(x[::2]) - max(x[1::2])
    # ex2) *x, = map(int, open(0).read().split())
    #     don't forget to add comma after *x if only one variable is used
# preprocessing
    # transpose = [x for x in zip(*data)]
    # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
    # flat = [flatten for inner in data for flatten in inner]
    # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [1, 2, 3, 4, 5, 6, 7, 8, 9]
# calculate and output
    # output pattern
    # ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6
"""

# functions used
r = lambda: sys.stdin.readline().strip()
r_int = lambda: int(r())
R = lambda: list(map(int, r().split()))
Rfloat = lambda: list(map(float, r().split()))
Rtuple = lambda: tuple(map(int, r().split()))
Rmap = lambda: map(int, r().split())

""" how to treat input
# single int: int(r())
# single string: r()
# single float: float(r())
# line int: R()
# line string: r().split()
# line (str, int, int): [j if i == 0 else int(j) for i, j in enumerate(r().split())]
# lines int: [R() for _ in range(n)]
"""


# ----------------------------------
# main

N = int(r())
A = R()
B = [0] * N
C = [0] * N
for i, a in enumerate(A):
    if i == 0:
        tmp = a
    else:
        tmp = gcd(i, tmp)
    B[i] = tmp

A.reverse()
for i, a in enumerate(A):
    if i == 0:
        tmp = a
    else:
        tmp = gcd(a, tmp)
    C[i] = tmp
C.reverse()

ans = 1
for i in range(N):
    if i == 0:
        ans = max(ans, C[i+1])
    elif i == N-1:
        ans = max(ans, B[i-1])
    else:
        ans = max(ans, gcd(B[i-1],C[i+1]))

print(ans)
# end of main
# ----------------------------------

"""memo: how to use defaultdict of list
# initialize
Dic = defaultdict(list)
# append / extend
Dic[x].append(y)
# for
for k, v in Dic.items():
"""

# if __name__ == '__main__':
#     main()

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 = list(map(int, input().split()))
B = [A[0]]
C = [A[N-1]]
for i in range(1,N):
  B.append(gcd(A[i],B[i-1]))
  C.append(gcd(A[N-i-1],C[i-1]))
D = [C[N-2]]
for j in range(2,N):
  D.append(gcd(B[j],C[N-j]))
D.append(B[N-2])
print(max(D))

Submission status: Wrong Answer

Solution code:
import fractions

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

  right = []
  left  = []

  right.append(a[0])
  left.append(a[-1])

  for i in range(1, len(a)-1):
    right.append(fractions.gcd(right[i-1], a[i]))
    left.append(fractions.gcd(left[i-1], a[-i-1]))
  
  ans = max(right[-1], left[-1])
  
  for i in range(len(right)-1):
    ans = max(ans, fractions.gcd(right[0], left[-i-2]))
    
  print(ans)
  
main()

Submission status: Wrong Answer

Solution code:
import fractions

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

  right = []
  left  = []

  right.append(a[0])
  left.append(a[-1])

  for i in range(1, len(a)-1):
    right.append(fractions.gcd(right[i-1], a[i]))
    left.append(fractions.gcd(left[i-1], a[len(a)-i-1]))
  
  ans = max(right[-1], left[-1])
  
  for i in range(len(right)-1):
    ans = max(ans, fractions.gcd(right[0], left[-i-2]))
    
  print(ans)
  
main()

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 = list(map(int, input().split()))
A.sort()
B = []
C = []
for i in range(N):
  B.append(gcd(A[0],A[i]))
  C.append(gcd(A[1],A[i]))
B.sort()
C.sort()
print(max(B[1],C[1]))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
import copy
N = int(input())
A=[int(i) for i in input().split()]
B=[]
def list_gcd(a):
    return reduce(fractions.gcd , a)
b = []
for i in range(N):
    if i>0 and i<N-1:
        a = A[:i-1]+A[i+1:]
    elif i == 0:
        a = A[1:]
    else:
        a = A[:N-1]
    b.append(list_gcd(a))
print(max(b))

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 = list(map(int, input().split()))
A.sort()
B = [ ]
for i in range(N):
  B.append(gcd(A[0],A[i]))
B.sort()
print(B[1])

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 = list(map(int, input().split()))
A.sort()
B = [ ]
for i in range(N):
  B.append(gcd(A[0],A[i]))
B.sort()
set(B)
print(B[1])

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
# print(N, A)

def solve(A, index):
    ans = A[0]
    if index == 0:
        ans = A[1]
    for i in range(len(A)):
        if i == index:
            continue
        ans = gcd(ans, A[i])
    return ans

index = -1
min_d = d = A[0]
for i in range(len(A)):
    d = gcd(d, A[i])
    if d < min_d:
        index = i
        min_d = d

ans = solve(A, index)
if index != 0:
    ans = max(solve(A, index - 1), ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
# print(N, A)

index = -1
min_d = A[0]
for i in range(len(A) - 1):
    d = gcd(A[i], A[i + 1])
    if d <= min_d:
        index = i
        min_d = d

del A[index]
ans = reduce(gcd, A)
print(ans)

Submission status: Wrong Answer

Solution code:
num_num = int(input())

Submission status: Wrong Answer

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

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

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

R.reverse()

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

print(max(M))

Submission status: Wrong Answer

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

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

l, r = [A[0]], [A[-1]]
for n in range(1, N):
	l += [gcd(l[-1], A[n])]
	r += [gcd(r[-1], A[N - n - 1])]
r = r[::-1]

list_gcd = [l[-2], r[-2]]
for n in range(N - 2):
	list_gcd += [gcd(l[n], r[n + 2])]

#print(l)
#print(r)
#print(list_gcd)

print(max(list_gcd))

Submission status: Wrong Answer

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

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

l, r = [A[0]], [A[-1]]
for n in range(1, N):
	l += [gcd(l[-1], A[n])]
	r += [gcd(r[-1], A[N - n - 1])]
r = r[::-1]

list_gcd = [l[-2], r[-2]]
for n in range(N - 2):
	list_gcd += [gcd(l[n], r[N - n - 1])]

print(max(list_gcd))

Submission status: Wrong Answer

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
As = nl()

from fractions import gcd
gcds_left = [0] * N
gcds_right = [0] * N
gcds_left[0] = As[0]
gcds_right[N-1] = As[N-1]

for i in range(1, N):
    gcds_left[i] = gcd(As[i], gcds_left[i-1])
    gcds_right[N-1-i] = gcd(As[N-1-i], gcds_right[N-i])

max_gcd = -1
for i in range(1, N-1):
    g = gcd(gcds_left[i-1], gcds_right[i+1])
    if g > max_gcd:
        max_gcd = g
print(max(max_gcd, gcds_left[1], gcds_right[N-2]))

Submission status: Wrong Answer

Solution code:
from fractions import gcd


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

total=0
left=[0]*(N+1)
right=[0]*(N+1)

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

for i in range(N):
    total=max(total,gcd(left[i],right[i+1]))

print(total)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce



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

li=[0]*(n+1)
ri=[0]*(n+1)

for i in range(n):
    li[i+1]=gcd(li[i], a[i])
for i in range(n-1, -1, -1):
    ri[i]=gcd(ri[i+1], a[i])

ans=0

for i in range(n-1):
    ans=max(gcd(li[i], ri[i+1]),ans)

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce



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

li=[0]*(n+1)
ri=[0]*(n+1)

for i in range(n):
   li[i+1]=gcd(li[i], a[i])
   ri[n-1-i]=gcd(ri[n-i], a[n-1-i])

ans=0

for i in range(n-1):
    ans=max(gcd(li[i], ri[i+1]),ans)

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

n=int(input())
a=sorted(list(map(int,input().split())), reverse=True)
ans=a[0]
flag=False

if reduce(gcd, a)!=1:
    a[1]=a[0]
    print(reduce(gcd, a))
    exit()

for i in range(n):
    if flag==False and gcd(ans, a[i])==1:
        ans=gcd(ans, a[0])
        flag=True
    else:
        ans=gcd(ans, a[i])

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

n=int(input())
a=sorted(list(map(int,input().split())), reverse=True)
ans=a[0]
flag=False

for i in range(n):
    ans=gcd(ans, a[i])
    if flag==False and ans==1:
        ans=gcd(a[i-1], a[i-1])
        flag=True

print(ans)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
N=input()
A=map(int,raw_input().split())

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

# L[i]:=gcd(A_0, ..., A_i)
# R[i]:=gcd(A_i, ..., A_{N-1})
L=[0]*N
R=[0]*N

L[0]=A[0]
R[N-1]=A[N-1]
for i,a in enumerate(A):
    if i==0:continue
    L[i]=gcd(L[i-1],a)
for i,a in enumerate(reversed(A)):
    if i==0:continue
    R[N-i-1]=gcd(R[N-i],a)

ans=R[1] 
ans=max(ans,L[N-2])
for i in range(N-1):
    if i==0:continue
    ans=max(ans,gcd(A[i-1],R[i+1]))
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
def gcd_strategy():
    import math
    import fractions
    return math.gcd if hasattr(math, "gcd") else fractions.gcd
gcd = gcd_strategy()

n=int(input())
a=list(map(int,input().split()))
ans=0
r=[]
if n==2:
    print(max(a[0],a[1]))
else:
    for i in range(n):
      l=a.copy()
      del l[i]
      r.clear()
      for j in range(n-2):
        r.append(gcd(l[j],l[j+1]))
      g=r[-1]
      if ans<g:
        ans=g
    print(ans)

Submission status: Wrong Answer

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

l=[a[0]]
r=[a[n-1]]

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

print(max(ans))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

# GCD
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x

def main():
  n=I()
  l=LI()

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

  l2=[l[-1]]
  for i in range(1,n):
    l2.append(gcd(l2[i-1],l[n-i-1]))
  l2.reverse()

  mx=l2[1]
  for i in range(n-2):
    mx=max(mx,gcd(l1[i],l2[i+2]))

  return mx

print(main())

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
A = [int(i) for i in input().split()]
ans = 0

L = [0]*(N+2)
R = [0]*(N+2)
L[0] = 0
L[1] = A[0]
R[N+1] = 0
R[N] = A[N-1]

for i in range(1, N):
  L[i+1] = fractions.gcd(L[i], A[i])
  R[N-i] = fractions.gcd(R[N+1-i],A[N-1-i])
for i in range(N-1):
  tmp = fractions.gcd(L[i], R[i+2])
  ans = max(tmp, ans)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def gcd(a, b):
	if not a % b:
		return b
	return gcd(b, a % b)

ll, rl = [A[0]], [A[-1]]

for a in A[1:]:
	ll += [gcd(ll[-1], a)]
for a in A[::-1][1:]:
	rl += [gcd(rl[-1], a)]
rl = rl[::-1]

#print(ll)
#print(rl)

gcd_max = max(ll[-2], rl[-2])
for n in range(2, len(ll)):
	gcd_max = max(gcd_max, gcd(ll[n - 2], rl[n]))

print(gcd_max)

Submission status: Wrong Answer

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

def gcd(a, b):
	if not a % b:
		return b
	return gcd(b, a % b)

ll, rl = [A[0]], [A[-1]]

for a in A[1:]:
	ll += [gcd(ll[-1], a)]
for a in A[::-1][1:]:
	rl += [gcd(rl[-1], a)]
rl = rl[::-1]

#print(ll)
#print(rl)

gcd_max = max(ll[-2], rl[-2])
for n in range(2, N):
	gcd_max = max(gcd_max, gcd(ll[n - 2], rl[n]))

print(gcd_max)

Submission status: Wrong Answer

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

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

def gcd(a, b):
	if not a % b:
		return b
	return gcd(b, a % b)

ll, rl = [A[0]], [A[-1]]

for a in A[1:]:
	ll += [gcd(ll[-1], a)]
for a in A[::-1][1:]:
	rl += [gcd(rl[-1], a)]
rl = rl[::-1]

gcd_max = max(ll[-2], rl[-2])
for n in range(2, N):
	gcd_max = max(gcd_max, gcd(ll[n - 2], rl[n]))

print(gcd_max)

Submission status: Wrong Answer

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

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

def gcd(a, b):
	if not a % b:
		return b
	return gcd(b, a % b)

ll, rl = [A[0]], [A[-1]]

for a in A[1:]:
	ll += [gcd(ll[-1], a)]
for a in A[::-1][1:]:
	rl += [gcd(rl[-1], a)]
rl = rl[::-1]

#print(ll)
#print(rl)

gcd_max = 0
for n in range(2, N):
	gcd_max = max(gcd_max, gcd(ll[n - 2], rl[n]))

if 3 == N:
	gcd_max = max(gcd_max, ll[1], rl[1])

print(gcd_max)

Submission status: Wrong Answer

Solution code:
import fractions

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

A.sort()
A[1]=A[0]
ans=A[0]
for i in range(N):
    ans=fractions.gcd(ans,A[i])
print(ans)

Submission status: Wrong Answer

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

import numpy as np

input()
A = np.array(list(map(int, input().split())))
N = len(A)
print(A)
if N <= 2:
    print(max(A))
    exit()

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

ans = 1
for ptr in range(N):
    li = np.concatenate([A[:ptr], A[ptr+1:]])
    g = li[0]
    for i in li[1:]:
        g = gcd(g,i) if g > i else gcd(i,g)
    ans = max(ans, g)

print(ans)

Submission status: Wrong Answer

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

import numpy as np

input()
A = np.array(list(map(int, input().split())))
N = len(set(A))

if N <= 2:
    print(max(A))
    exit()

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

ans = 1
for ptr in range(N):
    li = np.concatenate([A[:ptr], A[ptr+1:]])
    g = li[0]
    for i in li[1:]:
        g = gcd(g,i) if g > i else gcd(i,g)
    ans = max(ans, g)

print(ans)

Submission status: Wrong Answer

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

import numpy as np

input()
A = np.array(list(set(map(int, input().split()))))
N = len(A)

if N <= 2:
    print(max(A))
    exit()

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

ans = 1
for ptr in range(N):
    li = np.concatenate([A[:ptr], A[ptr+1:]])
    g = li[0]
    for i in li[1:]:
        g = gcd(g,i) if g > i else gcd(i,g)
    ans = max(ans, g)

print(ans)

Submission status: Wrong Answer

Solution code:
def euclid(x, y):
    while x % y != 0:
        temp = x
        x = y
        y = temp % y
    return y

n = int(input())
data = list(map(int, input().split()))
max = 0
array = data
for j in range(n):
    array = data
    array[j] = array[(j + 1) % n]
    x = data[0]
    for i in array:
        if(x > i):
            x = euclid(x, i)
        else:
            x = euclid(i, x)
        if(x > max):
            max = x
print(max)

Submission status: Wrong Answer

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

import numpy as np

input()
A = np.array(list(set(map(int, input().split()))))
N = len(A)

if N <= 2:
    print(max(A))
    exit()

b = 1
for ptr in range(N):
    li = np.concatenate([A[:ptr], A[ptr+1:]])
    
    max_li = max(li)
    tmp_ans = 1
    i = 2
    while i == 2 and i*i <= max_li:
        if max(li%2) == 0:
            li //= 2
            max_li = max(li)
            tmp_ans *= 2
        else:
            i += 1
    while i*i <= max_li:
        if max(li%i) == 0:
            li //= i
            max_li = max(li)
            tmp_ans *= i
        else:
            i += 2
    
    b = max(b, tmp_ans)

print(b)

Submission status: Wrong Answer

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

import numpy as np
import math

input()
A = np.array(list(set(map(int, input().split()))))
N = len(A)

if N <= 2:
    print(max(A))
    exit()

sqrt_max_A = math.sqrt(max(A))
ans = 1
i = 2
while i == 2 and i <= sqrt_max_A:
    if max(A%2) == 0:
        A //= 2
        max_A = math.sqrt(max(A))
        ans *= 2
    else:
        i += 1
while i <= sqrt_max_A:
    if max(A%i) == 0:
        A //= i
        max_A = math.sqrt(max(A))
        ans *= i
    else:
        i += 2

b = 1
for i in range(N):
    li = np.concatenate([A[:i], A[i+1:]])
    
    sqrt_max_li = math.sqrt(max(li))
    tmp_ans = 1
    i = 2
    while i == 2 and i <= sqrt_max_li:
        if max(li%2) == 0:
            li //= 2
            max_li = math.sqrt(max(li))
            tmp_ans *= 2
        else:
            i += 1
    while i <= sqrt_max_li:
        if max(li%i) == 0:
            li //= i
            max_li = math.sqrt(max(li))
            tmp_ans *= i
        else:
            i += 2
    
    b = max(b, tmp_ans)

print(ans*b)

Submission status: Wrong Answer

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

import numpy as np
import math

input()
A = np.array(list(set(map(int, input().split()))))
N = len(A)

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

sqrt_max_A = math.sqrt(max(A))
ans = 1
i = 2
while i == 2 and i <= sqrt_max_A:
    if max(A%2) == 0:
        A //= 2
        max_A = math.sqrt(max(A))
        ans *= 2
    else:
        i += 1
while i <= sqrt_max_A:
    if max(A%i) == 0:
        A //= i
        max_A = math.sqrt(max(A))
        ans *= i
    else:
        i += 2

b = 1
for i in range(N):
    li = np.concatenate([A[:i], A[i+1:]])
    
    sqrt_max_li = math.sqrt(max(li))
    tmp_ans = 1
    i = 2
    while i == 2 and i <= sqrt_max_li:
        if max(li%2) == 0:
            li //= 2
            max_li = math.sqrt(max(li))
            tmp_ans *= 2
        else:
            i += 1
    while i <= sqrt_max_li:
        if max(li%i) == 0:
            li //= i
            max_li = math.sqrt(max(li))
            tmp_ans *= i
        else:
            i += 2
    
    b = max(b, tmp_ans)

print(ans*b)