TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
import sys

N=input()
if isinstance(N,int)==0 or N<1 or N>20 :
    print("error")
    sys.exit()

N=int(N)

V=list(map(int,input().strip().split()))
C=list(map(int,input().strip().split()))

for i in range(N):
    if C[i]<1 or C[i]>20 or V[i]<1 or v[i]>20:
        print("error")
        sys.exit()

diff=0
max_profit=0



for i in range(N):
    # print(V[i],type(V[i]),C[i],type(C[i]))                                                         
    diff=V[i]-C[i]
    if diff >=0 :
        max_profit=max_profit+diff

print(max_profit)


import sys

N=int(input())
if N<1 or N>20 :
    print("error")
    sys.exit()

V=list(map(int,input().strip().split()))
C=list(map(int,input().strip().split()))
# print(V[0],V[1],V[2])                                                                              

for i in range(N):
    if C[i]<1 or C[i]>20 or V[i]<1 or v[i]>20:
        print("error")
        sys.exit()

    # try:                                                                                           
    #     inp=dic[input('[Y]es/[N]o? >> ').lower()]                                                  
    #     break                                                                                      
    # except:                                                                                        
    

diff=0
max_profit=0



for i in range(N):
    # print(V[i],type(V[i]),C[i],type(C[i]))                                                         
    diff=V[i]-C[i]
    if diff >=0 :
        max_profit=max_profit+diff

print(max_profit)


import sys

N=input()
if N.isdecimal() == 0 or int(N)<1 or int(N)>20 :
    print("error")
    sys.exit()

N=int(N)

V=list(map(int,input().strip().split()))
C=list(map(int,input().strip().split()))
# print(V[0],V[1],V[2])                                                                              

for i in range(N):
    if C[i]<1 or C[i]>50 or V[i]<1 or V[i]>50:
        print("error")
        sys.exit()

diff=0
max_profit=0



for i in range(N):
    # print(V[i],type(V[i]),C[i],type(C[i]))                                                         
    diff=V[i]-C[i]
    if diff >=0 :
        max_profit=max_profit+diff

print(max_profit)



Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
n=input()
v=list(map(int, input().split()))
c=list(map(int, input().split()))
t=[i-j,if i-j>0 else 0 for i,j in zip(v,c)]
print(sum(t))

n=input()
v=list(map(int, input().split()))
c=list(map(int, input().split()))
for i in range(n)
t[i]=v[i]-c[i]
a=0
for i in range(n)
if t[i]>0 :
a+=t[i]
print(a)

import nmpy as np
n=input()
v=np.array(map(int, input().split()))
c=np.array(map(int, input().split()))
t=v-c
a=0
for i in range(n)
if t[i]>0 :
a+=t[i]
print(a)


import nmpy as np
n=input()
v=np.array(map(int, input().split()))
c=np.array(map(int, input().split()))
t=v-c
a=0
for i in range(n)
if t[i]>0 :
a+=t[i]
print(a)


n=input()
v=list(map(int, input().split()))
c=list(map(int, input().split()))
t=v-c
a=0
for i in range(n)
if t[i]>0 :
a+=t[i]
print(a)

n=input()
v=list(map(int, input().split()))
c=list(map(int, input().split()))
t=[i-j if i-j>0 else 0 for i,j in zip(v,c)]
print(sum(t))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

diff = [v-c if (v-c > 0) else 0 for v, c in zip(V, C)]
print(max(diff))

N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

diff = [v-c if (v-c > 0) else 0 for v, c in zip(V, C)]
print(sum(diff))

Verdicts: Wrong Answer

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
N = int(input().split())
V = list(map(int,input().split()))
C = list(map(int,input().split()))

count = 0
for i in range(N):
    if V[i] > C[i]:
        count += V[i] - C[i]

print (count)

N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))

count = 0
for i in range(N):
    if V[i] > C[i]:
        count += V[i] - C[i]

print (count)

