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())
a = list(map(int, input().split()))

left_gcd_list = [a[0]]
right_gcd_list = [a[n - 1]]

for i in range(1, n):
    left_gcd_list.append(fractions.gcd(a[i], left_gcd_list[i - 1]))
    right_gcd_list.insert(0, fractions.gcd(a[n - 1 - i], right_gcd_list[0]))

print(max([left_gcd_list[n - 2]] +
          [fractions.gcd(left_gcd_list[i], right_gcd_list[i + 2]) for i in range(0, n - 2)] +
          [right_gcd_list[n - 2]]))


if __name__ == '__main__':
    pass

Submission status: Wrong Answer

Solution code:
_ = input()
L = list(map(int, input().split()))
L_set = list(set(L))
L_set.sort()

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()
    # print(divisors[::-1])
    return divisors[::-1]


def search(yakusu_list):
    for yakusu in yakusu_list:
        cnt = 0
        for l in L:
            if l % yakusu != 0:
                cnt += 1
        if cnt == 1 or cnt == 0:
            print(yakusu)
            return True
        else:
            pass
    return False


if not search(make_divisors(L[0])[:-1]):
    if not search(make_divisors(L[1])):
        print(1)

Submission status: Wrong Answer

Solution code:
_ = input()
L = list(map(int, input().split()))
L_set = list(set(L))
L_set.sort()

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()
    # print(divisors[::-1])
    return divisors[::-1]


def search(yakusu_list):
    for yakusu in yakusu_list:
        cnt = 0
        for l in L:
            if l % yakusu != 0:
                cnt += 1
        if cnt == 1 or cnt == 0:
            print(yakusu)
            return True
        else:
            pass
    return False


if not search(make_divisors(L[0])):
    if not search(make_divisors(L[1])):
        print(1)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return int(b*a/gcd(a,b))
N=int(input())
list1=list(map(int,input().split()))
list1.sort(reverse=True)
list2=[list1[0]]
for i in range(N-1):
    list2.append(gcd(list2[i],list1[i+1]))
x=min(list1)
list3=[]
for i in list2:
    list3.append(lcm(gcd(x,i),min(list2)))
print(max(list3))

Submission status: Wrong Answer

Solution code:
import importlib
import_module = lambda name:importlib.import_module(name)

input = import_module('sys').stdin.readline
input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_ints_list = lambda:list(input_ints())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,f:[f() for _ in range(n)]

gcd_base = lambda a,b:import_module('fractions').gcd(a,b) # 最大公約数（2値)
gcd = lambda a:import_module('functools').reduce(gcd_base,a) # 最大公約数（リスト）
lcm_base = lambda a,b:(a*b)//import_module('fractions').gcd(a,b) # 最小公倍数(2値)
lcm = lambda a:import_module('functools').reduce(lcm_base,a,1) # 最小公倍数(リスト)

permutations = lambda a,n:import_module('itertools').permutations(a,n) # 順列
combinations = lambda a,n:import_module('itertools').combinations(a,n) # 組み合わせ
product = lambda a,b:import_module('itertools').product(a,b) # 二つのリストの直積

init_array_1dim = lambda v,n:[v]*n
init_array_2dim = lambda v,n,m:[init_array_1dim for _ in range(m)]

# 四捨五入はround
ceil = lambda a:import_module('math').ceil(a) # 切り上げ
floor = lambda a:import_module('math').floor(a) # 切り捨て

# キュー
convert_list_to_queue = lambda a:import_module('collections').deque(a)
pop_q = lambda a:a.popleft()
push_q = lambda a,e:a.appendleft(e)
push_q_list = lambda a,l:a.extendleft(l) 

# プライオリティキュー
def init_head(a):import_module('heapq').heapify(a)
def heap_push(a,v):import_module('heapq').heappush(a,v)
heap_pop = lambda a:import_module('heapq').heappop(a) # 最小値を取り出す

# 二分探索
bisect_left = lambda a,x:import_module('bisect').bisect_left(a,x)
bisect_right = lambda a,x:import_module('bisect').bisect_left(a,x)
insert_left = lambda a,x:import_module('bisect').insert_left(a,bisect_left(a,x))
insert_right = lambda a,x:import_module('bisect').insert_right(a,bisect_right(a,x))

