ZhenlongDai/ACPR huggingface dataset:
Problem: p03379
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a = input()
a = int(a)
b = input()
b= b.rstrip().split(" ")


for j in range(len(b)):
    b1=[]
    for i in range(len(b)):
        if j ==i:
            i +=1
        else:
            b1.append(int(b[i]))
            i +=1
    print(b1[int(a/2)-1])
        
    j+=1

Failing test case input:
4
2 4 4 3

Expected output:
4
3
3
4

Actual output:
4
4
4
4


Fixed submission (verdict: Accepted):
a = input()
a = int(a)
b = input()
b= b.rstrip().split(" ")

bi =[]
for i in range(len(b)):
    bi.append(int(b[i]))
    i+=1
    

bs =sorted(bi)

for j in range(int(a)):
    if bi[j]>=bs[int(len(bs)/2)]:
        print(bs[int(len(bs)/2-1)])
        j+=1
    else:
        print(bs[int(len(bs)/2)])
        j+=1

Problem: p03379
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
N = int(input())
x = list(map(int, (input()).split()))

hoge = math.floor(N/2)

x.sort()
A = x[hoge]
B = x[hoge-1]

for i in range(hoge):
	print(A)
for i in range(hoge):
	print(B)

Failing test case input:
4
2 4 4 3

Expected output:
4
3
3
4

Actual output:
4
4
3
3


Fixed submission (verdict: Accepted):
import math
N = int(input())
x = list(map(int, (input()).split()))

hoge = math.floor(N/2)

y = sorted(x)
A = y[hoge]
B = y[hoge-1]

for i in range(N):
	if A <= x[i]:
		print(B)
	else:
		print(A)

Problem: p03379
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
x = list(map(str, input().split()))
sx = sorted(x)

mid1 = sx[int(n/2)]
mid2 = sx[int(n/2)-1]

for i in x:
    if i <= mid1:
        print(mid1)
    else:
        print(mid2)


Failing test case input:
4
2 4 4 3

Expected output:
4
3
3
4

Actual output:
4
4
4
4


Fixed submission (verdict: Accepted):
n = int(input())
x = list(map(int, input().split()))
sx = sorted(x)

min_mid = sx[int(n/2-1)]
max_mid = sx[int(n/2)]

for i in x:
    if i <= min_mid:    
        print(max_mid)
    else:               
        print(min_mid)

Problem: p03379
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
arr = list(map(int, input().split()))
arr.sort()

for i in range(N):
    if i < N/2:
        print(arr[int(N/2)])
    else:
        print(arr[int(N/2)-1])

Failing test case input:
4
2 4 4 3

Expected output:
4
3
3
4

Actual output:
4
4
3
3


Fixed submission (verdict: Accepted):
N = int(input())
arr = list(map(int, input().split()))
X = arr.copy()
arr.sort()

for i in range(N):
    if X[i] < arr[int(N/2)]:
        print(arr[int(N/2)])
    else:
        print(arr[int(N/2)-1])

Problem: p03379
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))

AB = sorted(A)
C = int(N/2)
for i in range(N):
    if AB[i] <= AB[C]:
        print(AB[C])
    else:
        print(AB[C-1])

Failing test case input:
4
2 4 4 3

Expected output:
4
3
3
4

Actual output:
4
4
4
4


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))

AB = sorted(A)
C = int(N
for i in range(N):
    if A[i] <= AB[C-1]:
        print(AB[C])
    else:
        print(AB[C-1])
Problem: p03379
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
index=int(n/2)-1
x=list(map(int,input().split()))
y=x
y.sort()
med=y[index]
for i in range(n):
    if x[i]>=med:
        print(med)
    else:
        print(y[index+1])    
    
    


Failing test case input:
4
2 4 4 3

Expected output:
4
3
3
4

Actual output:
4
3
3
3


Fixed submission (verdict: Accepted):
n=int(input())
index=int(n/2)-1
x=list(map(int,input().split()))
y=[]
for i in range(n):
  y.append(x[i])
y.sort()
med=y[index]
for i in range(n):
    if x[i]>med:
        print(med)
    else:
        print(y[index+1])

Problem: p03379
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
x = list(map(int, input().split()))

a = len(x)
b = sorted(x)
fa = b[int((a/2)-1)]
se = b[int(a/2)]


for i in range(n):
    if x[i] <= a/2:
        print(fa)
    else:
        print(se)

Failing test case input:
4
2 4 4 3

Expected output:
4
3
3
4

Actual output:
3
4
4
4


Fixed submission (verdict: Accepted):
n = int(input())
x = list(map(int, input().split()))

a = len(x)
b = sorted(x)
fa = b[int((a/2)-1)]
se = b[int(a/2)]

for i in range(n):
    if x[i] <= fa:
        print(se)
    else:
        print(fa)

Problem: p03379
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)

left=b[int(n/2)-1]
right=b[int(n/2)]
print(left, right)
for i in a:
    pos=bisect.bisect_left(b, i)+1
    if 2*pos<=n:
        print(right)
    else:
        print(left)

Failing test case input:
4
2 4 4 3

Expected output:
4
3
3
4

Actual output:
3 4
4
3
3
4


Fixed submission (verdict: Accepted):
import bisect
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)

left=b[int(n/2)-1]
right=b[int(n/2)]
for i in a:
    pos=bisect.bisect_left(b, i)+1
    if 2*pos<=n:
        print(right)
    else:
        print(left)

Problem: p03379
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def solve(N, A):
    c = int(N / 2)
    left = A[c - 1]
    right = A[c]
    for x in range(c - 1):
        print(left)
    print(right)
    print(left)
    for x in range(c + 1, N):
        print(right)
            
