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:
import fractions
N = int(input())
As =  list(map(int, input().split()))
sorted(As)
res = []
for n in range(N-1):
  r = []
  if n == 0:
    A = As[1:]
  else:
    A = As[0:n] + As[n+1:N]
  ans = A[0]
  for a in A[1:]:
     ans = fractions.gcd(ans, a)
  res.append(ans)
print(max(res))

Submission status: Wrong Answer

Solution code:
"""
問題文

N個の整数 A1,A2,...,ANが黒板に書かれています。
あなたはこの中から整数を 1つ選んで、1 以上 109以下の好きな整数に書き換えます。
元の整数と同じ整数に書き換えても構いません。書き換えた後のN個の整数の最大公約数の最大値を求めてください。

制約
入力は全て整数である。
2≤N≤105
1≤Ai≤109
"""

"""
3 5 7
最大公約数: 1
最大の最大公約数: 1

8 4 6
最大公約数: 2
最大の最大公約数: 4
『aとbとcの最大公約数』　＝　『aとbの最大公約数』と『c』　の最大公約数

A1 , A2 , A3 ... An

gcd(A1 , A2 , A3 ... An-1) * N
= gcd * N * N
= gcd * N^2

gcd(A1 , A2 , A3 ... An-1)
gcd(A1 , A2 , A3 ... An-2 , An) = gcd(A1 , A2 , A3 ... An-2) , An
"""
def gcd(a, b):  # a>b
    a, b = max(a, b), min(a, b)
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

from functools import reduce
def GCD(numbers):
    if len(numbers) == 0 : return 0
    if len(numbers) == 1 : return numbers[0]
    if len(numbers) == 2 : 
        return gcd(numbers[0] , numbers[1])
    else : 
        value = GCD(numbers[:len(numbers)-1])
        result = gcd(value , numbers[len(numbers) - 1])
        return result

def main() : 
    N = int(input())
    a_list = input().split(" ")
    a_list = [int(i) for i in a_list]
    R = [0 for i in range(N - 1)]
    L = [0 for i in range(N - 1)]
    R[0] = a_list[0]
    L[0] = a_list[-1]

    for i in range(1 , N-1) : 
        R[i] = gcd(R[i - 1] , a_list[i])
    
    for j in range(1 , N-1) : 
        L[j] = gcd(L[j - 1] , a_list[- j - 1])
    
    maxValue = 0
    for i in range(N - 2) : 
        value = gcd(R[i] , L[N - i - 3])
        if value > maxValue : maxValue = value
    print(maxValue)
main()

Submission status: Wrong Answer

Solution code:

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


import sys
if n == 2:
    print(max(a))
    sys.exit()


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


g = a[0]
gcd_left = [g]
for i in range(n-1):
    g = gcd(g, a[i+1])
    gcd_left.append(g)

g = a[n-1]
gcd_right = [g]
for i in range(n-1):
    g = gcd(g, a[n-2-i])
    gcd_right.append(g)

max_gcd = gcd_right[n-1]
for i in range(1, n-1):
    max_gcd = max(max_gcd, gcd(gcd_left[i-1], gcd_right[n - 2 - i]))
max_gcd = max(max_gcd, gcd_left[n-1])

print(max_gcd)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = [int(i) for i in input().split()]
minus_count_even_flug = True
zero_exist_flug = False
  
for a in a_list:
    if a < 0:
        minus_count_even_flug = not minus_count_even_flug
    if a == 0:
        zero_exist_flug = True
     
a_abs_list = [abs(a) for a in a_list]
sum_a_abs_list = sum(a_abs_list)
if minus_count_even_flug or zero_exist_flug:
    print(sum_a_abs_list)
else:
    print(sum_a_abs_list - 2 * min(a_abs_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]))
  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
from functools import reduce
import copy

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

fValueList = []
lValueList = []
maxList = []

if n == 2:
  print(gcd(a[0], a[1]))