# 累積和、累積積、累積GCD
cumsum = lambda a:import_module('numpy').cumsum(import_module('numpy').array(a)) # 累積和
cumprod = lambda a:import_module('numpy').cumprod(import_module('numpy').array(a)) # 累積積
cumgcd = lambda a:import_module('numpy').frompyfunc(gcd_base, 2, 1).accumulate(a, dtype=import_module('numpy').object).astype(import_module('numpy').int) # 累積GCD

class UnionFind(object):
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

# グラフで全部到達できる経路が何個あるか
def dfs_graph(v,n,graph,visited):
    if all(visited):return 1 # 全部到達できたら1を返す
    ans = 0
    for i in range(n):
        if not graph[v][i]:continue # 結ぶ線がないときはスキップ
        if visited[i]:continue # 到達済みだったらスキップ
        visited[i] = True
        ans += dfs_graph(i,n,graph,visited)
        visited[i] = False
    return ans

# ワーシャルフロイド（グラフの要素数、グラフ）
def warshall_floyd(n,graph):
    d = init_array_2dim(float("inf"),n,n)
    # 初期化
    for i in range(n):
        d[i][i] = 0
        for j in range(n):
            if graph[i][j]:d[i][j] = 1
    # 距離算出
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

# グラフを初期化（グラフの要素数、グラフの線の両端、有向無向）
def init_graph(n,a,directed=False):
    visited = init_array_1dim(False,n)
    graph = init_array_2dim(False,n,n)
    for e in a:
        graph[e[0]-1][e[1]-1] = True
        if not directed:graph[e[1]-1][e[0]-1] = True # 無向グラフの場合
    return visited,graph

def two_pointers(s,threshold,ope='sum'):
    l,r = 0,0
    base = 0 
    if ope == 'sum':base = 0
    if ope == 'prd':base = 1
    diff = 0
    while r < len(s):
        val = 0
        if ope == 'sum':val = base+s[r]
        if ope == 'prd':val = base*s[r]
        if val <= threshold:
            if ope == 'sum':base += s[r]
            if ope == 'prd':base *= s[r]
            diff = max(diff, r-l+1)
            r += 1
        elif l == r:
            r += 1
            l += 1
        else:
            if ope == 'sum':base -= s[l]
            if ope == 'prd':base //= s[l]
            l += 1
    return diff

def solution():
    import numpy as np
    N = input_int()
    A = np.array(list(set(input_ints_list())))

    if len(A) == 1:print(A[0])
    else:
        gcds = [gcd(np.delete(A,i).tolist()) for i in range(len(A))]
        print(max(gcds))
	
if __name__ == '__main__':
    solution()

Submission status: Wrong Answer

Solution code:
import importlib
import_module = lambda name:importlib.import_module(name)

input = import_module('sys').stdin.readline
input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_ints_list = lambda:list(input_ints())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,f:[f() for _ in range(n)]

gcd_base = lambda a,b:import_module('fractions').gcd(a,b) # 最大公約数（2値)
gcd = lambda a:import_module('functools').reduce(gcd_base,a) # 最大公約数（リスト）
lcm_base = lambda a,b:(a*b)//import_module('fractions').gcd(a,b) # 最小公倍数(2値)
lcm = lambda a:import_module('functools').reduce(lcm_base,a,1) # 最小公倍数(リスト)

permutations = lambda a,n:import_module('itertools').permutations(a,n) # 順列
combinations = lambda a,n:import_module('itertools').combinations(a,n) # 組み合わせ
product = lambda a,b:import_module('itertools').product(a,b) # 二つのリストの直積

init_array_1dim = lambda v,n:[v]*n
init_array_2dim = lambda v,n,m:[init_array_1dim for _ in range(m)]

# 四捨五入はround
ceil = lambda a:import_module('math').ceil(a) # 切り上げ
floor = lambda a:import_module('math').floor(a) # 切り捨て

# キュー
convert_list_to_queue = lambda a:import_module('collections').deque(a)
pop_q = lambda a:a.popleft()
push_q = lambda a,e:a.appendleft(e)
push_q_list = lambda a,l:a.extendleft(l) 

# プライオリティキュー
def init_head(a):import_module('heapq').heapify(a)
def heap_push(a,v):import_module('heapq').heappush(a,v)
heap_pop = lambda a:import_module('heapq').heappop(a) # 最小値を取り出す

