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: Runtime Error

Solution code:
#include <stdio.h>
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<complex>
#include<vector>
#include<array>

using namespace std;

int nx[]={0,1,0,-1};
int ny[]={0,1,0,-1};

int gcd(int a,int b)
{
    if(a<b) return gcd(b,a);
    if(b==0)return a;
    int r;
    while((r=a%b))
    {
        a=b;
        b=r;
    }
    return b;
}

//*****************************************
//方針：この問題はＮコからN-1コもってきたときの最大公約数が最大となるときの最大公約数を出せという問題になる
//したがって、N-1コに対する最大公約数を全探索すれば良いのではないか

//反省：案の定ＧＣＤ全探索はＴＬＥになる、ＤＰで時間短縮だ！！
int n,i;

int main(void){

    
    scanf("%d",&n);

    int A[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&A[i]);
    }


    int L[n+1],R[n+1];
    L[0]=0;
    R[n]=0;

    for(i=0;i<n;i++)
    {
        L[i+1]=gcd(L[i],A[i]);
    }

    for(i=n;i>0;i--)
    {
        R[i-1]=gcd(R[i],A[i-1]);
    }

    int dp[n];
    int max=-100;
    for(i=0;i<n;i++)
    {
        dp[i]=gcd(L[i],R[i+1]);
        if(max<dp[i])
        {
            max=dp[i];
        }
    }

    cout<<max<<endl;


    return 0;
}

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = sorted(A.copy(), reverse=True)

ans = 1
counts = [N] * (B[0]+1)
t = B[-1]//2-1
t = t if t > 0 else 0
for d in range(B[0], t, -1):
    for b in B:
        if b % d == 0:
            counts[d] -= 1
            if d != b // d:
                counts[b//d] -= 1

    if counts[d] < 2:
        ans = d
        break

if ans == 1:
    for i in range(B[-1]//2, 0, -1):
        if counts[i] < 2:
            ans = i
            break

print(ans)

Submission status: Runtime Error

Solution code:

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

if n==2:
    print(max(a))
    exit()
'''
L = [gcd(a[0], a[1])]
R = [gcd(a[n-2], a[n-1])]
'''
L = [0 for i in range(n+1)]
R = [0 for i in range(n+1)]
for i in range(1,n+1):
    L[i] = gcd(L[i-1], a[i-1])

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

m = []

for i in range(n):
    m.append(gcd(L[i], R[i+1]))

print(max(m))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys,math
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):
        _l = math.gcd(_l, A[i])
        L.append(_l)

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

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



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

#
# solve !!
#
solve(lines)

Submission status: Runtime Error

Solution code:
n = int(input())
num_list = list(map(int, input().split()))
num_unique = list(set(num_list))
num_unique.sort()
num_unique.reverse()
max_num = 0
flag = False
for i in range(num_unique[-2], 0, -1):
    if i == 1:
        max_num = 1
        break
    if flag and count < 2:
        break
    else:
        flag = True
        count = 0
        max_num = i
    for num in num_unique:
        if num / max_num < 1 or num % max_num != 0:
            count += 1
            if count > 1:
                break
print(max_num)

Submission status: Runtime Error

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

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

chk = {}
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

if n == 2:
    print max(a[0],a[1])
else:
    for i in range(2):
        make_divisors(a[i])
    cnt = 1
    for i in range(2,len(a)):
        k = a[i]
        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())
    for i in chk:
        if int(chk[i]) >= n - 1 and i > answer:
            answer = i
    print answer

Submission status: Runtime Error

Solution code:
import copy
import fractions
 
inp = int(input())
v = [int(d) for d in input().split()]
cc = []
m = []

if len(v) == 2:
    s = fractions.gcd(v[0],v[1])
    print(s)
    exit()
 
for e in range(len(v)):
    dd = copy.deepcopy(v)
    del dd[e]
    cc.append(dd)
 
for q in cc: #q 1抜き
    s = q[0]
    for a in range(len(q) -1): 
        s = gcd(s,q[a+1])
    m.append(s)
m.sort()
 
print(m[-1])

Submission status: Runtime Error

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

max_gcd = 1