else:
  fValueList.append(a[0])
  lValueList.append(a[n-1])
  for i in range(1,n-1):
    g = fValueList[i-1]
    fValueList.append(gcd(g, a[i]))

  for i in range(1,n-1):
    g = lValueList[i-1]
    lValueList.append(gcd(g, a[n-i]))
  
  maxList.append(fValueList[n-2])
  maxList.append(lValueList[n-2])
  for k in range(n-2):
    g = gcd(fValueList[k], lValueList[n-3-k])
    maxList.append(g)
    
  print(max(maxList))

Submission status: Wrong Answer

Solution code:
import fractions

n = list(map(int, input().split()))
A = list(map(int, input().split()))
a_max = max(A)
result = []
for a in A:
    result.append(fractions.gcd(a_max,a))

result.sort()

print(result[1])

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)

import random
 
n = int(input())
a = list(map(int, input().split()))
 
tmpgcd = list()
tmpgcd.append(gcd(a[0], a[-1]))

tmpgcd = sorted(tmpgcd)
mini = tmpgcd[0]

result = 0
for i in range(mini, -1, -1):
    tmp = [x % i for x in a]
    tmp = [x for x in tmp if x != 0]
    if len(tmp) <= 1:
        result = i
        break
 
print(result)

Submission status: Wrong Answer

Solution code:
"""
問題文

N個の整数 A1,A2,...,ANが黒板に書かれています。
あなたはこの中から整数を 1つ選んで、1 以上 109以下の好きな整数に書き換えます。
元の整数と同じ整数に書き換えても構いません。書き換えた後のN個の整数の最大公約数の最大値を求めてください。

制約
入力は全て整数である。
2≤N≤105
1≤Ai≤109
"""

"""
3 5 7
最大公約数: 1
最大の最大公約数: 1

8 4 6
最大公約数: 2
最大の最大公約数: 4
『aとbとcの最大公約数』　＝　『aとbの最大公約数』と『c』　の最大公約数

A1 , A2 , A3 ... An

gcd(A1 , A2 , A3 ... An-1) * N
= gcd * N * N
= gcd * N^2

gcd(A1 , A2 , A3 ... An-1)
gcd(A1 , A2 , A3 ... An-2 , An) = gcd(A1 , A2 , A3 ... An-2) , An
"""
def gcd(a, b):  # a>b
    a, b = max(a, b), min(a, b)
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

from functools import reduce
def GCD(numbers):
    if len(numbers) == 0 : return 0
    if len(numbers) == 1 : return numbers[0]
    if len(numbers) == 2 : 
        return gcd(numbers[0] , numbers[1])
    else : 
        value = GCD(numbers[:len(numbers)-1])
        result = gcd(value , numbers[len(numbers) - 1])
        return result

def main() : 
    N = int(input())
    a_list = input().split(" ")
    a_list = [int(i) for i in a_list]
    R = [0 for i in range(N - 1)]
    L = [0 for i in range(N - 1)]
    R[0] = a_list[0]
    L[0] = a_list[-1]

    for i in range(1 , N-1) : 
        R[i] = gcd(R[i-1] , a_list[i])
    
    for j in range(1 , N-1) : 
        L[j] = gcd(L[0] , a_list[N - j - 1])
    
    maxValue = 0
    for i in range(N - 3) : 
        value = gcd(R[i] , L[N - i - 3])
        if value > maxValue : maxValue = value
    print(maxValue)
main()

Submission status: Wrong Answer

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

@author: Owner
"""

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019

@author: Owner
"""

import numpy as np
import sys
""""
import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect
"""

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default
# 約数を高速で列挙するコード
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse = True)
    return divisors