# 二分探索
bisect_left = lambda a,x:import_module('bisect').bisect_left(a,x)
bisect_right = lambda a,x:import_module('bisect').bisect_left(a,x)
insert_left = lambda a,x:import_module('bisect').insert_left(a,bisect_left(a,x))
insert_right = lambda a,x:import_module('bisect').insert_right(a,bisect_right(a,x))

# 累積和、累積積、累積GCD
cumsum = lambda a:import_module('numpy').cumsum(import_module('numpy').array(a)) # 累積和
cumprod = lambda a:import_module('numpy').cumprod(import_module('numpy').array(a)) # 累積積
cumgcd = lambda a:import_module('numpy').frompyfunc(gcd_base, 2, 1).accumulate(a, dtype=import_module('numpy').object).astype(import_module('numpy').int) # 累積GCD

class UnionFind(object):
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

# グラフで全部到達できる経路が何個あるか
def dfs_graph(v,n,graph,visited):
    if all(visited):return 1 # 全部到達できたら1を返す
    ans = 0
    for i in range(n):
        if not graph[v][i]:continue # 結ぶ線がないときはスキップ
        if visited[i]:continue # 到達済みだったらスキップ
        visited[i] = True
        ans += dfs_graph(i,n,graph,visited)
        visited[i] = False
    return ans

# ワーシャルフロイド（グラフの要素数、グラフ）
def warshall_floyd(n,graph):
    d = init_array_2dim(float("inf"),n,n)
    # 初期化
    for i in range(n):
        d[i][i] = 0
        for j in range(n):
            if graph[i][j]:d[i][j] = 1
    # 距離算出
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

# グラフを初期化（グラフの要素数、グラフの線の両端、有向無向）
def init_graph(n,a,directed=False):
    visited = init_array_1dim(False,n)
    graph = init_array_2dim(False,n,n)
    for e in a:
        graph[e[0]-1][e[1]-1] = True
        if not directed:graph[e[1]-1][e[0]-1] = True # 無向グラフの場合
    return visited,graph

def two_pointers(s,threshold,ope='sum'):
    l,r = 0,0
    base = 0 
    if ope == 'sum':base = 0
    if ope == 'prd':base = 1
    diff = 0
    while r < len(s):
        val = 0
        if ope == 'sum':val = base+s[r]
        if ope == 'prd':val = base*s[r]
        if val <= threshold:
            if ope == 'sum':base += s[r]
            if ope == 'prd':base *= s[r]
            diff = max(diff, r-l+1)
            r += 1
        elif l == r:
            r += 1
            l += 1
        else:
            if ope == 'sum':base -= s[l]
            if ope == 'prd':base //= s[l]
            l += 1
    return diff

def solution():
    import numpy as np
    N = input_int()
    A = np.array(input_ints_list())
    A[::-1].sort()

    max_gcd = -1
    for i in range(min(len(A),3)):
        nota = np.delete(A,i)
        gcd_nota = gcd(nota.tolist())
        max_gcd = gcd_nota if max_gcd < gcd_nota else max_gcd
    
    print(max_gcd)
	
if __name__ == '__main__':
    solution()

Submission status: Wrong Answer

Solution code:
import importlib
import_module = lambda name:importlib.import_module(name)

input = import_module('sys').stdin.readline
input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_ints_list = lambda:list(input_ints())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,f:[f() for _ in range(n)]

gcd_base = lambda a,b:import_module('fractions').gcd(a,b) # 最大公約数（2値)
gcd = lambda a:import_module('functools').reduce(gcd_base,a) # 最大公約数（リスト）
lcm_base = lambda a,b:(a*b)//import_module('fractions').gcd(a,b) # 最小公倍数(2値)
lcm = lambda a:import_module('functools').reduce(lcm_base,a,1) # 最小公倍数(リスト)

permutations = lambda a,n:import_module('itertools').permutations(a,n) # 順列
combinations = lambda a,n:import_module('itertools').combinations(a,n) # 組み合わせ
product = lambda a,b:import_module('itertools').product(a,b) # 二つのリストの直積

init_array_1dim = lambda v,n:[v]*n
init_array_2dim = lambda v,n,m:[init_array_1dim for _ in range(m)]

# 四捨五入はround
ceil = lambda a:import_module('math').ceil(a) # 切り上げ
floor = lambda a:import_module('math').floor(a) # 切り捨て