Verdicts: Runtime Error

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
N = int(input())
V = [int(input()) for i in range(N)]
C = [int(input()) for i in range(N)]
_ = 0
for j in range(N):
  if V[j] > C[j]:
    _ += V[j] - C[j]
print(_)

N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))
_ = 0
for j in range(N):
  if V[j] > C[j]:
    _ += V[j] - C[j]
print(_)

Verdicts: Runtime Error

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
n = int(input())
vs = input().split(" ")
cs = input().split(" ")

xy = 0
for i in range(n):
  v = vs[i]
  c = cs[i]
  if v>c:
    xy += v-c

print(xy)

n = int(input())
vs = input().split(" ")
cs = input().split(" ")
 
xy = 0
for i in range(n):
  v = int(vs[i])
  c = int(cs[i])
  if v>c:
    xy += v-c
 
print(xy)

Verdicts: Runtime Error

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
import numpy as np

n = int(input())
v = np.array(list(map(int, input().split())))
c = np.array(list(map(int, input().split())))
p = v-c
for i in p:
    if i>0:
        ans+=i

print(ans)


n=int(input())
V=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=0
for v,c in zip(V,C):
    diff=v-c
    if 0<diff:
        ans+=diff
print(ans)

Verdicts: Runtime Error

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):

n = input()
n = int(n)

total = 0

lst_a = input().split()
lst_b = input().split()

for i in range(0, n ,1):
    a = lst_a[0]
    b = lst_b[0]
    a = int(a)
    b = int(b)
    if a > b:
        total += (a - b)

print(total)

n = input()
n = int(n)

total = 0

lst_a = input().split()
lst_b = input().split()

for i in range(n):
    a = int(lst_a[i])
    b = int(lst_b[i])
    if a > b:
        total += (a - b)

print(total)

Verdicts: Wrong Answer

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
n= int(input())

v= list(map(int, input().split())) 
c= list(map(int, input().split()))
r=[]

for i in range(n):
  r.append(v[i]-c[i]) 

r.append(0)
r.sort(reverse=True)
print(r)

ret= sum([j for j in r if j>=0])
print(ret)

n= int(input())

v= list(map(int, input().split())) 
c= list(map(int, input().split()))
r=[]

for i in range(n):
  r.append(v[i]-c[i]) 

r.append(0)
r.sort(reverse=True)

ret= sum([j for j in r if j>=0])
print(ret)

Verdicts: Wrong Answer

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
import itertools
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

M = [[V[i], C[i]]for i in range(N)]
print(M)

com_M = list(itertools.combinations(M, 2))
m_M = []
for i in range(N):
    X = com_M[i][0][0] + com_M[i][1][0]
    Y = com_M[i][0][1] + com_M[i][1][1]
    #print(X)
    
    m_M.append(X - Y)

print(max(m_M))


import itertools
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

M = [[V[i], C[i]]for i in range(N)]
#print(M)


tx = 0
R = 0
for i in range(N):
    tx = V[i] - C[i]
    if (tx > 0):
        R += tx

print(R)

Verdicts: Runtime Error

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
n = int(input())
vs = list(map(int, input().split()))
cs = list(map(int, input().split()))
ans = 0
for i in range(len(vs)):
  if vs >= cs:
    ans += (vs[i]-cs[i])
print(ans)

n = int(input())
vs = list(map(int, input().split()))
cs = list(map(int, input().split()))
ans = 0
for i in range(len(vs)):
  if vs[i] >= cs[i]:
    ans += (vs[i]-cs[i])
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):

i = list(map(int, input().split()))
s = list(map(int, input().split()))
t = list(map(int, input().split()))
z=0
for q in range(0,i[0]):
	if(s[q]-t[0]>0):
      z+s[q]
    else:
      
print(z)

s=list(map(int,input().split()))
t=list(map(int,input().split()))
u=list(map(int,input().split()))
vw=[]
for i in range(s[0]):
  if t[i]-u[i]>0:
    vw.append(t[i]-u[i])
print(sum(vw))