"""
N, X = map(int, input().split())

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

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

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


def main():
    A.sort()
    CNT = dict()
    non_kouho = []
    
    for i,a in enumerate(A):
        ads = make_divisors(a)
        if i == 0 or i ==1:
            ads2 = ads
        else:
            ads2 =(set(non_kouho) ^ set(ads)) & set(ads)

        for ad in ads2:
            if ad in CNT:
                CNT[ad]+=1
            else:
                if i == 0 or i==1:
                    CNT[ad]=1
                if i>1:
                    non_kouho.append(ad)
        if i==2:
            de_list=[]
            for key in CNT.keys():
                if CNT[key] <= 1:
                    de_list.append(key)
                    non_kouho.append(key)
            for key in de_list:
                CNT.pop(key)
    l_kouho = list(CNT.keys())
    print(max(l_kouho))

    
            
    
if __name__ == '__main__':
    main()

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)

def gcd_for_list(l):
    temp=0
    l = [0]+l+[0]
    for i in range(len(l)):
        temp = gcd(l[i],temp)
    return temp

N= int(input())
t = list(map(int, input().split()))
soin = []
temp=0
nokori =[]

if (N != 2):
    for i in range(N):
        l = t[0:i]+t[i+1:]
        soin.append(gcd_for_list(l))
else:
    soin.append(gcd(t[0], t[1]))

print(max(soin))

Submission status: Wrong Answer

Solution code:
import fractions

n = list(map(int, input().split()))
A = list(map(int, input().split()))
a_max = max(A)
result = []
for a in A:
    result.append(fractions.gcd(a_max,a))

result.sort(reverse=True)

print(result[1])

Submission status: Wrong Answer

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

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

fValueList = []
lValueList = []
maxList = []

if n == 2:
  print(gcd(a[0], a[1]))
else:
  fValueList.append(a[0])
  lValueList.append(a[n-1])
  for i in range(1,n-1):
    g = fValueList[i-1]
    fValueList.append(gcd(g, a[i]))

  for i in range(1,n-1):
    g = lValueList[i-1]
    lValueList.append(gcd(g, a[n-i]))
  
  maxList.append(fValueList[n-2])
  maxList.append(lValueList[n-2])
  for k in range(n-2):
    g = gcd(lValueList[k], lValueList[n-3-k])
    maxList.append(g)
    
  print(max(maxList))

Submission status: Wrong Answer

Solution code:
from functools import reduce

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

def solve(N, As):
    init_gcd = reduce(gcd, As, 0)
    Bs = list(map(lambda x: x // init_gcd, As))
    x = 1

    if N == 2:
        print(max(As[0], As[1]))
    else:
        for idx, (b1, b2) in enumerate(zip(Bs, Bs[1:])):
            if gcd(b1, b2) == 1:
                gcd1 = reduce(gcd, Bs[:idx] + [b2] + Bs[idx + 1:], 0)
                gcd2 = reduce(gcd, Bs[:idx + 1] + [b1] + Bs[idx + 2:], 0)
                x = max(x, gcd1, gcd2)
        print(init_gcd * x)
        return


if __name__ == '__main__':
    N = int(input()) # ignore
    As = list(map(int, input().split()))
    solve(N, As)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import sys
 
N = int(input())
A = list(map(int, input().strip().split(' ')))
 
if N == 2:
    print(max(A[0], A[1]))
    sys.exit(0)
 
G1 = [0 for i in range(N)]
G2 = [0 for i in range(N)]
 
G1[0] = A[0]
G2[N-1] = A[N-1]
#G1[1] = math.gcd(A[0], A[1])
#G2[N-2] = math.gcd(A[-1], A[-2])
for i in range(1, N):
    G1[i] = gcd(G1[i-1], A[i])
    G2[N-i-1] = gcd(G2[N-i], A[N-i-1])
 
min_g = max(G1[1], G2[-2])
for i in range(1, N-1):
    min_g = max(min_g, gcd(G1[i-1], G2[i+1]))
 
print(min_g)

Submission status: Wrong Answer

Solution code:

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

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

f = [a[0]]
b = [a[-1]]

for i in range(1, n):
    f.append(gcd(f[i-1], a[i]))
    b.append(gcd(b[i-1], a[n-1-i]))
f.insert(0, 0)
b.insert(0, 0)
b.reverse()
ans = []
for i in range(n-1):
    ans.append(gcd(f[i], b[i+1]))
print(max(ans))

Submission status: Wrong Answer

Solution code:
import fractions

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

L = [0]
R = [0]

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

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

print(max(M))

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a % b)
 
N = int(input())
As =  list(map(int, input().split()))
sorted(As)
res = []
for n in range(N-1):
  r = []
  if n == 0:
    A = As[1:]
  else:
    A = As[0:n] + As[n+1:N]
  ans = A[0]
  for a in A[1:]:
     ans = gcd(ans, a)
  res.append(ans)
print(max(res))

Submission status: Wrong Answer

Solution code:

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

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

f = [a[0]]
b = [a[-1]]

for i in range(1, n):
    f.append(gcd(f[i-1], a[i]))
    b.append(gcd(b[i-1], a[n-1-i]))
f.insert(0, 0)
b.insert(0, 0)
b.reverse()
print(f)
print(b)
ans = []
for i in range(n-1):
    ans.append(gcd(f[i], b[i+1]))
print(max(ans))

Submission status: Wrong Answer

Solution code:
from functools import reduce

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

def solve(N, As):
    init_gcd = reduce(gcd, As, 0)
    Bs = list(map(lambda x: x // init_gcd, As))
    x = 1

    if N == 2:
        print(max(As[0], As[1]))
    else:
        for idx, (b1, b2) in enumerate(zip(Bs, Bs[1:])):
            if gcd(b1, b2) == 1:
                gcd1 = reduce(gcd, Bs[:idx] + [b2] + Bs[idx + 1:], 0)
                gcd2 = reduce(gcd, Bs[:idx + 1] + [b1] + Bs[idx + 2:], 0)
                x = max(gcd1, gcd2)
                break
        print(init_gcd * x)
        return


if __name__ == '__main__':
    N = int(input()) # ignore
    As = list(map(int, input().split()))
    solve(N, As)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N =int(input())
A = list(map(int,input().split()))
A.sort()

if len(A) < 5:
    A.append(1)
    A.append(1)
    A.append(1)
    A.append(1)
    A.append(1)
    
import fractions

ans = 0
for i in range(4):
    for j in range(4):
        if i == j:
            continue
        ans = max(ans,fractions.gcd(A[i],A[j]))
        
print(ans)

Submission status: Wrong Answer

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

if M == 1:
    A.pop(1)
tmp = 1
for i in reversed(range(2,M+1)):
    count = 0
    memo = 0
    for j in range(len(A)):
        if A[j]%i != 0:
            count += 1
            memo = j
            if count > 1:
                break
    if count <= 1:
        tmp = i
        break
        

print(tmp)

Submission status: Wrong Answer

Solution code:
from functools import reduce

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

def solve(N, As):
    init_gcd = reduce(gcd, As, 0)
    Bs = list(map(lambda x: x // init_gcd, As))
    x = 1

    if N == 2:
        print(max(As[0], As[1]))
    else:
        for idx, (b1, b2) in enumerate(zip(Bs, Bs[1:])):
            if gcd(b1, b2) == 1:
                gcd1 = reduce(gcd, Bs[:idx] + Bs[idx + 1:], 0)
                gcd2 = reduce(gcd, Bs[:idx + 1] + Bs[idx + 2:], 0)
                x = max(gcd1, gcd2)
                break
        print(init_gcd * x)
        return


if __name__ == '__main__':
    N = int(input()) # ignore
    As = list(map(int, input().split()))
    solve(N, As)

Submission status: Wrong Answer

Solution code:
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq

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

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

Submission status: Wrong Answer

Solution code:
import itertools
def hcf1(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        temp = a % b
        a = b
        b = temp
    return a
def blackbord(n,a):
    k = 0
    c = list(itertools.combinations(a, 2))
    for i in range(len(c)):
        t = hcf1(c[i][0],c[i][1])
        k = max(k,t)
    return k
n = int(input())
a=list(map(int, input().split()))
print(blackbord(n,a))

Submission status: Wrong Answer

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

n=int(input())
A=list(map(int, input().split()))
#a=1
init=1
#maxa=99999999999999999999999999
#maxa=A[1]
B1=[]
for i in A:
    if init==1:
        a=i
        init=0
        B1.append(a)
    else:
        a=gcd(a,i)
        B1.append(a)

init=1
B2=[]
for i in A[::-1]:
    if init==1:
        a=i
        init=0
        B2.append(a)
    else:
        a=gcd(a,i)
        B2.append(a)

#print(B1)
#print(B2)
result=0
for i in range(n):
    if i==0:
        if result<B2[n-2]:
            result=B2[n-2]
    elif i==n-1:
        if result<B1[n-2]:
            result=B1[n-2]
    else:
        if result<gcd(B1[i-1],B2[n-i-1]):
            result=gcd(B1[i-1],B2[n-i-1])

print(result)

Submission status: Wrong Answer

Solution code:
import statistics
import math

N = int(input())
value = list(map(int, input().split()))
ans = []
for i in range(N):
  p = 0
  A = 2
  while True:
    if value[i] % A == 0:
      ans.append(A)
      break
    else:
  	  A = A + 1
    p = p + 1

ans = statistics.mode(ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions # python 3.4.3
# import copy
from functools import reduce

N=int(input())

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

# n個目までの最小公約数
dp=[0 for _ in range(N+1)]
dpRev=[0 for _ in range(N+1)]

def gcd(a,b):
	if a == 0: 
		return b
	elif b == 0: 
		return a
	# print(a,b)
	return reduce(fractions.gcd, (a,b))

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

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

# print(dp)
# print(dpRev)


ans=0
for n in range(N-1):
	ans = max( ans, gcd(dp[n],dpRev[n+1]) )


print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
Alist = [0]+list(map(int, input().split()))+[0]
Rlist = [0]*(N+2)
Llist = [0]*(N+1)
for i in range(N):
    Llist[i+1] = gcd(Llist[i], Alist[i])
    Rlist[N-i] = gcd(Rlist[N-i+1], Alist[N-i+1])
print(max([gcd(Rlist[i], Llist[i]) for i in range(N)]))

Submission status: Wrong Answer

Solution code:
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq

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

Submission status: Wrong Answer

Solution code:
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq

if 1 == 0:
        print(1)
else:
        print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A = sorted(A,reverse=True)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

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

while not len(A) == 2:
    x = A.pop()
    y = A.pop()
    a = gcd(x,y)
    A.append(a)
    A = sorted(A,reverse=True)
print(A[1])

Submission status: Wrong Answer

Solution code:
import fractions
import copy

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

ans = 0

for i in range(N):
    for j in range(i+1, N):
        tmp = fractions.gcd(A_li[i], A_li[j])
        if tmp > ans:
            ans = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

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

def mass_gcd(L):
    # num is 1
    if len(L) == 1:
        return L[0]
    else:
        max_gcd = fractions.gcd(L[0], L[1])

    # solve gcd
    for i in range(1, len(L) - 1):
        max_gcd = max(max_gcd, fractions.gcd(L[i], L[i + 1]))
    return max_gcd

ans = mass_gcd(A)
for i in range(0, N):
    left = A[:i]
    right = A[(i + 1):]
    if len(left) == 0:
        pass
    elif len(right) == 0:
        pass
    else:
        ans = max(ans, fractions.gcd(mass_gcd(left), mass_gcd(right)))
print(ans)

Submission status: Wrong Answer

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


N = int(input())
A = list(map(int, input().split()))
R = [0 for i in range(N - 1)]
L = [0 for i in range(N - 1)]
R[0] = A[0]
L[0] = A[-1]
for i in range(1, N - 1):
    R[i] = gcd(R[i - 1], A[i])
for j in range(1, N - 1):
    L[j] = gcd(L[j - 1], A[-1 - j])
    # print(L[j])
t = 0
for i in range(N - 2):
    print(R[i], L[N - 3 - i])
    t = max(t, gcd(R[i], L[N - 3 - i]))
print(max(t, R[-1], L[-1]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 27 21:46:41 2019

@author: ryo
"""