# キュー
convert_list_to_queue = lambda a:import_module('collections').deque(a)
pop_q = lambda a:a.popleft()
push_q = lambda a,e:a.appendleft(e)
push_q_list = lambda a,l:a.extendleft(l) 

# プライオリティキュー
def init_head(a):import_module('heapq').heapify(a)
def heap_push(a,v):import_module('heapq').heappush(a,v)
heap_pop = lambda a:import_module('heapq').heappop(a) # 最小値を取り出す

# 二分探索
bisect_left = lambda a,x:import_module('bisect').bisect_left(a,x)
bisect_right = lambda a,x:import_module('bisect').bisect_left(a,x)
insert_left = lambda a,x:import_module('bisect').insert_left(a,bisect_left(a,x))
insert_right = lambda a,x:import_module('bisect').insert_right(a,bisect_right(a,x))

# 累積和、累積積、累積GCD
cumsum = lambda a:import_module('numpy').cumsum(import_module('numpy').array(a)) # 累積和
cumprod = lambda a:import_module('numpy').cumprod(import_module('numpy').array(a)) # 累積積
cumgcd = lambda a:import_module('numpy').frompyfunc(gcd_base, 2, 1).accumulate(a, dtype=import_module('numpy').object).astype(import_module('numpy').int) # 累積GCD

class UnionFind(object):
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

# グラフで全部到達できる経路が何個あるか
def dfs_graph(v,n,graph,visited):
    if all(visited):return 1 # 全部到達できたら1を返す
    ans = 0
    for i in range(n):
        if not graph[v][i]:continue # 結ぶ線がないときはスキップ
        if visited[i]:continue # 到達済みだったらスキップ
        visited[i] = True
        ans += dfs_graph(i,n,graph,visited)
        visited[i] = False
    return ans

# ワーシャルフロイド（グラフの要素数、グラフ）
def warshall_floyd(n,graph):
    d = init_array_2dim(float("inf"),n,n)
    # 初期化
    for i in range(n):
        d[i][i] = 0
        for j in range(n):
            if graph[i][j]:d[i][j] = 1
    # 距離算出
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

# グラフを初期化（グラフの要素数、グラフの線の両端、有向無向）
def init_graph(n,a,directed=False):
    visited = init_array_1dim(False,n)
    graph = init_array_2dim(False,n,n)
    for e in a:
        graph[e[0]-1][e[1]-1] = True
        if not directed:graph[e[1]-1][e[0]-1] = True # 無向グラフの場合
    return visited,graph

def two_pointers(s,threshold,ope='sum'):
    l,r = 0,0
    base = 0 
    if ope == 'sum':base = 0
    if ope == 'prd':base = 1
    diff = 0
    while r < len(s):
        val = 0
        if ope == 'sum':val = base+s[r]
        if ope == 'prd':val = base*s[r]
        if val <= threshold:
            if ope == 'sum':base += s[r]
            if ope == 'prd':base *= s[r]
            diff = max(diff, r-l+1)
            r += 1
        elif l == r:
            r += 1
            l += 1
        else:
            if ope == 'sum':base -= s[l]
            if ope == 'prd':base //= s[l]
            l += 1
    return diff

def solution():
    N = input_int()
    A = input_ints_list()

    A.sort(reverse=True)
    max_gcd = -1
    for i in range(3):
        nota = [A[j] for j in range(len(A)) if j != i]
        gcd_nota = gcd(nota)
        max_gcd = gcd_nota if max_gcd < gcd_nota else max_gcd
    
    print(max_gcd)
	
if __name__ == '__main__':
    solution()

Submission status: Wrong Answer

Solution code:
import math


def gcd(numbers):
  res = numbers[0]
  for i in range(len(numbers)):
    res = math.gcd(res, numbers[i])
  return res


def main():
  input()
  arr = [int(x) for x in input().split()]
  M = 0
  for i in range(len(arr)):
    arr2 = arr[:i] + arr[i + 1:]
    # M = max(M, gcd(arr2))

  print(M)


if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
import math


def gcd(numbers):
  res = numbers[0]
  for i in range(len(numbers)):
    res = math.gcd(res, numbers[i])
  return res


def main():
  input()
  arr = [int(x) for x in input().split()]


if __name__ == "__main__":
  main()