Verdicts: Runtime Error

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
def solve():
    N = int(input())
    V = list(map(int,input().split()))
    C = list(map(int,input().split()))
    cnt=0
    for i in range(len(V)):
        if V < C:
            pass
        else:
            cnt += V(i)-C(i)
    print(cnt)


solve()


def solve():
    N = int(input())
    V = list(map(int,input().split()))
    C = list(map(int,input().split()))
    cnt=0
    for i in range(len(V)):
        if V[i] < C[i]:
            pass
        else:
            cnt += V[i]-C[i]
    print(cnt)


solve()


Verdicts: Runtime Error

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
n = int(input())
V = [int(v) for v in input().split]
C = [int(c) for c in input().split]

G = [v - c for v, c in zip(V, C)]

s = 0
for g in G:
    if g > 0:
        s += g

print(s)

n = int(input())
V = [int(v) for v in input().split()]
C = [int(c) for c in input().split()]

G = [v - c for v, c in zip(V, C)]

s = 0
for g in G:
    if g > 0:
        s += g

print(s)

Verdicts: Runtime Error

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))

for i in range(N):
    if V[i] <= C[i]:
        continue
    Max = Max + V[i] - C[i]
print(Max)

N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))
Max = 0

for i in range(N):
    if V[i] <= C[i]:
        continue
    Max = Max + V[i] - C[i]
print(Max)

Verdicts: Runtime Error

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
N = input("宝石の数")
V = list(map(int,input().split())) #Value
Y = list(map(int,input().split())) 
goukei = 0
for v, y in zip(V,Y): 
    if(y-v >= 0):
        goukei +=0
    else:
        goukei += v-y
print(goukei)        
    

N = int(input())
sum_value=0
V =  list(map(int,input().split()))
C =  list(map(int,input().split()))

for v,c in zip(V,C):
    if (v>c):
        sum_value +=v-c
print(sum_value)


Verdicts: Wrong Answer

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):

n = int(input())

v = input().split()
c = input().split()
sum=0

print(v,c)
for i in range(0,n):
    s = int(v[i])-int(c[i]) 
    print(s)
    if s >=0:
        sum += s
print(sum)


n = int(input())

v = input().split()
c = input().split()
sum=0

for i in range(0,n):
    s = int(v[i])-int(c[i]) 
    if s >=0:
        sum += s
print(sum)

Verdicts: Wrong Answer

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
import numpy as np

n=int(input())
v = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

v = np.array(v)
c= np.array(c)
hikizan = v-c

x = np.zeros((3,n))
x[1] = v
x[2] = c
x[0] = hikizan

a = x[: , x[0,:].argsort()]

kotae = 0

for i in range(0,n):
    if a[0,i] > 0:
        kotae += a[0,i]
        
print(kotae)

import numpy as np

n=int(input())
v = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

v = np.array(v)
c= np.array(c)
hikizan = v-c

x = np.zeros((3,n))
x[1] = v
x[2] = c
x[0] = hikizan

kotae = 0

for i in range(0,n):
    if x[0,i] > 0:
        kotae += x[0,i]
        
print(int(kotae))

Verdicts: Wrong Answer

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
N, K = map(int, input().split())

ans = 0

for i in range(N):
    t = 0
    p = i + 1
    while K > p:
        t += 1
        p *= 2
    ans += (0.5 ** t) / N
print(ans)

N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0

for i in range(N):
    d = V[i] - C[i]
    if d > 0:
        ans += d

print(ans)

Verdicts: Runtime Error

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
n=int(input())
v=[]
c=[]
x=[]
for i in range(n):
  v[i]=int(input())
for i in range(n):
  c[i]=int(input())
  x[i]=v[i]-c[i]

ans=0
while x[i]>0:
  ans+=x[i]
  
print(ans)

n=int(input())
v=list(map(int, input().split()))
c=list(map(int, input().split()))
x=[]
for i in range(n):
  if v[i]-c[i]>0:
    x.append(v[i]-c[i])

print(sum(x))

Verdicts: Runtime Error

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
import numpy as np

N = int(input())
VS = input().split()
CS = input().split()