if __name__ == "__main__":
    N = int(input())
    A = list(map(lambda x: int(x), input().split()))
    solve(N, A)


Failing test case input:
4
2 4 4 3

Expected output:
4
3
3
4

Actual output:
4
4
4
4


Fixed submission (verdict: Accepted):
def solve(N, A):
    c = int(N / 2)
    left = sorted(A)[c - 1]
    right = sorted(A)[c]
    if left == right:
        for x in range(N):
            print(left)
        return;
    for x in range(N):
        if A[x] <= left:
            print(right)
        if A[x] >= right:
            print(left)
            
if __name__ == "__main__":
    N = int(input())
    A = list(map(lambda x: int(x), input().split()))
    solve(N, A)
Problem: p03379
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input().strip())
X = list(map(int,input().strip().split(' ')))
sorted_X = sorted(X)
med_l=sorted_X[int(N/2-1)]
med_r=sorted_X[int(N/2)]
print(sorted_X)
for iX in X:
    if iX <= med_l:
        print(med_r)
    elif med_r <= iX:
        print(med_l)
    

Failing test case input:
4
2 4 4 3

Expected output:
4
3
3
4

Actual output:
[2, 3, 4, 4]
4
3
3
4


Fixed submission (verdict: Accepted):
N = int(input().strip())
X = list(map(int,input().strip().split(' ')))
sorted_X = sorted(X)
med_l=sorted_X[int(N/2-1)]
med_r=sorted_X[int(N/2)]
for iX in X:
    if iX <= med_l:
        print(med_r)
    elif med_r <= iX:
        print(med_l)

Problem: p03379
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def abc094C():
    n = int(input())
    x = input().split()
    x = list(map(int, x))
    y = x.copy()
    y.sort()
    print(y)
    nums = y[int(n / 2 - 1): int(n / 2 + 1)]
    for i in range(n):
        y = x.copy()
        tf = nums[0] >= y[i]
        del y[i]
        y.sort()
        print(nums[tf])


abc094C()

Failing test case input:
4
2 4 4 3

Expected output:
4
3
3
4

Actual output:
[2, 3, 4, 4]
4
3
3
4


Fixed submission (verdict: Accepted):
def abc094C():
    n = int(input())
    x = input().split()
    x = list(map(int, x))
    y = x.copy()
    y.sort()
    nums = y[int(n / 2 - 1): int(n / 2 + 1)]
    for i in range(n):
        tf = nums[0] >= x[i]
        print(nums[tf])


abc094C()

Problem: p03379
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
x = list(map(str, input().split()))
sx = sorted(x)

print(sx)
max_mid = sx[int(n/2)]
min_mid = sx[int(n/2-1)]

for i in x:
    if i <= min_mid:    
        print(max_mid)
    else:               
        print(min_mid)


Failing test case input:
4
2 4 4 3

Expected output:
4
3
3
4

Actual output:
['2', '3', '4', '4']
4
3
3
4


Fixed submission (verdict: Accepted):
n = int(input())
x = list(map(int, input().split()))
sx = sorted(x)

min_mid = sx[int(n/2-1)]
max_mid = sx[int(n/2)]

for i in x:
    if i <= min_mid:    
        print(max_mid)
    else:               
        print(min_mid)

Problem: p03379
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))

AB = sorted(A)
C = int(N/2)
for i in range(N):
    if i <= AB[C-1]:
        print(AB[C])
    else:
        print(AB[C-1])

Failing test case input:
4
2 4 4 3

Expected output:
4
3
3
4

Actual output:
4
4
4
4


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))