Submission status: Wrong Answer

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

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

for i in range(n):
    b=list(a)
    del b[i]
    for j in range(n-1):
        gc=b[0]
        gc=gcd(gc,b[j])
    ggcd=max(gc,ggcd)

print(ggcd)

Submission status: Wrong Answer

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

    gcd_max = []
    l, r = 0, 0
    for idx in range(0, n):
        for idx_l in range(0, idx):
            if idx_l == 0:
                l = a[idx_l]
                continue
            l = gcd(l, a[idx_l])

        for idx_r in range(n-1, idx, -1):
            if idx_r == n-1:
                r = a[idx_r]
                continue
            r = gcd(r, a[idx_r])

        gcd_max.append(gcd(l, r))

    print(max(gcd_max))




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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce


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


n = int(input())
a = list(map(int, input().split()))
gcdli = []
a_copy = []
for i in range(n - 1):
    for j in a:
        a_copy.append(j)
    a_copy.pop(i)
    gcdli.append(gcd_list(a_copy))
    a_copy = []
print(max(gcdli))

Submission status: Wrong Answer

Solution code:
import fractions
n=int(input())
lis=list(map(int,input().split()))
li=[lis[0]]
l=[lis[n-1]]
for i in range (0,n-1):
  li.append(fractions.gcd(li[i],lis[i+1]))
  l.append(fractions.gcd(l[i],lis[n-i-2]))
li.insert(0,lis[0])
l.insert(0,lis[n-1])
ans_li=[]
for i in range(0,n-2):
  ans_li.append(fractions.gcd(li[i],l[n-3-i]))
ans_li.insert(0,li[n-2])
ans_li.append(l[n-2])
ans_li.sort()           
ans_li.reverse()
print(ans_li[0])

Submission status: Wrong Answer

Solution code:
import fractions
n=int(input())
lis=list(map(int,input().split()))
li=[]
l=[]
for i in range (0,n-1):
  t=fractions.gcd(lis[i],lis[i+1])
  k=fractions.gcd(lis[n-i-1],lis[n-i-2])
  li.append(t)
  l.append(k)
li.insert(0,lis[0])
l.insert(0,lis[n-1])
ans_li=[]
for i in range(0,n-2):
  ans_li.append(fractions.gcd(li[i],l[n-3-i]))
ans_li.insert(0,li[n-2])
ans_li.append(l[n-2])
ans_li.sort()           
ans_li.reverse()
print(ans_li[0])

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
"""解説
GCD

「一つを選んで好きな数字に変えられる」とあるが、今回のケースでは「その数字を消す」と同じ。

すべてのGCDを試す
"""
import copy

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

    def gcd(x, y):
        """ 最大公約数を求める """
        # x > y にしたい
        if y > x:
            x, y = y, x
        if y == 0:
            return x
        return gcd(x%y, y)

    ans = 0
    for i in range(N):
        tmp_A = copy.deepcopy(A)
        tmp_A.pop(i)
        if len(tmp_A)==1:
            tmp_ans = tmp_A[0]
        else:
            tmp_ans = gcd(tmp_A[0], tmp_A[1])
            for j in range(2, len(tmp_A)):
                tmp_ans = gcd(A[j], tmp_ans)
        ans = max(ans, tmp_ans)
    
    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int, input().split(' ')))
a = max(L)
b = min(L)
r = a%b
while r > 0:
  a = b
  b = r
  r = a%b
print(b)

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())
a = list(map(int,input().split()))
if N==2:
    print(max(a))
else:
    gcd1 = gcd(a[0],a[1])
    gcd2 = gcd(a[0],a[2])
    gcd3 = gcd(a[1],a[2])
    flag1 = flag2 = flag3 = 0
    for i in range(N):
        if a[i]%gcd1 == 0:
            flag1 += 1
        if a[i]%gcd2 == 0:
            flag2 += 1
        if a[i]%gcd3 == 0:
            flag3 += 1
    ans = []
    if flag1 == N-1:
        ans.append(gcd1)
    if flag2 == N-1:
        ans.append(gcd2)
    if flag3 == N-1:
        ans.append(gcd3)
    if not ans:
        print("1")
    else:
        print(max(ans))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

odd_list = []
even_list = []

for i in range(N):
    
    if Num_list[i] % 2 == 0:
        even_list.append(Num_list[i])
        
    else:
        odd_list.append(Num_list[i])