V = [int(v) for v in VS]
C = [int(v) for v in CS]

R = []


for i in range(N-1):
    R.append(V[i]/C[i])

RR = reversed(R)
RA = np.argsort(RR)

best = 0

Vsum=0
Csum=0

for r in RA:
    Vsum += V[r]
    Csum += C[r]

    if (Vsum-Csum) >= best:
        best = Vsum-Csum

print(best)


import numpy as np

N = int(input())
VS = input().split()
CS = input().split()

V = [int(v) for v in VS]
C = [int(v) for v in CS]

R = [N]


for i in range(N-1):
    R[i] = V[i]/C[i]

RA = np.argsort(-R)

best = 0

Vsum=0
Csum=0

for r in RA:
    Vsum += V[i]
    Csum += C[i]

    if (Vsum-Csum) >= best:
        best = Vsum-Csum

print(best)


n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
    if v[i] - c[i] > 0:
        ans += v[i] - c[i]
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

m = a[0]
k = b[0]
for i in range(n):
    if a[i] >b[i] :
        ans = a[i]-b[i]
print(ans)

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
m = a[0]
k = b[0]
for i in range(n):
    if a[i] >b[i] :
        ans += a[i]-b[i]
print(ans)

Verdicts: Runtime Error

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))
S = 0
for i in range(N):
    D = V[i] - C[i]
    if D >0:
    S = S + D
    
print(S)



N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))
S = 0
for i in range(N):
    D = V[i] - C[i]
    if D >0:
        S = S + D
    
print(S)



Verdicts: Runtime Error

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
n= int(input())
v,c= list(map(int, input().split()))

ans=0
for i in range(n):
    if v[i] > c[i]:
        ans+=v[i]-c[i]
print(ans)


n= int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))
ans=0
for i in range(n):
    if v[i] > c[i]:
        ans+=v[i]-c[i]
print(ans)


Verdicts: Runtime Error

Accepted
Problem: There are N gems. The value of the i-th gem is V_i.  You will choose some of these gems, possibly all or none, and get them.  However, you need to pay a cost of C_i to get the i-th gem.  Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid.  Find the maximum possible value of X-Y.

Submission attempts (in order):
N = int(input().split())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
P = []
for i in range(N):
    p = V[i]-C[i]
    if p >0:
    	P.append(p)

print(sum(P))

N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
P = []
for i in range(N):
    p = V[i]-C[i]
    if p >0:
    	P.append(p)

print(sum(P))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from functools import reduce


def gcd(v1, v2):
    v3 = v1 % v2
    if v3 == 0:
        return v2
    return gcd(v2, v3)


def main():
    N = int(input())
    A = [int(v) for v in input().split()]

    max_gcd = max(reduce(gcd, A[1:]), reduce(gcd, A[:N-1]))

    for i in range(1, N - 1):
        v1 = reduce(gcd, A[:i])
        v2 = reduce(gcd, A[i + 1:])

        max_gcd = max(max_gcd, gcd(v1, v2))

    print(reduce(gcd, A))

    print(max_gcd)


if __name__ == "__main__":
    main()


from functools import reduce


def gcd(v1, v2):
    v3 = v1 % v2
    if v3 == 0:
        return v2
    return gcd(v2, v3)


def main():
    N = int(input())
    A = [int(v) for v in input().split()]

    max_gcd = max(reduce(gcd, A[1:]), reduce(gcd, A[:N-1]))

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

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

    # print(left)
    # print(right)

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

    print(max_gcd)


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

inf = int(2e9)

m = inf
check = 0
for i in range(N):
    check1 = gcd(A[0], A[i])
    if check1 < m:
        m = check1
        check = i


check2 = A[1]
for i in range(0,N):
    check2 = gcd(check2, A[i])

ans = check2


if check != 0:
    check3 = A[0]
    for i in range(N):
        if i == check:
            continue
        check3 = gcd(check3, A[i])
    ans = max(check2, check3)

print(ans)

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

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

A.sort()