import copy
import numpy as np
n=int(input())
array=[]
array=map(int,input().split())
array = list(array)
array = np.array(array)
answer_array = []

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

def return_best_gcd(array):
    if(array.size==2):
        return gcd(array[0],array[1])
    
    for drop in range(0,n):
        cp_array = array.copy()
        
        cp_array = np.delete(cp_array,drop)
        
        gcd_candidate = 1
        for index in range(0,cp_array.size-1):
            val = gcd(cp_array[index],cp_array[index+1])
            if(val > gcd_candidate):
                gcd_candidate = val
        answer_array.append(gcd_candidate)
    return np.max(np.array(answer_array))


answer = return_best_gcd(array)
print(answer)

Submission status: Wrong Answer

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

n=int(input())
A=list(map(int, input().split()))
#a=1
init=1
#maxa=99999999999999999999999999
#maxa=A[1]
B1=[]
for i in A:
    if init==1:
        a=i
        init=0
        B1.append(a)
    else:
        a=gcd(a,i)
        B1.append(a)

init=1
B2=[]
for i in A[::-1]:
    if init==1:
        a=i
        init=0
        B2.append(a)
    else:
        a=gcd(a,i)
        B2.append(a)

result=0
for i in range(n):
    if i==0:
        if result<B2[n-1]:
            result=B2[n-1]
    elif i==n-1:
        if result<B1[n-1]:
            result=B1[n-1]
    else:
        if result<gcd(B1[i-1],B2[n-i-2]):
            result=gcd(B1[i-1],B2[n-i-2])