if len(even_list) < 2:
    even_max = 1
    even_min = 1
    
else:
    even_max = max(even_list)
    even_min = min(even_list)
    
    
if len(odd_list) < 2:
    odd_max = 1
    odd_min = 1
else:
    odd_max = max(odd_list)
    odd_min = min(odd_list)

frac_1 = gcd(even_max,even_min)
frac_2 = gcd(odd_max, odd_min)
frac_3 = gcd(even_max, odd_min)
frac_4 = gcd(odd_max, even_min)

max_frac = max([frac_1, frac_2, frac_3, frac_4])

print(max_frac)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

rs, ls = [0], [0]
for i in range(n-1):
  rs.append(gcd(rs[i], a[i]))
  ls.append(gcd(ls[i], a[-i-1]))

print(rs)
print(ls)
print(max(gcd(r, l) for r, l in zip(rs, ls[::-1])))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=[]
import fractions
b=a[0]
c=a[n-1]
for s in range(n):
 for i in range(1,s):
  b=fractions.gcd(a[i],b)
 for i in range(s+2,n-1):
  c=fractions.gcd(a[i],c)
 x.append(fractions.gcd(b,c))
print(max(x))

Submission status: Wrong Answer

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

set_a = set(a)
set_a = list(set_a)
len_set_a = len(set_a)

set_a.append(0)
set_a.insert(0, 0)
cd = []
for i, ai in enumerate(set_a[:len(set_a)]):
    common_divisor = 0
    for li in set_a[:i]:
        common_divisor = fractions.gcd(common_divisor,li)
    for ri in set_a[i+1:]:
        common_divisor = fractions.gcd(common_divisor, ri)
    cd.append(common_divisor)
print(max(cd))

Submission status: Wrong Answer

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

set_a = set(a)
set_a = list(set_a)
len_set_a = len(set_a)
if len_set_a ==1:
    print(set_a[0])
else:
    set_a.append(0)
    set_a.insert(0, 0)
    cd = []
    for i, ai in enumerate(set_a[:len(set_a)-1]):
        common_divisor = 0
        for li in set_a[:i]:
            common_divisor = fractions.gcd(common_divisor,li)
        for ri in set_a[i+1:]:
            common_divisor = fractions.gcd(common_divisor, ri)
        cd.append(common_divisor)
    print(max(cd))

Submission status: Wrong Answer

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

set_a = set(a)
set_a = list(set_a)
len_set_a = len(set_a)
if len_set_a ==1:
    print(set_a[0])
else:
    set_a.append(0)
    set_a.insert(0, 0)
    cd = []
    for i, ai in enumerate(set_a):
        common_divisor = 0
#         print(ai)
        for li in set_a[:i]:
            common_divisor = fractions.gcd(common_divisor,li)
#             print(set_a[:i])
        for ri in set_a[i+1:]:
#             print(set_a[i+1:])
            common_divisor = fractions.gcd(common_divisor, ri)
#         print(common_divisor)
        cd.append(common_divisor)
    print(max(cd))

Submission status: Wrong Answer

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

set_a = set(a)
set_a = list(set_a)
len_set_a = len(set_a)
if len_set_a ==1:
    print(set_a[0])
else:
    set_a.append(0)
    set_a.insert(0, 0)
    cd = []
    for i, ai in enumerate(set_a[1:len_set_a]):
        common_divisor = 0
        for li in set_a[:i]:
            common_divisor = fractions.gcd(common_divisor,li)
        for ri in set_a[i+1:]:
            common_divisor = fractions.gcd(common_divisor, ri)
        cd.append(common_divisor)
    print(max(cd))

Submission status: Wrong Answer

Solution code:
import fractions

integral_count = int(input())
blackboard_integers = list(map(int, input().split()))

gcd_integers = list(set(blackboard_integers))

gcd = 0
result = 1
for i in range(len(gcd_integers)):
    if blackboard_integers.count(gcd_integers[i]) >= 2:
        for n in gcd_integers:
            gcd = fractions.gcd(gcd, n)
    else:
        for n in gcd_integers[:i]:
            gcd = fractions.gcd(gcd, n)
        for n in gcd_integers[i+1:]:
            gcd = fractions.gcd(gcd, n)
    if gcd > result:
        result = gcd