inf = int(2e9)

m = inf
check = 0
for i in range(N):
    check1 = gcd(A[0], A[i])
    if check1 < m:
        m = check1
        check = i


check2 = A[1]
for i in range(1,N):
    check2 = gcd(check2, A[i])

ans = check2


if check != 0:
    check3 = A[0]
    for i in range(N):
        if i == check:
            continue
        check3 = gcd(check3, A[i])
    ans = max(check2, check3)

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import fractions
n=int(input())
a=list(map(int,input().split()))
x=100000
X=0
a.sort()
flag=False

for i in range(0,n-1):
  if fractions.gcd(a[i],a[i+1])==1 and fractions.gcd(a[i+1],a[i+2])==1:
    a.pop(i+1)
    flag=True
    break
if flag!=True:
  for i in range(n-1):
    if x>=fractions.gcd(a[i],a[i+1]):
      x=fractions.gcd(a[i],a[i+1])
      X=a[i]
  if X in a:
    a.remove(X)

ans = a[0]
for i in range(1,n-1):
  ans = fractions.gcd(ans, a[i])
print(ans)

import math
#n=int(input())
#a=list(map(int,input().split()))
import random
n=random.randrange(2,1000)
a=[random.randrange(2,1000) for i in range(n)]

ra=list(reversed(a))

left=[]
right=[]
right.append(ra[0])
left.append(a[0])

if n>2:
  k=math.gcd(a[0],a[1])
  left.append(k)
  for i in range(2,n-1):
    k=math.gcd(k,a[i])
    left.append(k)

  k=math.gcd(ra[0],ra[1])
  right.append(k)
  for i in range(2,n-1):
    k=math.gcd(k,ra[i])
    right.append(k)

  ans=[right[-1]]
  for i in range(1,n-1):
    ans.append(math.gcd(left[i-1],right[len(right)-i-1]))
  ans.append(left[-1])
  print(max(ans))
else:
  print(max(ra[0],a[0]))

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

ra=list(reversed(a))

left=[]
right=[]
right.append(ra[0])
left.append(a[0])

if n>2:
  import math
  left.append(math.gcd(a[0],a[1]))
  for i in range(2,n-1):
    k=math.gcd(k,a[i])
    left.append(k)

  right.append(math.gcd(ra[0],ra[1]))
  for i in range(2,n-1):
    k=math.gcd(k,ra[i])
    right.append(k)

  print(left)
  print(right)
  ans=[right[-1]]
  for i in range(1,n-1):
    ans.append(math.gcd(left[i-1],right[len(left)-i-1]))
  ans.append(left[-1])
  print(max(ans))
else:
  print(max(ra[0],a[0]))

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

ra=list(reversed(a))

left=[]
right=[]
right.append(ra[0])
left.append(a[0])

if n>2:
  k=math.gcd(a[0],a[1])
  left.append(k)
  for i in range(2,n-1):
    k=math.gcd(k,a[i])
    left.append(k)

  k=math.gcd(ra[0],ra[1])
  right.append(k)
  for i in range(2,n-1):
    k=math.gcd(k,ra[i])
    right.append(k)

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

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))

import fraction
from functools import reduce

ans = 0
for i in range(n):
  x = a[:i] + a[i+1:]
  ans = max(ans, reduce(fraction.gcd, x))
  
print(ans)

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

import fractions
from functools import reduce

ans = 0
for i in range(n):
  x = a[:i] + a[i+1:]
  ans = max(ans, reduce(fractions.gcd, x))
  
print(ans)

n = int(input())
a = list(map(int, input().split()))
end = sorted(a)[1]

for i in range(end+1, 0, -1):
  x = 0
  for j in a:
    if j % i != 0:
      x += 1
    if x >= 2:
      break
  if x <= 1:
    print(i)
    break

Verdicts: Runtime Error

Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
  if a*b==0:
    return a if b==0 else b
  else:
    while b:
      a,b=b,a%b
  return a

B=[0]*(n+5)
C=[0]*(n+5)