def L(i):
        if i == 0:
                return 0
        else:
                return gcd(L(i-1),A[i-1])

def R(i):
        if i == N:
                return 0
        else:
                return gcd(R(i+1),A[i])

M = []

for i in range(N):
        # print(M)
        M.append(gcd(L(i), R(i+1)))

print(max(M))

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce
def gcd_list(numbers):
    return reduce(gcd, numbers)
n = int(input())
a = [int(_) for _ in input().split()]
a.sort()
ir = [a[0]]
for i in range(1,n):
    ir.append(gcd(a[0], a[i]))
mi = ir[1:].index(min(ir[1:]))+1
mr = []
for i in range(n):
    mr.append(gcd(a[mi], a[i]))
if ir.count(min(ir)) > mr.count(min(mr)):
    print(gcd_list(a[1::]))
elif ir.count(min(ir)) == mr.count(min(mr)):
    print(a[0])
elif ir.count(min(ir)) < mr.count(min(mr)):
    a.pop(mi)
    print(gcd_list(a))

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce
N = int(input())
Alist = list(map(int, input().split()))
Alist = AList+[Alist[0]]
def gcd_list(numbers):
  return reduce(gcd, numbers)
if len(Alist) == 2:
    print(max(Alist))
else:
    gcdlist=[gcd_list(Alist[i:i+2]) for i in range(N)]
    ind = gcdlist.index(min(gcdlist))
    if ind == N:
      print(max([gcd_list(Alist[:N]), gcd_list(Alist[1:])]))
    else:
      print(max([gcd_list(Alist[:ind]+Alist[ind+1:]), gcd_list(Alist[:ind+1]+Alist[ind+2:])]))

Submission status: Runtime Error

Solution code:
import functools
import fractions

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

num = 1

if len(A) == 2:
  print(max(A))
else:
  for i in range(len(A)):
    B = A[ : i] + A[i + 1:]
    g = functools.reduce(fractions.gcd, A[:i] + A[i+1:])
    num = g if g > num
  print(num)