print(result)

Submission status: Wrong Answer

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

set_a = set(a)
set_a = list(set_a)
len_set_a = len(set_a)
set_a.append(0)
cd = []
for i, ai in enumerate(set_a[:len_set_a]):
    common_divisor = 0
    for li in set_a[:i]:
        common_divisor = fractions.gcd(common_divisor,li)
    for ri in set_a[i+1:]:
        common_divisor = fractions.gcd(common_divisor, ri)
    cd.append(common_divisor)
print(max(cd))

Submission status: Wrong Answer

Solution code:
import fractions

integral_count = int(input())
blackboard_integers = list(map(int, input().split()))

gcd_integers = list(set(blackboard_integers))

gcd = 0
result = 1
for i in range(len(gcd_integers)):
    if blackboard_integers.count(gcd_integers[i]) == 1:
        for n in gcd_integers[:i]:
            gcd = fractions.gcd(gcd, n)
        for n in gcd_integers[i+1:]:
            gcd = fractions.gcd(gcd, n)
    else:
        for n in gcd_integers:
            gcd = fractions.gcd(gcd, n)
    if gcd > result:
        result = gcd

print(result)

Submission status: Wrong Answer

Solution code:
import fractions

integral_count = int(input())
blackboard_integers = list(map(int, input().split()))

gcd_integers = list(set(blackboard_integers))

gcd = 0
result = 1
for i in range(len(gcd_integers)):
    for n in gcd_integers[:i]:
        gcd = fractions.gcd(gcd, n)
    for n in gcd_integers[i+1:]:
        gcd = fractions.gcd(gcd, n)
    if gcd > result:
        result = gcd

print(result)

Submission status: Wrong Answer

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

set_a = set(a)
if len(set_a)<=2:
    print(max(set_a))
else:
    set_a = list(set_a)
    kou1 = fractions.gcd(set_a[0],set_a[1])
    kou2 = fractions.gcd(set_a[1],set_a[2])
    kou3 = fractions.gcd(set_a[0],set_a[2])
    print(max(kou1,kou2,kou3))

Submission status: Wrong Answer

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

# val_max = max(a)
# val_min = max(a)
# kou1 = math.gcd(a,b)

# index_min = a.index()
# a_new = 
if len(a)==2:
    print(max(a))
else:
    kou1 = fractions.gcd(a[0],a[1])
    kou2 = fractions.gcd(a[1],a[2])
    kou3 = fractions.gcd(a[0],a[2])
    print(max(kou1,kou2,kou3))

Submission status: Wrong Answer

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

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

max_gcd = 0

for i in range(n):
    for j in range(n):
        if j == i:
            continue
        else:
            a_gcd = gcd(aa[i], aa[j])
            if max_gcd < a_gcd:
                max_gcd = a_gcd

print(max_gcd)

Submission status: Wrong Answer

Solution code:
import sys
from functools import *
from itertools import *

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

def gcd(a, b):
    a , b = (a, b) if a > b else (b, a)
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b
        pass
    return b

Bs = sorted(As)
Bs_len = len(Bs)

if Bs_len == 1:
    print(Bs[0])
    sys.exit(0)
    pass

if Bs_len == 2:
    print(max(*Bs))
    sys.exit(0)
    pass

x = gcd(Bs[0], Bs[1])
y = gcd(Bs[1], Bs[2])
z = gcd(Bs[2], Bs[0])
w = max(x, y, z)
print(reduce(gcd, chain([w], islice(Bs, 3, None))))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

N = int(input())
a_list = [int(x) for x in input().split()]

if N!=2:
    buf = gcd(a_list[0], a_list[1])
    for i in range(2, N):
        buf = gcd(buf, a_list[i])
    Max = buf
    for i in range(N):
        b_list = a_list[:i]+a_list[i+1:]
        buf = gcd(b_list[0], b_list[1])
        for i in range(2, N-1):
            buf = gcd(buf, a_list[i])
        if buf > Max:
            Max = buf
    print(Max)
else:
    print(max(a_list[0], a_list[1]))

Submission status: Wrong Answer

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

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

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

max = 1

for i in range(N):
    j = i+1
    while j < N:
        r = gcd(A[i], A[j])
#        print("i:{}, j:{}, r:{}".format(i, j, r))
        if max < r:
            max = r
        j = j + 1

print(max)