for i in range(n-2):
  B[i+1]=gcd(B[i],A[i])
  C[i+1]=gcd(C[i],A[n-i-1])
po=0
for i in range(n):
  po=max(po,gcd(B[i],C[n-1-i]))
print(po)


n=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
  if a*b==0:
    return a if b==0 else b
  else:
    while b:
      a,b=b,a%b
  return a

B=[]
B[0]=0
C=[]
C[0]=0
for i in range(n-1):
  B[i+1]=gcd(B[i],A[i])
  C[i+1]=gcd(C[i],A[n-i-1])
po=0
for i in range(n):
  po=max(po,B[i]*C[n-1-i])
print(po)


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

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

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

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

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from functools import reduce
n = int(input())
a = list(map(int, input().split()))

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

def gcd_list(ns):
    return reduce(gcd, ns)

ans = 0
l=len(a)
for i in range(l):
    b = a[0:i] + a[i+1:l]
    ans = max(ans, gcd_list(b))
    print(b)

print(ans)



from functools import reduce


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


def gcd_list(nums):
    return reduce(gcd, nums)


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


l = [0 for _ in range(n)]
l[0] = 0
for i in range(1, n):
    l[i] = gcd(l[i-1], a[i-1])
# print(l)


r = [0 for _ in range(n)]
r[n-1] = 0
for i in reversed(range(n-1)):
    r[i] = gcd(r[i+1], a[i+1])
# print(r)


ans = 0
for i in range(n):
    ans = max(ans, gcd(l[i],r[i]))


print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def gcd(x, y):
    while y!=0:
        x, y = y, x % y 
    return x

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

if n == 2:
    print(max(a))

if n>=3:
    l = [-1] * n
    r = [-1] * n
    l[0] = a[0]  
    r[-1] = a[-1] 
# print(l)
# print(r)

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

        
        # print("r",r)

        ans = max(r[1], l[-2]) 
        

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


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

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

if n == 2:
    print(max(a))

# if n>=3:
l = [-1] * n
r = [-1] * n
l[0] = a[0]  
r[-1] = a[-1] 
print(l)
print(r)

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

print("l",l) 
print("r",r)

ans = max(r[1], l[-2]) 


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

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

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

if n == 2:
    print(max(a))

elif n>=3:
    l = [-1] * n
    r = [-1] * n
    l[0] = a[0]  
    r[-1] = a[-1] 
# print(l)
# print(r)

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

        
        # print("r",r)

    ans = max(r[1], l[-2]) 
        

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

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from fractions import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
result = 1
for n in range(N):
    X = A[:n] + A[n + 1:]
    result = max(result, reduce(gcd, X))
print(result)


import math
N = int(input())
A = sorted(list(map(int, input().split())))
if N == 2:
    print(max(A))
    exit()
result = []
num = 0
for a in A[1:]:
    if a % A[0] != 0:
        num += 1
        if num == 2:
            break
else:
    result.append(A[0])
for n in range(2, int(math.sqrt(A[0])) + 1):
    if A[0] % n != 0:
        continue
    num = 0
    x = A[0] // n
    for a in A[1:]:
        if a % x != 0:
            num += 1
            if num == 2:
                break
    else:
        result.append(x)
    num = 0
    for a in A[1:]:
        if a % n != 0:
            num += 1
            if num == 2:
                break
    else:
        result.append(n)
num = 0
B = A[0:1] + A[2:]
for a in B:
    if a % A[1] != 0:
        num += 1
        if num == 2:
            break
else:
    result.append(A[1])
for n in range(2, int(math.sqrt(A[1])) + 1):
    if A[1] % n != 0:
        continue
    num = 0
    x = A[1] // n
    for a in B:
        if a % x != 0:
            num += 1
            if num == 2:
                break
    else:
        result.append(x)
    num = 0
    for a in B:
        if a % n != 0:
            num += 1
            if num == 2:
                break
    else:
        result.append(n)
if len(result) != 0:
    print(max(result))
else:
    print(1)


Verdicts: Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
### C

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

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