AB = sorted(A)
C = int(N
for i in range(N):
    if A[i] <= AB[C-1]:
        print(AB[C])
    else:
        print(AB[C-1])
Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,m=map(int,input().split())
arr=list(map(int,input().split()))
maximum=max(arr)
if (maximum-1)<=(sum(arr)-maximum):
  print(0)
else:
  print(sum(arr)-maximum)

Failing test case input:
110 2
110

Expected output:
109


Actual output:
0


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
arr=list(map(int,input().split()))
maximum=max(arr)
if (maximum-1)<=(sum(arr)-maximum):
  print(0)
else:
  print((maximum-1)-(sum(arr)-maximum))

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k, t = map(int, input().split())
a = list(map(int, input().split()))
n = abs(2 * max(a) - sum(a) )
if n <= 1:
    print(0)
else:
    print(n - 1)

Failing test case input:
28 1
4 2 4

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
k, t = map(int, input().split())
a = list(map(int, input().split()))
n = k - max(a)
if max(a) <= k 
    print(0)
else:
    print(k - n * 2 - 1)

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

k, t, *a = map(int, read().split())
x, y = 0, 0
for aa in a:
    if x > y:
        y += aa
    else:
        x += aa
print(abs(x - y) - 1)


Failing test case input:
7 4
0 1 1

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

k, t, *a = map(int, read().split())
print(max(0, 2 * max(a) - k - 1))

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k, t = map(int, input().split())
a = list(map(int, input().split()))
if max(a)%2 == 1:
    print(max(a)-t)
else:
    print(max(a)-1-t)

Failing test case input:
6 3
1 4 1

Expected output:
1

Actual output:
0


Fixed submission (verdict: Accepted):
k, t = map(int, input().split())
a = list(map(int, input().split()))

print(max(max(a)-1-sum(a)+max(a), 0))

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, T = map(int, input().split())

A = list(map(int, input().split()))
m = max(A)

print(max(0, m - 1 - (T - m)))


Failing test case input:
6 1
2 0 2

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
K, T = map(int, input().split())

A = list(map(int, input().split()))
m = max(A)

print(max(0, m - 1 - (K - m)))

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, T = map(int, input().split())
A = list(map(int, input().split()))

if T == 1:
    print(K)
    exit()
print(max(0, max(A) - (K-max(A)+1)))

Failing test case input:
7 1
1 1 2

Expected output:
0


Actual output:
7


Fixed submission (verdict: Accepted):
K, T = map(int, input().split())
A = list(map(int, input().split()))

print(max(0, max(A) - (K-max(A)+1)))
Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k, t = map(int, input().split())

print(max(list(map(int, input().split()))) - t)

Failing test case input:
7 3
4 1 2

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
k, t = map(int, input().split())
ma = max(list(map(int, input().split())))
print(max(0, ma - 1 - (k - ma)))

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, T = map(int, input().split())
A = list(map(int, input().split()))

print(max(A) - (K-max(A)+1))

Failing test case input:
6 4
1 0 1

Expected output:
0


Actual output:
-5


Fixed submission (verdict: Accepted):
K, T = map(int, input().split())
A = list(map(int, input().split()))

print(max(0, max(A) - (K-max(A)+1)))

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k,t=map(int,input().split())
a=list(map(int,input().split()))
if max(a)<=sum(a)-max(a)+1:
    print(0)
else:
    if t==1:
        print(a[0]-1)
    else:
        print(sum(a)-max(a)-1)


Failing test case input:
100 2
100

Expected output:
99


Actual output:
-1


Fixed submission (verdict: Accepted):
k,t=map(int,input().split())
a=list(map(int,input().split()))
num=sum(a)-max(a)
if max(a)<=num+1:
    print(0)
else:
    if max(a)<=(num+1)*2:
        print(max(a)-(num+1))
    else:
        print(num+max(a)-num-1)

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, T = map(int, input().split())

A = list(map(int, input().split()))
m = max(A)

print(max(0, m - 1 - (T - 1)))


Failing test case input:
18 1
7 2 4

Expected output:
0


Actual output:
6


Fixed submission (verdict: Accepted):
K, T = map(int, input().split())

A = list(map(int, input().split()))
m = max(A)

print(max(0, m - 1 - (K - m)))

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K,T=map(int,input().split())
a=list(map(int,input().split()))

maxi=max(a)
other = sum(a)-maxi
print(maxi,other)

if maxi<=other:
    print(0)
else:
    print(maxi-other-1)

Failing test case input:
110 2
110

Expected output:
109


Actual output:
110 0
109


Fixed submission (verdict: Accepted):
K,T=map(int,input().split())
a=list(map(int,input().split()))

maxi=max(a)
other = sum(a)-maxi


if maxi<=other:
    print(0)
else:
    print(maxi-other-1)

Problem: p03958
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
k,t = map(int,input().split())
a= list(map(int,input().split()))
sa = sum(a)
ma = max(a)

print(max(sa-ma-1,0))

Failing test case input:
7 5
1 1 1

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
k,t = map(int,input().split())
a= list(map(int,input().split()))
sa = sum(a)
ma = max(a)

print(max(ma-(sa-ma)-1,0))
Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K,T=map(int,input().split())
A=list(map(int,input().split()))

if abs(sum(A)-max(A)-max(A)) <=1:
  print(0)
else:
  print(abs(sum(A)-max(A)-max(A))-1)

Failing test case input:
13 4
4 2 4

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
K,T=map(int,input().split())
A=list(map(int,input().split()))

if max(A)-(sum(A)-max(A))<=1:
  print(0)
else:
  print(max(A)-(sum(A)-max(A))-1)

Problem: p03958
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,K = map(int,input().split())
A = list(map(int,input().split()))
print(max(2*max(A)-K-1,0))

Failing test case input:
28 1
4 2 4

Expected output:
0


Actual output:
6


Fixed submission (verdict: Accepted):
K,T = map(int,input().split())
A = list(map(int,input().split()))
print(max(2*max(A)-K-1,0))

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k,t,*a=map(int,open(0).read().split());print(abs(sum(a)-max(a)*2)-1)

Failing test case input:
16 1
4 2 4

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
k,t,*a=map(int,open(0).read().split());print(max([i+i-k-1for i in a]+[0]))

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K,T=map(int,input().split())
a=list(map(int,input().split()))
print(max(a)-(K-max(a))-1,0)

Failing test case input:
6 1
1 0 1

Expected output:
0


Actual output:
-5 0


Fixed submission (verdict: Accepted):
K,T=map(int,input().split())
a=list(map(int,input().split()))
print(max(max(a)-(K-max(a))-1,0))

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, T = list(map(int, input().split()))
a = list(map(int, input().split()))













print(max(a)*2-sum(a)-1)


Failing test case input:
6 1
1 0 1

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
K, T = list(map(int, input().split()))
a = list(map(int, input().split()))













print(max(0,max(a)*2-sum(a)-1))

Problem: p03958
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):

import math
from collections import deque
import copy
import bisect
k, n = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
m=max(A)
if n==1:
    print(k-1)
else:
    print(max(m - math.ceil(k/2), 0))

Failing test case input:
28 1
4 2 4

Expected output:
0


Actual output:
27


Fixed submission (verdict: Accepted):

import math
from collections import deque
import copy
import bisect
k, n = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
m=max(A)
s=k-m
print(max(m-1-s, 0))