print(result)

Submission status: Wrong Answer

Solution code:
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq

print("Hello")

Submission status: Wrong Answer

Solution code:
import sys
from fractions import gcd
from functools import reduce
from itertools import combinations

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    A = il()
    b = [0] * N
    c = [0] * N
    for i in range(1, N):
        b[i] = gcd(b[i - 1], A[i - 1])
    for i in range(N - 2, 0, -1):
        c[i] = gcd(c[i + 1], A[i + 1])
    d = [gcd(b[i], c[i]) for i in range(N)]
    return max(d)


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)

n = ip()                                     #入力整数1つ
#a,b,t= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#k = ip()                      #入力セット(整数改行あり)(1/2)
#v=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
if n==2:
    print(max(a))
else:
    ans = []
    s = [a[0]]
    for i in range(1,n):
        s.append(fractions.gcd(s[i-1],a[i]))
    r = [a[n-1]]
    for i in range(n-2,-1,-1):
        r.insert(0,fractions.gcd(r[0],a[i]))
#    print(s,"from left")
   # print(r,"from right")
    ans.append(r[1])
    for i in range(1,n-1):
        ans.append(fractions.gcd(s[i-1],r[i+1]))
    ans.append(r[n-2])
    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)
  ans2=[]
  for i in range(n):
    ans2.append(gcd(gcd(arr[1],arr[2]),arr[i]))
  ans2=sorted(ans2)
  ans3=[]
  for i in range(n):
    ans3.append(gcd(gcd(arr[2],arr[0]),arr[i]))
  ans3=sorted(ans3)
  finans1=ans1[1]
  finans2=ans2[1]
  finans3=ans3[1]
  finalans=max(finans1,finans2,finans3)
  print(finalans)