Submission status: Runtime Error

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) : 
        print(i , R[i] , L[N - i - 3])
        value = gcd(R[i] , L[N - i - 3])
        if value > maxValue : maxValue = value
    print(max(maxValue , R[-1] , L[-1])
main()

Submission status: Runtime Error

Solution code:
import math
N = int(input())
aLst = list(map(int, input().split()))

ansLst = []
for i in range(len(aLst)):
    ans = 0
    for j in range(len(aLst)):
        if i != j:
            ans = math.gcd(ans, aLst[j])
    ansLst.append(ans)
ansLst.sort(reverse=True)
print(ansLst[0])

Submission status: Runtime Error

Solution code:
n = int(N)
a_list = [int(i) for i in A.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: Runtime Error

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: Runtime Error

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

num = 1

if len(A) == 2:
  print(max(A))
else:
  for i in range(len(A)):
    B = A[ : i] + A[i + 1:]
    g = functools.reduce(fraction.gcd, B)
    if (g > num):
      num = g
  print(num)

Submission status: Runtime Error

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.appenzad(gl)
    gr = fractions.gcd(gr,l[N-1-i])
    R.append(gr)

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

print(max(M))

Submission status: Runtime Error

Solution code:
import functools
import math
import copy
N = int(input())
a_new = list(map(int,input().split()))
a = copy.deepcopy(a_new)
b = a[N//2:]
a = a[:N//2]
N = N//2
if len(a_new) >= 4:
    if functools.reduce(math.gcd, b) < functools.reduce(math.gcd, a) and len(a) !=1:
        a = b
        max = functools.reduce(math.gcd, a)
    elif len(a) != 1:
        max = functools.reduce(math.gcd, b)
    while True:
        if len(a) == 1:
            break
        b = a[N//2:]
        a = a[:N//2]
        if len(a) == 1:
            a = int(a[0])
            break
        if functools.reduce(math.gcd,b) < functools.reduce(math.gcd,a):
            a = copy.deepcopy(b)
        N = len(a)


    b_old = copy.deepcopy(b)
    b.append(max)
    a_resu = (math.gcd(max,a))
    b_resu = (functools.reduce(math.gcd,b))
    if a_resu == b_resu:
        print(max)
    elif a_resu < b_resu:
        a_new.remove(a)
        print(functools.reduce(math.gcd,a_new))
    else:
        a = [b_old[0],max]
        b = [b_old[1],max]
        if functools.reduce(math.gcd, b) < functools.reduce(math.gcd, a):
            a_new.remove(b_old[1])
            print(functools.reduce(math.gcd, a_new))
        else:
            a_new.remove(b_old[0])
            print(functools.reduce(math.gcd, a_new))
elif len(a_new) == 3:
    print(max(math.gcd(a_new[0], a_new[1]),math.gcd(a_new[0], a_new[2]),math.gcd(a_new[1],a_new[2])))
else:
    print(max(a_new[0],a_new[1]))

Submission status: Runtime Error

Solution code:
#C問題　累積和でやってみよう
import copy
N = int(input())
A = [int(i) for i in input().split()]

def gcd(*numbers):
    return reduce(math.gcd, numbers)

num = []
for i in range(N):
    temp = copy.copy(A)
    del temp[i]
    num.append(gcd(*temp))

print(max(num))

Submission status: Runtime Error

Solution code:
from fractions import gcd
#from functools import reduce
a=int(input())
li=list(map(int,input().split()))
left_gcd=[]
left_gcd.append(li[0])
right_gcd=[]
right_gcd.append(li[a-1])

for i in range(a-1):
    left_gcd.append(gcd(left_gcd[i],li[i+1]))
k=0
for i in range(a-1,0,-1):
    right_gcd.append(gcd(right_gcd[k],li[i-1]))
    k=k+1
# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)
#print(right_gcd)
#print(left_gcd)
num_li=[]
num_li.append(right_gcd[a-2])
num_li.append(left_gcd[a-2])
#s=2
for i in range(a):
    ans=math.gcd(left_gcd[(a-3)-i],right_gcd[i])
    #print(left_gcd[(a-3-i)],right_gcd[i])
  
    #print(ans)
    num_li.append(ans)
    

print(max(num_li))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = min(A)
tmp = 1
if M == 1:
    A.pop(1)
    if 1 in A:
        tmp = 1
    else:
        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
    

else:
    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: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = [int(i) for i in input().split()]
B = sorted(A.copy(), reverse=True)

ans = 1
counts = np.full(B[0]+1, N)
for d in range(B[0], B[-1]//2-1, -1):
    for b in B:
        if b % d == 0:
            counts[d] -= 1
            if d != b // d:
                counts[b//d] -= 1

    if counts[d] < 2:
        ans = d
        break

if ans == 1:
    for i in range(B[-1]//2, 0, -1):
        if counts[i] < 2:
            ans = i
            break

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

result.sort(reverse=True)

print(result[1])

Submission status: Runtime Error

Solution code:
from fractions import gcd
#from functools import reduce
a=int(input())
li=list(map(int,input().split()))
left_gcd=[]
left_gcd.append(li[0])
right_gcd=[]
right_gcd.append(li[a-1])

for i in range(a-1):
    left_gcd.append(math.gcd(left_gcd[i],li[i+1]))
k=0
for i in range(a-1,0,-1):
    right_gcd.append(math.gcd(right_gcd[k],li[i-1]))
    k=k+1
# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)
#print(right_gcd)
#print(left_gcd)
num_li=[]
num_li.append(right_gcd[a-2])
num_li.append(left_gcd[a-2])
#s=2
for i in range(a):
    ans=math.gcd(left_gcd[(a-3)-i],right_gcd[i])
    #print(left_gcd[(a-3-i)],right_gcd[i])
  
    #print(ans)
    num_li.append(ans)
    

print(max(num_li))

Submission status: Runtime Error

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

num = 1

if len(A) == 2:
  print(max(A))
else:
  for i in range(len(A)):
    B = A[ : i] + A[(i + 1):]
    g = functools.reduce(math.gcd, B)
    if (g > num):
      num = g
  print(num)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
x = 0
for i in range(n-1):
    keep = a[0]
    a.pop(0)
    num = reduce(math.gcd, a)
    if num > x:
        x = num
    a.append(keep)
print(x)

Submission status: Runtime Error

Solution code:
from fraction 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: Runtime Error

Solution code:
def gcd(a,b):
    if b==0:
        return max(a,b)
    else:
        if a%b == 0:
            return(b)
        else:
            return gcd(b,a%b)
n = int(input())
a = list(map(int,input().split()))
l=[0 for i in range(n+1)]
r=[0 for i in range(n+1)]

for i in range(1,n):
    l[i]=gcd(l[i-1],a[i-1])
    r[i]=gcd(r[i-1],a[n-i])
for i in range(n):
    e[i] = gcd(l[i],r[n-1-i])
print(max(e))

Submission status: Runtime Error

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]))
        raise "hoge"
    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: Runtime Error

Solution code:
import math
#from functools import reduce
a=int(input())
li=list(map(int,input().split()))
left_gcd=[]
left_gcd.append(li[0])
right_gcd=[]
right_gcd.append(li[a-1])

for i in range(a-1):
    left_gcd.append(math.gcd(left_gcd[i],li[i+1]))
k=0
for i in range(a-1,0,-1):
    right_gcd.append(math.gcd(right_gcd[k],li[i-1]))
    k=k+1
# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)
#print(right_gcd)
#print(left_gcd)
num_li=[]
num_li.append(right_gcd[a-2])
num_li.append(left_gcd[a-2])
#s=2
for i in range(a):
    ans=math.gcd(left_gcd[(a-3)-i],right_gcd[i])
    #print(left_gcd[(a-3-i)],right_gcd[i])
  
    #print(ans)
    num_li.append(ans)
    

print(max(num_li))

Submission status: Runtime Error

Solution code:
import numpy as np
import copy

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

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def gcdover3(a):
    res = max(a)
    for idx in range(len(a)-1):
        res = min([gcd(a[idx],a[idx+1]),res])
    return res

if N<=2:
    print(max(A))
else:
    gcdss = []
    for i in range(len(A)):
        A_temp = copy.deepcopy(A)
        A_temp.pop(i)
        gcdss.append(gcdover3(A_temp))
    print(max(gcdss))

Submission status: Runtime Error

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: Runtime Error

Solution code:
N = int(input())
A = [int(s) for s in input().split()]
ans = 0
temp = [0] * (max(A) + 1)
for i in range(N):
    for d in range(1, int(A[i]/2)):
        if A[i] % d == 0:
            temp[d] += 1
    temp[A[i]] += 1
for i in range(max(A), 0, -1):
    if N - 1 <= temp[i]:
        ans = i
        break
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

n=int(input())
a = np.array([int(x) for x in input().split()])
a = np.sort(a)

b = np.diag(a)

for i in range(0, len(a)):
    for j in range(0, i):
        b[i,j] = a[i] - a[j]
        b[j,i] = a[i] - a[j]
        
c = np.delete(b, obj=max(np.unravel_index(np.argmin(b), b.shape)[0],np.unravel_index(np.argmin(b), b.shape)[1]), axis=0)
c = np.delete(c, obj=max(np.unravel_index(np.argmin(b), b.shape)[0],np.unravel_index(np.argmin(b), b.shape)[1]), axis=1)

d=np.copy(b)
d[np.unravel_index(np.argmin(b), b.shape)[0], np.unravel_index(np.argmin(b), b.shape)[1]] = c.min()
d[np.unravel_index(np.argmin(b), b.shape)[1], np.unravel_index(np.argmin(b), b.shape)[0]] = c.min()

for i in range(0,n):
    if i != max(np.unravel_index(np.argmin(b), b.shape)[0],np.unravel_index(np.argmin(b), b.shape)[1]):
        d[i, max(np.unravel_index(np.argmin(b), b.shape)[0],np.unravel_index(np.argmin(b), b.shape)[1])]= d[max(np.unravel_index(np.argmin(b), b.shape)[0],np.unravel_index(np.argmin(b), b.shape)[1]), max(np.unravel_index(np.argmin(b), b.shape)[0],np.unravel_index(np.argmin(b), b.shape)[1])] - d[i,i]
        d[max(np.unravel_index(np.argmin(b), b.shape)[0],np.unravel_index(np.argmin(b), b.shape)[1]), i]= d[max(np.unravel_index(np.argmin(b), b.shape)[0],np.unravel_index(np.argmin(b), b.shape)[1]), max(np.unravel_index(np.argmin(b), b.shape)[0],np.unravel_index(np.argmin(b), b.shape)[1])] - d[i,i]
print(math.gcd(d[0,0], d[d>0].min()))

Submission status: Runtime Error

Solution code:
def Lgcd(i):
    if i == 0:
        return 0
    if i == 1:
        return a_s[0]
    if i in Lmemo:
        return Lmemo[i]
    re = gcd(Lgcd(i - 1), a_s[i - 1])
    Lmemo[i] = re
    return re


def Rgcd(i):
    if i == n - 1:
        return 0
    if i == n - 2:
        return a_s[-1]
    if i in Rmemo:
        return Rmemo[i]
    re = gcd(Rgcd(i + 1), a_s[i + 1])
    Rmemo[i] = re
    return re


def gcd(a, b):
    if a * b == 0:
        return a + b
    while 1:
        a, b = b, a % b
        if b == 0:
            return a


Lmemo = {}
Rmemo = {}
n = int(input())
a_s = list(map(int, input().split()))
mx = 0
for i in range(n):
    g = gcd(Lgcd(i),Rgcd(i))
    if g > mx:
        mx = g
print(mx)

Submission status: Runtime Error

Solution code:
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq
math.gcd(0,1)

Submission status: Runtime Error

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():
        if A[j]%i != 0:
            count += 1
            memo = j
            if count > 1:
                break
    if count <= 1:
        tmp = i
        break
        

print(tmp)

Submission status: Runtime Error

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(math.gcd(1,2))

Submission status: Runtime Error

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():
        if A[j]%i != 0:
            count += 1
            memo = j
            if count > 1:
                break
    if count <= 1:
        tmp = i
        break
        

print(tmp)

Submission status: Runtime Error

Solution code:
from functools import reduce

result = 0

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

n = int(input())
A = list(map(int, input().split()))
X = [0 for i in range n]
Y = [0 for i in range n]
for i in range(1, N):
    X[i] = gcd(X[i-1], A[i-1])
for i in range(n-1)[::-1]:
    Y[i] = gcd(Y[i+1], A[i+1])
print(max(gcd(X[i], Y[i]) for i in range(n)))

Submission status: Runtime Error

Solution code:
import math

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

l = [0]*(n+2)
r = [0]*(n+2)
m = [0]*(n+2)

for i in range(n+1):
    j = n-i
    if i == 0:  # j = n
        l[i] = 0
        r[j+1] = 0
    else:
        l[i] = math.gcd(l[i-1], a[i-1])
        r[j] = math.gcd(r[j+1], a[j])

m = [math.gcd(l[i], r[i+1]) for i in range(n+1)]

print(max(m))

Submission status: Runtime Error

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(math.gcd(L[-1], A[i]))

Submission status: Runtime Error

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
gcd_L_map = {}
def GCD_L(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 : 
        if len(numbers) in gcd_L_map : 
            return gcd_L_map[len(numbers)]
        value = GCD_L(numbers[:len(numbers)-1])
        result = gcd(value , numbers[len(numbers) - 1])
        gcd_L_map[len(numbers)] = result
        return result

gcd_R_map = {}
def GCD_R(numbers):
    numbers = list(reversed(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 : 
        if len(numbers) in gcd_L_map : 
            return gcd_R_map[len(numbers)]
        value = GCD_L(numbers[:len(numbers)-1])
        result = gcd(value , numbers[len(numbers) - 1])
        gcd_R_map[len(numbers)] = result
        return result

def main() : 
    N = int(input())
    a_list = input().split(" ")
    a_list = [int(i) for i in a_list]
    maxValue = 0
    for i in range(N) : 
        if i == 0 : 
            prev_list = a_list[1:]
            rst = GCD_R(prev_list )
        elif i == N - 1 : 
            after_list = a_list[:N-1]
            rst = GCD_L(after_list)
        else : 
            prev_list = a_list[0 : i ]
            after_list = a_list[i + 1 :] 
            rst = gcd(GCD_L(prev_list ) , GCD_R(after_list ))
        if maxValue < rst : maxValue = rst
    print(maxValue)
main()

Submission status: Runtime Error

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

L = len(A)
from functools import reduce
from fractions import gcd

g = reduce(gcd, A)

class SegTree():
  import math
  def __init__(self, func, A, identity=1):
    self._func = func
    self._N = 1
    while self._N < len(A):
      self._N *= 2
       # 長さ 7 なら N=3 (2^3=8)
    self._identity = identity # maxなら-1e9, sumなら0, productなら1

    self._tree = [self._identity] * (2*self._N -1) 
    self._tree[self._N-1:self._N-1+ len(A)] = A #最下段に元の配列を
    for i in range(self._N-2, -1, -1):
      self._update_single_node(i)
    ########
    # N=3: #
    # 0000 #
    # 1122 #
    # 3456 #
    ########
    self._node_range = [(i-self._N+1,i-self._N+2) for i in range(2*self._N-1)] #right_exclusive
    for i in range(self._N-2, -1, -1):
      self._node_range[i] = (self._node_range[2*i+1][0], self._node_range[2*i+2][1])

  def _update_single_node(self,i):
    self._tree[i] = self._func(self._tree[2*i+1], self._tree[2*i+2])

  def point_update(self,i,x):
    # A[i] = x (addではないので注意)
    j = self._N-1+i
    self._tree[j] = x
    while j>0:
      j = (j-1)//2
      self._update_single_node(j)

  def range_query(self, l, r, on=0):
    # reduce(func, A[l:r])
    # onはノード[on]上と重なる部分の，ということ
    onl, onr = self._node_range[on]
    
    # ノード[on]上はすべて覆う
    if l<=onl and onr<=r:
      return self._tree[on]
    
    # 重なりなし
    elif onr<=l or r<=onl:
      return self._identity
    
    else:
      return self._func(self.range_query(l, r, on=2*on+1),
                        self.range_query(l, r, on=2*on+2))

st = SegTree(gcd, A, identity=l)

answer = 0
for i in range(len(A)):
  st
  st.point_update(i, A[i-1])
  answer = max(answer, st._tree[0])
  st.point_update(i, A[i])

print(answer)

Submission status: Runtime Error

Solution code:
import sys
from fractions import gcd

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

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

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

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

ans = 0
for i in range(n - 2):
    ans = max(ans, gcd(l[i], r[i + 2]))
ans = max(ans, l[-2], r[1])
print(ans)

Submission status: Runtime Error

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            if not i in divisors:
                divisors.append(i)
            if not (n//i) in divisors and i != n // i:
                divisors.append(n//i)
    return divisors

N = int(input())
aList = [int(x) for x in input().split()]
memo = {}
for a in aList:
    cache = make_divisors(a)
    for x in cache:
        if x in memo:
            memo[x] += 1
        else:
            memo[x] = 1
result = 1
for x, y in sd:
    if y > N-2 and x > result:
        result = x
print(result)

Submission status: Runtime Error

Solution code:
import math
import random


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

l = [0]*(n+2)
r = [0]*(n+2)
m = [0]*(n+2)

for i in range(n+1):
    j = n-i
    if i == 0:  # j = n
        l[i] = 0
        r[j+1] = 0
    else:
        l[i] = math.gcd(l[i-1], a[i-1])
        r[j] = math.gcd(r[j+1], a[j])

m = [math.gcd(l[i], r[i+1]) for i in range(n+1)]

print(max(m))




#
# tmpgcd = list()
#
# for i in range(2):
#     sample = random.choices(a, k=2)
#     tmpgcd.append(computeGCD(sample[0], sample[1]))
# tmpgcd = sorted(tmpgcd)
#
# # print('hey')
#
# mini = tmpgcd[1]
#
#
# def computeGCD(x, y):
#     if x > y:
#         small = y
#     else:
#         small = x
#     for i in range(1, small + 1):
#         if ((x % i == 0) and (y % i == 0)):
#             gcd = i
#
#     return gcd
# # print(mini, tmpgcd)
# 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)
#
#
#
#
#
#