Problem: p03958
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
k, t = map(int, input().split())
a = sorted(list(map(int, input().split())))

b = a.pop()
print(abs(b-sum(a))-1)

Failing test case input:
9 1
1 0 1

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
k, t = map(int, input().split())
a = sorted(list(map(int, input().split())))

b = a.pop()
print(max(0,b-sum(a)-1))
Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = list(map(int, input().split()))
Q = list(map(int, input().split()))
maxQ = max(Q)
rest = N[0] - 1
print(max([maxQ-rest-1, 0]))

Failing test case input:
6 0
1 4 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N = list(map(int, input().split()))
Q = list(map(int, input().split()))
maxQ = max(Q)
rest = N[0] - maxQ
print(max([maxQ-rest-1, 0]))

Problem: p03958
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
k, t = map(int, input().split())
a = list(map(int, input().split()))
max_a = max(a)
rest_a = sum(a) - max_a

if max_a % (rest_a + 1) == 0:
    ans = max_a 
    ans -= 1
else:
    ans = max_a 
print(ans)

Failing test case input:
23 3
2 1 0

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
import math
k, t = map(int, input().split())
a = list(map(int, input().split()))
max_a = max(a)
rest_a = sum(a) - max_a
print(max(max_a - 1 - rest_a, 0))

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k, _, *a = map(int, open(0).read().split())
print(max(b*2 - k - 1 for b in a))

Failing test case input:
3 3
1 1 0

Expected output:
0


Actual output:
-2


Fixed submission (verdict: Accepted):
k, _, *a = map(int, open(0).read().split())
print(max(max(a)*2 - k - 1, 0))

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k,t = map(int, input().split())
list_cake = list((map(int, input().split())))
list_cake.sort()
if len(list_cake) == 1:
    print(k-1)
elif list_cake[-1] <= k/2:
    print(0)
else:
    print(k - (k-list_cake[-1]) * 2)


Failing test case input:
7 3
4 1 2

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
k,t = map(int, input().split())
list_cake = list((map(int, input().split())))
list_cake.sort()
if list_cake[-1] <= k/2:
    print(0)
else:
    print(k - (k-list_cake[-1]) * 2 - 1)

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k, t = map(int, input().split())
a = list(map(int, input().split()))
print(max(a)-t)

Failing test case input:
6 0
1 4 1

Expected output:
1


Actual output:
4


Fixed submission (verdict: Accepted):
k, t = map(int, input().split())
a = list(map(int, input().split()))

print(max(max(a)-1-sum(a)+max(a), 0))

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, T = map(int, input().split())
a = list(map(int, input().split()))
print(max(a)-(sum(a)-max(a))-1, 0)

Failing test case input:
6 3
1 4 1

Expected output:
1

Actual output:
1 0


Fixed submission (verdict: Accepted):
K, T = map(int, input().split())
a = list(map(int, input().split()))
print(max(max(a)-(sum(a)-max(a))-1, 0))
Problem: p03958
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
k, t = map(int, input().split())
a = list(map(int, input().split()))
max_a = max(a)
rest_a = sum(a) - max_a
ans = math.ceil((max_a / (rest_a + 1))) - 1
print(ans)

Failing test case input:
110 2
000

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
import math
k, t = map(int, input().split())
a = list(map(int, input().split()))
max_a = max(a)
rest_a = sum(a) - max_a
print(max(max_a - 1 - rest_a, 0))

Problem: p03958
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
k,t = map(int,input().split())
a = list(map(int,input().split()))
print(max(0,max(a)-t))

Failing test case input:
13 3
4 2 4

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
k,t = map(int,input().split())
a = list(map(int,input().split()))
print(max(0,max(a)-1-(k-max(a))))

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k,t=map(int,input().split())
a=list(map(int,input().split()))
m=max(a)
n=k-m
print(min(m-n-1,0))

Failing test case input:
7 5
-1 1 1

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):
k,t=map(int,input().split())
a=list(map(int,input().split()))
m=max(a)
n=k-m
print(max(m-n-1,0))

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
l=list(map(int, input().split()))
r=list(map(int, input().split()))
print(2*max(r)-l[0]-1)

Failing test case input:
7 8
-1 1 1

Expected output:
0


Actual output:
-6


Fixed submission (verdict: Accepted):
l=list(map(int, input().split()))
r=list(map(int, input().split()))
print(max(0,2*max(r)-l[0]-1))

Problem: p03958
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, T = map(int, input().split())
*A, = map(int, input().split())
A = sorted(A, reverse=True)
print(A[0] - sum(A[1:]) - 1)

Failing test case input:
3 3
1 1 0

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
K, T = map(int, input().split())
*A, = map(int, input().split())
A = sorted(A, reverse=True)
print(max(A[0] - sum(A[1:]) - 1, 0))
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



def euclid(a,b):
    a,b=max(a,b),min(a,b)
    if a%b==0:
        return b
    else:
        a,b=b,a%b
        return euclid(a,b)

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

if N==2:
    print(max(A[0],A[1]))
    exit()

log=10**9
place=0
for i in range(N-1):
    temp=euclid(A[i],A[i+1])
    log=min(log,temp)
    if log==temp:
        place=i

A.pop(place)
log=10**9
for i in range(N-2):
    temp=euclid(A[i],A[i+1])
    log=min(log,temp)

print(log)

Failing test case input:
3
9 28 18

Expected output:
9


Actual output:
2


Fixed submission (verdict: Accepted):


def euclid(a,b):
    a,b=max(a,b),min(a,b)
    if a%b==0:
        return b
    else:
        a,b=b,a%b
        return euclid(a,b)

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