Submission status: Wrong Answer

Solution code:
import fractions

n = int(input())
a = list(map(int, input().split()))
t = []
l = 0
r = 0

for i in range(n):
    for j in range(i-1):
        l = fractions.gcd(l, a[j])
        r = fractions.gcd(r, a[n-j-1])
    t.append(fractions.gcd(l, r))

print(max(t))

Submission status: Wrong Answer

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

### input num
#i = input()
#A, B, T = [int(x) for x in i.split()]
N = int(input())
A = [int(x) for x in input().split()]
#C = [int(x) for x in input().split()]

### input debug
#print("debug:{}".format(gcd(max(A),min(A))))
#print(list(reversed(range(1, gcd(max(A),min(A))+1))))

B = sorted(A)
Amax = B.pop()
Amax = B.pop()

#N = max(A)//2 if max(A)//2 > gcd(Amax, min(A)) else gcd(Amax, min(A))

X = 0
for i in reversed(range(1, Amax//2+1)):
    count = 0
    for j in A:
        if (j % i) == 0:
            count += 1
    if count > len(A)-2:
        X = i
        break

### output
print(X)

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())
t = list(map(int, input().split()))
soin = []
temp=0
nokori =[]

if (N != 2):
    for i in range(N):
        nokori = t[0:i]+t[i+1:]

        for j in range(N-2):
            soin.append(gcd(nokori[j],nokori[j+1]))
else:
    soin.append(gcd(t[0], t[1]))

print(max(soin))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce


def main():

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

    gcds_r = [1] * N
    gcds_r[0] = A[0]
    for n in range(1, N):
        gcds_r[n] = fractions.gcd(gcds_r[n-1], A[n])

    gcds_l = [1] * N
    gcds_l[-1] = A[-1]
    for n in range(N-1)[::-1]:
        gcds_l[n] = fractions.gcd(gcds_l[n+1], A[n])

    max_gcd = 1
    for n in range(1, N-1):
        max_gcd = max(max_gcd, fractions.gcd(gcds_r[n-1], gcds_l[n+1]))

    max_gcd = max(max_gcd, gcds_l[N-1], gcds_r[1])

    print(max_gcd)  


main()

Submission status: Wrong Answer

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

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


N=int(input())
a=sorted(spaceinput(),reverse=True)


notrewrite=[-1]*N
rewrite=[-1]*N
best=[-1]*N

notrewrite[0]=a[0]
notrewrite[1]=gcd(a[0],a[1])
rewrite[0]=a[0]
rewrite[1]=a[0]
best[0]=a[0]
best[1]=a[0]

for i in range(2,N):
    notrewrite[i]=gcd(notrewrite[i-1],a[i])
    rewrite[i]=notrewrite[i-1]
    best[i]=max([rewrite[i],gcd(a[i],best[i-1])])
    #print([notrewrite[i],rewrite[i]])



print(best[-1])

Submission status: Wrong Answer

Solution code:

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

### input num
#i = input()
#A, B, T = [int(x) for x in i.split()]
N = int(input())
A = [int(x) for x in input().split()]
#C = [int(x) for x in input().split()]

### input debug
#print("debug:{}".format(gcd(max(A),min(A))))
#print(list(reversed(range(1, gcd(max(A),min(A))+1))))

B = sorted(A)
Amax = B.pop()
Amax = B.pop()

N = max(A)//2 if max(A)//2 > gcd(Amax, min(A)) else gcd(Amax, min(A))

X = 0
for i in reversed(range(1, N+1)):
    count = 0
    for j in A:
        if (j % i) == 0:
            count += 1
    if count > len(A)-2:
        X = i
        break

### output
print(X)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

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

# 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))で計算できる。

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 == 0:
        v = R[1]
    elif i == N-1:
        v = L[N-1]
    else:
        v = gcd(R[i+1], L[i-1])
    mx = max(v, mx)
print(mx)