tmp = []
for i in range(1, N):
    tmp.append(gcd(A[0], A[i]))
    if i+1 < N:
        tmp.append(gcd(A[2], A[i+1]))

print(max(tmp))

### C

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

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

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

for i in range(N):
    left[i+1] = gcd(A[i], left[i])
for i in reversed(range(N)):
    right[i] = gcd(A[i], right[i+1])
    
res = 0
for i in range(N):
    l = left[i]
    r = right[i+1]
    res = max(gcd(l, r), res)

print(res)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import fractions
from functools import reduce

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

if __name__ == '__main__':
  n = int(input())
  a_lst = [int(elem) for elem in input().split()]  
  res_lst = []
  for i, a in enumerate(a_lst):
    new_lst = list(a_lst)
    new_lst.pop(i)
    res = gcd_list(new_lst)
    res_lst.append(res)
  print(max(res_lst))

import fractions
from functools import reduce

def gcd_list(numbers):
  if numbers != []:
    return reduce(fractions.gcd, numbers)
  else:
    return 0

if __name__ == '__main__':
  n = int(input())
  a_lst = [int(elem) for elem in input().split()] 
  left_gcd = [0] * n
  right_gcd = [0] * n
  ans = 0
  for i in range(0,n):
    left_gcd[i] = gcd_list(a_lst[:i])
    right_gcd[i] = gcd_list(a_lst[i+1:])
  print(left_gcd, right_gcd)
  for i in range(n):
    ans = max(ans, fractions.gcd(left_gcd[i],right_gcd[i]))
  print(ans)

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

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

left_gcd = [0]*(n+1)
right_gcd = [0]*(n+1)
left_gcd[1] = a[0]
right_gcd[1] = a[-1]

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

ans = right_gcd[n-1]
for i in range(n):
    ans = max(ans,gcd(left_gcd[i],right_gcd[n-1-i]))
print(ans)


Verdicts: Time Limit Exceeded

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def euclid(a, b):
    mod = a % b
    if mod != 0:
        b = euclid(b, mod)
    return b
N = int(input())
A = [int(a) for a in input().split()]
gcd_lis = []
inv_gcd_lis = []
gcd = A[0]
for a in A[1:]:
    gcd = euclid(gcd, a)
    gcd_lis.append(gcd)
gcd = A[-1]
for a in A[-2::-1]:
    gcd = euclid(gcd, a)
    inv_gcd_lis.append(gcd)
print(gcd_lis)
print(inv_gcd_lis[::-1])

def euclid(a, b):
    mod = a % b
    if mod != 0:
        b = euclid(b, mod)
    return b
N = int(input())
A = [int(a) for a in input().split()]
gcd_lis = [A[0]]
gcd = A[0]
for a in A[1:]:
    gcd = euclid(gcd, a)
    gcd_lis.append(gcd)
inv_gcd_lis = [A[-1]]
gcd = A[-1]
for a in A[::-1][1:]:
    gcd = euclid(gcd, a)
    inv_gcd_lis.append(gcd)
inv_gcd_lis = inv_gcd_lis[::-1]
maximam = 0
for index in range(N):
    if index == 0:
        gcd = inv_gcd_lis[1]
    elif index == N - 1:
        gcd = gcd_lis[N-2]
    else:
        gcd = euclid(gcd_lis[index - 1], inv_gcd_lis[index + 1])
    maximam = max(gcd, maximam)
print(maximam)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from functools import reduce
import copy

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

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

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

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

print(l)
print(r)

ans = 0
for i in range(n):
    lr = gcd(l[i], r[i])
    print (lr)
    ans = max(ans, lr)

print(ans)


from functools import reduce
import copy

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

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

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

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

print(l)
print(r)

ans = 0
for i in range(n):
    lr = gcd(l[i], r[i])
    print (lr)
    ans = max(ans, lr)

print(ans)


from functools import reduce
import copy

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

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

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

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

ans = 0
for i in range(n):
    lr = gcd(l[i], r[i])
    ans = max(ans, lr)