org_A=A[:]

A=A[::-1]
l=[A.pop(-1)]
while A:
    l.append(euclid(l[-1],A.pop(-1)))

A=org_A
r=[A.pop(-1)]
while A:
    r.append(euclid(r[-1],A.pop(-1)))
r=r[::-1]

ans=0

for i in range(N):
    temp=euclid(l[i-1] if i!=0 else r[i+1],r[i+1] if i!=N-1 else l[i-1])
    
    ans=max(ans,temp)

print(ans)

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def GCD(a, b):
    
    if a < b: (a, b) = (b, a)
    print(a, b)
    if b == 0: return a
    m = a % b
    while m != 0:
        a = b
        b = m
        m = a % b
    return b

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

if N < 2 and 1e5 < N: raise()
for v in A:
    if v < 1 and v < 1e9: raise()

result = []
for skip in range(N):
    l = 0
    r = 0
    for v in range(0, skip): l = GCD(l, A[v])
    for v in range(N-1, skip, -1): r = GCD(r, A[v])
    result.append(GCD(l, r))

print(max(result))

Failing test case input:
2
0010110100 1110100011

Expected output:
1110100011


Actual output:
1110100011 0
1110100011 0
10110100 0
10110100 0
1110100011


Fixed submission (verdict: Accepted):
def GCD(a, b):
    
    if a < b: (a, b) = (b, a)
    if b == 0: return a
    m = a % b
    while m != 0:
        a = b
        b = m
        m = a % b
    return b

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

if N < 2 and 1e5 < N: raise()
for v in A:
    if v < 1 and v < 1e9: raise()


l_list = []
l = 0
for i in range(0, N):
    l = GCD(l, A[i])
    l_list.append( l )

r_list = []
r = 0
for i in range(-1, -(N+1), -1):
    r = GCD(r, A[i])
    r_list.append( r )

n = []    
for i in range(0, N):
    if i-1 < 0:
        l = 0
    else:
        l = l_list[i-1]
    if N-i-2 < 0:
        r = 0
    else:
        r = r_list[N-i-2]
    n.append(GCD(l, r))
print(max(n))
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
v = list(map(int, input().split()))
m = 1
gf = []
gp = []


def gcd(x, y):
    if x < y:
        x += y
        y = x - y
        x -= y

    while y > 0:
        r = x % y
        x = y
        y = r

    return x


gf.append(v[0])
for i in range(n-1):
    gf.append(gcd(gf[i], v[i+1]))

gp.append(v[n-1])
for i in range(n-1):
    gp.append(gcd(gp[i], v[n-2-i]))

m = gp[n-2]

for i in range(n-1):
    b = gcd(gf[i], gp[n-3-i])
    if m < b:
        m = b
if m < gf[1]:
    m = gf[n-2]

print(m)


Failing test case input:
2
0011011001 0001101010

Expected output:
11011001


Actual output:
1101010


Fixed submission (verdict: Accepted):
n = int(input())
v = list(map(int, input().split()))
m = 1
gf = []
gp = []


def gcd(x, y):
    if x < y:
        x += y
        y = x - y
        x -= y

    while y > 0:
        r = x % y
        x = y
        y = r

    return x


gf.append(v[0])
for i in range(n-1):
    gf.append(gcd(gf[i], v[i+1]))

gp.append(v[n-1])
for i in range(n-1):
    gp.append(gcd(gp[i], v[n-2-i]))

m = gp[n-2]

for i in range(n-1):
    b = gcd(gf[i], gp[n-3-i])
    if m < b:
        m = b
if m < gf[n-2]:
    m = gf[n-2]

print(m)

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin

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

n = int(stdin.readline().rstrip())
an = list(map(int, input().split()))

left = []
right = []

before = -1
for i in range(n):
  if(i==0):
    before = an[i]
  else:
    before = gcd(before, an[i])
  left.append(before)

before = -1
for i in range(n):
  if(i==0):
    before = an[n-1-i]
  else:
    before = gcd(before, an[n-1-i])
  right.append(before)


max = 0
for i in range(n):
  if(i==0):
    before = right[1];
  elif(i==(n-1)):
    before = left[n-2];
  else:
    before = gcd(left[i-1],right[n-2-i])
  if(max < before ):
    max = before

print(max)

Failing test case input:
2
1010110100 1110101111

Expected output:
1110101111


Actual output:
1010110100


Fixed submission (verdict: Accepted):
from sys import stdin

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

n = int(stdin.readline().rstrip())
an = list(map(int, input().split()))

left = []
right = []

for i in range(n):
  if(i==0):
    before = an[i]
  else:
    before = gcd(before, an[i])
  left.append(before)

for i in range(n):
  if(i==0):
    before = an[n-1-i]
  else:
    before = gcd(before, an[n-1-i])
  right.append(before)

max = 0
for i in range(n):
  if(i==0):
    before = right[n-2];
  elif(i==(n-1)):
    before = left[n-2];
  else:
    before = gcd(left[i-1],right[n-2-i])
  if(max < before ):
    max = before

print(max)
Problem: p03061
Buggy submission (Python (3.8.2), verdict: Wrong Answer):


import sys
sys.setrecursionlimit(10**6)

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

from math import gcd

L = [0] * (n+1)
R = [0] * (n+1)

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

ans = 0
for i in range(n):
    ans = max(ans, gcd(L[i-1], R[i+1]))

print(ans)


Failing test case input:
2
0010100100 0010100010

Expected output:
10100100


Actual output:
10100010


Fixed submission (verdict: Accepted):


import sys
sys.setrecursionlimit(10**6)

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

from math import gcd

L = [0] * n
R = [0] * n

for i in range(n-1):
    L[i+1] = gcd(L[i], A[i])
for i in range(n-1, 0, -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)

Problem: p03061
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def larger(x, y):
	if x > y:
		return x
	return y

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

N = int(input())
A = list(map(int, input().split()))
gcdL = [A[0]]
for i in range(1, N):
	gcdL.append(euc(gcdL[-1], A[i]))
gcdR = [A[-1]]
for i in range(1, N):
	gcdR.append(euc(gcdR[-1], A[-1-i]))
gcdR.reverse()
max = gcdR[0]
for i in range(1, N-1):
	max = larger(max, euc(gcdL[i-1], gcdR[i+1]))
max = larger(max, gcdL[-1])
print(max)

Failing test case input:
2
1000000111 1101001110

Expected output:
1101001110


Actual output:
11


Fixed submission (verdict: Accepted):
def larger(x, y):
	if x > y:
		return x
	return y

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

N = int(input())
A = list(map(int, input().split()))
gcdL = [A[0]]
for i in range(1, N):
	gcdL.append(euc(gcdL[-1], A[i]))
gcdR = [A[-1]]
for i in range(1, N):
	gcdR.append(euc(gcdR[-1], A[-1-i]))
gcdR.reverse()
max = gcdR[1]
for i in range(1, N-1):
	max = larger(max, euc(gcdL[i-1], gcdR[i+1]))
max = larger(max, gcdL[-2])
print(max)

Problem: p03061
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
if N==2: print(max(A));exit()
from math import gcd
L = {}
R = {}
L[0] = A[0]
R[N-1] = A[-1]
ans = 0
for i in range(1,N):
    L[i] = gcd(L[i-1],A[i])
    R[N-i-1] = gcd(R[N-i],A[N-i-1])
for i in range(2,N):
    ans = max(ans,gcd(L[i-2],R[i]))
ans = max(ans,R[1])
ans = max(ans,L[N-1])
ans = max(ans,R[0])
print(ans)

Failing test case input:
3
4 2 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
if N==2: print(max(A));exit()
from math import gcd
L = {}
R = {}
L[0] = A[0]
R[N-1] = A[-1]
ans = 0
for i in range(1,N):
    L[i] = gcd(L[i-1],A[i])
    R[N-i-1] = gcd(R[N-i],A[N-i-1])
for i in range(2,N):
    ans = max(ans,gcd(L[i-2],R[i]))
ans = max(ans,R[1])
ans = max(ans,L[N-2])
ans = max(ans,R[0])
print(ans)
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n,a,b=int(input()),list(map(int,input().split())),[]
if n==2:print(gcd(a[0],a[1]))
elif n==3:print(max(gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2])))
else:
  no,mi=a[0],a[0]
  for i in range(1,n):
    s=gcd(no,a[i])
    if s!=no:
      no=max(s,mi)
      mi=gcd(s,mi)
  on,im=a[-1],a[-1]
  for i in range(1,n):
    s=gcd(on,a[n-i-1])
    if s!=on:
      on=max(s,im)
      im=gcd(s,im)
  print(max(no,on))

Failing test case input:
2
1111100000 1000000100

Expected output:
1111100000


Actual output:
100


Fixed submission (verdict: Accepted):
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n,a,b=int(input()),list(map(int,input().split())),[]
if n==2:print(max(a[0],a[1]))
elif n==3:print(max(gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2])))
else:
  no,mi=a[0],a[0]
  for i in range(1,n):
    s=gcd(no,a[i])
    if s!=no:
      no=max(s,mi)
      mi=gcd(s,mi)
  print(no)

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


N = int(input())
A = list(map(int, input().split()))
L = [0 for i in range(N)]
R = [0 for i in range(N)]
T = [0 for i in range(N)]

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

Failing test case input:
2
0010110100 0010100010

Expected output:
10110100


Actual output:
10100010


Fixed submission (verdict: Accepted):
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


N = int(input())
A = list(map(int, input().split()))
L = [0 for i in range(N)]
R = [0 for i in range(N)]
T = [0 for i in range(N)]

for i in range(N):
    if i == 0:
        L[i] = 0
    else:
        L[i] = gcd(L[i-1], A[i-1])
for i in reversed(range(0, N)):
    if i == N-1:
        R[i] = 0
    else:
        R[i] = gcd(R[i+1], A[i+1])
for i in range(N):
    T[i] = gcd(L[i], R[i])

print(max(T))

Problem: p03061
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import math
N = int(input())
A = list(map(int, input().split()))

B = [0 for _ in range(N)]
C = [0 for _ in range(N)]

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

C[N-1] = A[N-1]
for i in range(N-2,-1,-1):
  C[i] = math.gcd(C[i+1],A[i])
  
ans = max(C[1],B[N-2])
for i in range(1,N-1):
  print(i, math.gcd(C[i+1],B[i-1]))
  ans = max(math.gcd(C[i+1],B[i-1]), ans)
          
print(ans)



Failing test case input:
3
36 36 10

Expected output:
36


Actual output:
1 2
36


Fixed submission (verdict: Accepted):
import math
N = int(input())
A = list(map(int, input().split()))

B = [0 for _ in range(N)]
C = [0 for _ in range(N)]

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

C[N-1] = A[N-1]
for i in range(N-2,-1,-1):
  C[i] = math.gcd(C[i+1],A[i])
  
ans = max(C[1],B[N-2])
for i in range(1,N-1):
  
  ans = max(math.gcd(C[i+1],B[i-1]), ans)
          