print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 27 20:57:32 2019

@author: Yamazaki Kenichi
"""

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

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

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

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

@author: Yamazaki Kenichi
"""

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

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

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



# -*- coding: utf-8 -*-
"""
Created on Sun Apr 28 15:46:33 2019

@author: Yamazaki Kenichi
"""

N = int(input())
A = list(map(int,input().split()))
 
def eg(x,y):
    if y == 0:
        return x
    x, y = y, x%y
    return eg(x,y)

L, R = [0 for i in range(N)],[0 for i in range(N)]
L[0], R[N-1] = A[0], A[N-1]
for i in range(1,N):
    L[i] = eg(L[i-1], A[i])
    R[N-1-i] = eg(R[N-i], A[N-1-i])
ans = [0 for i in range(N)]
for i in range(N):
    if i == 0:
        ans[i] = R[i+1]
    elif i == N-1:
        ans[i] = L[i-1]
    else:
        ans[i] = eg(L[i-1],R[i+1])

print(max(ans))
    


    

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def m(a, b):
    if a > b:
        a, b = b, a
    while b % a:
        a, b = b % a, a
    return a


N = int(input())
A = list(map(int, input().split()))
AF = [1] * (N - 1)
AB = [1] * (N - 1)

AF[0] = A[0]
AB[0] = A[-1]
if N == 2:
    print(max(A))
else:
    for i in range(1, N - 1):
        AF[i] = m(A[i - 1], A[i])
        AB[i] = m(A[i - 1], A[- (i + 1)])

    L = max(AF[-1], AB[-1], max([m(AF[i], AB[N - 3 - i]) for i in range(N - 2)]))

    print(L)

def m(a, b):
    if a > b:
        a, b = b, a
    while b % a:
        a, b = b % a, a
    return a


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

if N == 2:
    print(max(A))
else:
    AF = [1] * (N - 1)
    AB = [1] * (N - 1)

    AF[0] = A[0]
    AB[0] = A[-1]

    for i in range(1, N - 1):
        AF[i] = m(AF[i - 1], A[i])
        AB[i] = m(AB[i - 1], A[- (i + 1)])
    L = max(AF[-1], AB[-1], max([m(AF[i], AB[N - 3 - i]) for i in range(N - 2)]))

    print(L)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = []
for x in input().split():
    a.append(int(x))

ans = []

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

def gcd_list(numbers):
    element = gcd(numbers[0], numbers[1])
    if len(numberes)==2:
        return element
    else:
        for i in range(2, len(numbers)):
            element=gcd(element, numbers[i])
        return element

if n == 2:
    print(max(a))
else:
    for i in range(n):
        c = a.copy()
        c.remove(a[i])
        ans.append(gcd_list(c))

    print(max(ans))


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

N=int(input())
A=[int(i) for i in 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])
Z=[gcd(X[i],Y[i]) for i in range(N)]
print(max(Z))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import copy
import fractions
from functools import reduce
n = int(input())
a = list(map(int, input().split()))
max_gcd = 1
for i in range(0, n-1):
  _a = copy.copy(a)
  _a.pop(i)
  _gcd = reduce(fractions.gcd, _a)
  if _gcd > max_gcd:
    max_gcd = _gcd
print(max_gcd)

import fractions

def get_m(_a, i):
  def _gcd(a, b):
    if a == 0:
      return b
    elif b == 0:
      return a
    else:
      return fractions.gcd(a, b)

  l = 0
  for t in range(0, i):
    l = _gcd(l, _a[t])
  r = 0
  for t in range(n-1, i, -1):
    r = _gcd(r, _a[t]) 
  return _gcd(l, r)

n = int(input())
a = list(map(int, input().split()))
gcds = []
for i in range(0, n-1):
  gcds.append(get_m(a, i))
print(max(gcds))

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

n = int(input())
a = list(map(int, input().split()))
l = [0 for i in range(n)]
r = l[:]

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

Verdicts: Wrong Answer

Wrong Answer

Accepted