print(ans)
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(a,b):
    while b != 0:
        a,b=b,a%b
    return a

n=int(input())
a=[0] + list(map(int,input().split())) + [0]

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

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

print(max(z))


Failing test case input:
2
1000100111 0101011110

Expected output:
1000100111


Actual output:
101011110


Fixed submission (verdict: Accepted):
def gcd(a,b):
    while b != 0:
        a,b=b,a%b
    return a

n=int(input())
a=[0] + list(map(int,input().split())) + [0]

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

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

print(max(z))

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
from functools import lru_cache

@lru_cache(maxsize=None)
def gcd(a, b):
    if a % b == 0:
        return b
    else:
        return gcd(b, a % b)


N, *A = map(int, sys.stdin.read().split())
L, R = [0] * (N + 1), [0] * (N + 1)
for i in range(N):
    L[i + 1] = gcd(L[i], A[i])
    R[-i - 2] = gcd(R[-i - 1], A[-i - 1])


res = 1
for i in range(N - 1):
    tmp = gcd(L[i], R[i + 1])
    if res < tmp:
        res = tmp
print(res)


Failing test case input:
2
1001000110 0000011100

Expected output:
1001000110


Actual output:
11100


Fixed submission (verdict: Accepted):
import sys
from functools import lru_cache

@lru_cache(maxsize=None)
def gcd(a, b):
    if b == 0:
        return a
    if a % b == 0:
        return b
    else:
        return gcd(b, a % b)


N, *A = map(int, sys.stdin.read().split())
L = [0] * (N + 2)
R = [0] * (N + 2)
for i in range(N):
    L[i + 2] = gcd(L[i + 1], A[i])
    R[-i - 2] = gcd(R[-i - 1], A[-i - 1])

print(max(gcd(L[i], R[i + 1]) for i in range(1, N + 1)))

Problem: p03061
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math

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

L=[a[0]]
gcdl = a[0]
R=[a[n-1]]
gcdr = a[n-1]
for xi in range(1,n):
    L.append(math.gcd(gcdl,a[xi]))

for xi in range(n-2,-1,-1):
    R.append(math.gcd(gcdr,a[xi]))

R.reverse()

m = []
m.append(R[1])
m.append(L[n-1])


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




print(max(m))


Failing test case input:
3
32 24 1

Expected output:
8


Actual output:
1


Fixed submission (verdict: Accepted):
import math

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

L=[a[0]]
gcdl = a[0]
R=[a[n-1]]
gcdr = a[n-1]
for xi in range(1,n):
    gcdl = math.gcd(gcdl,a[xi])
    L.append(gcdl)

for xi in range(n-2,-1,-1):
    gcdr = math.gcd(gcdr,a[xi])
    R.append(gcdr)

R.reverse()



m = []
m.append(R[1])
m.append(L[n-2])


if n>2:
    for xi in range(1,n-1):
        m.append(math.gcd(L[xi-1],R[xi+1]))
        


print(max(m))
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def gcd(a,b):
    if a%b == 0:
        return b
    else:
        return gcd(b, a%b)
    
n = ni()
a = list(li())

a.sort()

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

print(sorted(gcds)[1] if n > 2 else max(a[0], a[1]))

Failing test case input:
3
7 6 8

Expected output:
2

Actual output:
1


Fixed submission (verdict: Accepted):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def gcd(a,b):
    if a%b == 0:
        return b
    else:
        return gcd(b, a%b)
    
n = ni()
a = list(li())
    
gcd_left = [0, a[0]]
gcd_right = [0, a[-1]]

for ai in a[1:]:
    gcd_left.append(gcd(gcd_left[-1], ai))
    
for ai in a[-2::-1]:
    gcd_right.append(gcd(gcd_right[-1], ai))
    
ans = 1

for le, ri in zip(gcd_left[:-1], gcd_right[::-1][1:]):
    if le == 0 or ri == 0:
        ans = max(ans, le, ri)
        
    else:
        ans = max(ans, gcd(le, ri))
        
print(ans)

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))

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

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



result = 0
for i in range(N-1):
  
  g = gcd(L[i], R[i+2])
  result = max([g, result])
  
print(result)

Failing test case input:
2
1101101000 0110101101

Expected output:
1101101000


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))

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

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



result = 0
for i in range(N):
  
  g = gcd(L[i], R[i+1])
  
  result = max([g, result])
  
print(result)
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
L = list(map(int,input().split()))

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

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

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

Failing test case input:
2
1001101000 0110101101

Expected output:
1001101000


Actual output:
110101101


Fixed submission (verdict: Accepted):
n = int(input())
L1 = list(map(int,input().split()))

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

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

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

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = sorted(list(map(int, input().split())))

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

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

result = 0
for i in range(N-1):
  
  g = gcd(L[i], R[i+2])
  print(g)
  result = max([g, result])
  
print(result)

Failing test case input:
2
1111101101 1100101000

Expected output:
1111101101


Actual output:
[1100101000, 1100101000, 1]
[1, 1111101101, 1111101101]
1
1


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))

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

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



result = 0
for i in range(N):
  
  g = gcd(L[i], R[i+1])
  
  result = max([g, result])
  
print(result)

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())

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

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

list_koyaku1=[]
list_koyaku11=[]       
         
if N==2:
    ans=max(A)

else:
    b=min(A)
    c=max(A)
    for a in A:
        list_koyaku1.append(gcd(a,b))

    for a in list_koyaku1:
        list_koyaku11.append(gcd(a,c))
    ans=max(list_koyaku11)

print(ans)

Failing test case input:
3
36 36 10

Expected output:
36


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())

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


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

list1=[0]
L=0
for a in A:
    L=gcd(L,a)
    list1.append(L)

list2=[0]
R=0
for a in reversed(A):
    R=gcd(R,a)
    list2.append(R)

list2.reverse()

ans=[]

for i in range(N):
    ans.append(gcd(list1[i],list2[i+1]))

print(max(ans))
Problem: p03061
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
read = sys.stdin.read
from math import gcd
def main():
    n, *a = map(int, read().split())
    l = [0] * (n + 1)
    for i1 in range(n):
        l[i1 + 1] = gcd(l[i1], a[i1])
    r = [0] * (n + 1)
    for j1 in range(n - 1, -1, -1):
        r[j1] = gcd(r[j1 + 1], a[j1])
    m = [0] * (n + 1)
    for k1 in range(n - 1):
        m[k1] = gcd(l[k1], r[k1 + 1])
    r = max(m)
    print(r)

if __name__ == '__main__':
    main()

Failing test case input:
2
1110001110 1011000101

Expected output:
1110001110


Actual output:
1011000101


Fixed submission (verdict: Accepted):
import sys
read = sys.stdin.read
from math import gcd
def main():
    n, *a = map(int, read().split())
    if n == 1:
        print(a[0])
        sys.exit()
    l = [0] * (n + 1)
    for i1 in range(n):
        l[i1 + 1] = gcd(l[i1], a[i1])
    r = [0] * (n + 1)
    for j1 in range(n - 1, -1, -1):
        r[j1] = gcd(r[j1 + 1], a[j1])
    m = [0] * (n + 1)
    for k1 in range(n):
        m[k1] = gcd(l[k1], r[k1 + 1])
    r = max(m)
    print(r)

if __name__ == '__main__':
    main()

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
li = [ int(it) for it in input().split() ]
lil = [0]*N
lir = [0]*N

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
  
lil[0]=li[0]
lir[N-1]=li[N-1]
for i in range(N-1):
  lil[i+1]=gcd(li[i+1],lil[i])
for i in range(N-1,0,-1):
  lir[i-1]=gcd(li[i-1],lir[i])
s = -1
for i in range(N):
  if (i==0):
    gc = lil[1]
  elif (i==N-1):
    gc = lir[N-2]
  else:
    gc = gcd(lil[i-1],lir[i+1])
  s = max(s, gc )
print (s)


Failing test case input:
2
0010110100 1010100010

Expected output:
1010100010


Actual output:
10


Fixed submission (verdict: Accepted):
N = int(input())
li = [ int(it) for it in input().split() ]
lil = [0]*N
lir = [0]*N

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
  
lil[0]=li[0]
lir[N-1]=li[N-1]
for i in range(N-1):
  lil[i+1]=gcd(li[i+1],lil[i])
for i in range(N-1,0,-1):
  lir[i-1]=gcd(li[i-1],lir[i])
s = -1
for i in range(N):
  if (i==0):
    gc = lir[1]
  elif (i==N-1):
    gc = lil[N-2]
  else:
    gc = gcd(lil[i-1],lir[i+1])
  s = max(s, gc )
print (s)
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)
 
N = (int(input()))
A = [int(i) for i in input().split()]

A1 = [0] * (N)
A2 = [0] * (N)
A3 = [0] * (N)
A1[0] = A[0]
A2[N-1] = A[N-1]

for i in range(N):
  if i==0 : continue
  A1[i] = gcd(A1[i-1],A[i])
  A2[N-1-i] = gcd(A2[N-i],A[N-1-i])
  
for i in range(N):
  A3[i] = max(A1[i],A2[i])

print(min(A3))

Failing test case input:
3
9 28 30

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)
 
N = (int(input()))
A = [int(i) for i in input().split()]

A1 = [0] * (N)
A2 = [0] * (N)
A3 = [0] * (N)
A1[0] = A[0]
A2[N-1] = A[N-1]

for i in range(N):
  if i==0 : continue
  A1[i] = gcd(A1[i-1],A[i])
  A2[N-1-i] = gcd(A2[N-i],A[N-1-i])
  
for i in range(N):
  if i==0 : A3[i] = A2[i+1] ; continue
  if i==N-1 : A3[i] = A1[i-1] ; continue
  A3[i] = gcd(A1[i-1],A2[i+1])

print(max(A3))

Problem: p03061
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def gcd(a, b):  
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

def makelist(n, m):
    return [[0 for i in range(m)] for j in range(n)]

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

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

toLeft = [0]*(N+1)
toLeft[N] = A[N]
for i in reversed(range(1, N)):
    toLeft[i] = gcd(toLeft[i+1], A[i])
    
ans = max(toRight[-2], toLeft[2])
for i in range(3, N-3 + 1):
    now = gcd(toRight[i-1], toLeft[-i-1])
    ans = max(ans, now)

print(ans)


Failing test case input:
3
7 6 7

Expected output:
7


Actual output:
1


Fixed submission (verdict: Accepted):
def gcd(a, b):  
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

def makelist(n, m):
    return [[0 for i in range(m)] for j in range(n)]

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

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

toLeft = [0]*(N+1)
toLeft[N] = A[N]
for i in reversed(range(1, N)):
    toLeft[i] = gcd(toLeft[i+1], A[i])



    
ans = max(toRight[-2], toLeft[2])
for i in range(2, N-1 + 1):
    now = gcd(toRight[i-1], toLeft[i+1])
    ans = max(ans, now)

print(ans)