Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def mul(inp):
    return int(inp * 2)


if __name__ == '__main__':
    n = int(input())
    a = list(map(mul, map(int, input().split())))
    res = [0] * n
    for x in range(0, n):
        res[x] = a[x]
        count = 1
        for i in range(x + 1, n + x, 2):
            mod_i = i % n
            res[x] = res[x] - a[mod_i]
        for i in range(x + 2, n + x, 2):
            mod_i = i % n
            res[x] = res[x] + a[mod_i]
        res[x] = str(int(res[x] / 2))
    print(' '.join(res))


Fixed submission:
def mul(inp):
    return int(inp * 2)


if __name__ == '__main__':
    n = int(input())
    a = list(map(mul, map(int, input().split())))
    res = [0] * n
    for x in range(0, 1):
        res[x] = a[x]
        count = 1
        for i in range(x + 1, n + x, 2):
            mod_i = i % n
            res[x] = res[x] - a[mod_i]
        for i in range(x + 2, n + x, 2):
            mod_i = i % n
            res[x] = res[x] + a[mod_i]
        res[x] = int(res[x] / 2)
    for x in range(1, n):
        res[x] = a[x - 1] - res[x - 1]
    print(' '.join(map(str, res)))

Buggy python submission (verdict: Time Limit Exceeded):
def mul(inp):
    return int(inp * 2)


if __name__ == '__main__':
    n = int(input())
    a = list(map(mul, map(int, input().split())))
    res = [0] * n
    for x in range(0, n):
        res[x] = a[x]
        count = 1
        for i in range(x + 1, n + x):
            mod_i = i % n
            count += 1
            if count % 2 == 0:
                res[x] = res[x] - a[mod_i]
            else:
                res[x] = res[x] + a[mod_i]
        res[x] = str(int(res[x] / 2))
    print(' '.join(res))


Fixed submission:
def mul(inp):
    return int(inp * 2)


if __name__ == '__main__':
    n = int(input())
    a = list(map(mul, map(int, input().split())))
    res = [0] * n
    for x in range(0, 1):
        res[x] = a[x]
        count = 1
        for i in range(x + 1, n + x, 2):
            mod_i = i % n
            res[x] = res[x] - a[mod_i]
        for i in range(x + 2, n + x, 2):
            mod_i = i % n
            res[x] = res[x] + a[mod_i]
        res[x] = int(res[x] / 2)
    for x in range(1, n):
        res[x] = a[x - 1] - res[x - 1]
    print(' '.join(map(str, res)))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
l=list()
for i in range(N):
    l.append(int(input()))

num=list()
M=max(l)
for k in range(N):
    if(l[k]==M):
        num=l[:k]+l[k+1:]
        print(max(num))
    else:
        print(M)


Fixed submission:
N=int(input())
l=list()
for i in range(N):
    l.append(int(input()))
a=sorted(l)
m1=a[-1]
m2=a[-2]
for k in range(N):
    if(m1==l[k]):
        print(m2)
    else:
        print(m1)

Buggy python submission (verdict: Runtime Error):
N=int(input())
l=list()
for i in range(N):
    l.append(int(input()))

num=list()
M=max(l)
for k in range(N):
    if(k[i]==M):
        num=l[:k]+l[k+1:]
        print(max(num))
    else:
        print(M)


Fixed submission:
N=int(input())
l=list()
for i in range(N):
    l.append(int(input()))
a=sorted(l)
m1=a[-1]
m2=a[-2]
for k in range(N):
    if(m1==l[k]):
        print(m2)
    else:
        print(m1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
l=list()
for i in range(N):
    l.append(int(input()))

num=list()
for k in range(N):
    num=l[:k]+l[k+1:]
    print(max(num))

Fixed submission:
N=int(input())
l=list()
for i in range(N):
    l.append(int(input()))
a=sorted(l)
m1=a[-1]
m2=a[-2]
for k in range(N):
    if(m1==l[k]):
        print(m2)
    else:
        print(m1)
Buggy python submission (verdict: Runtime Error):
A=list(input())
B=[]
a=A[0]
cnt1=0
cnt2=0
for i in range(4):
    if(a==A[i]):
        cnt1+=1
    else:
        B.append(A[i])
b=B[0]
if(cnt1==2):
    for i in range(2):
        if(b==B[i]):
            cnt2+=1
    if(cnt2==2):
        print("Yes")
    else:
        print("No")        
else:
    print("No")


Fixed submission:
A=list(input())
B=[]
a=A[0]
cnt1=0
cnt2=0
for i in range(4):
    if(a==A[i]):
        cnt1+=1
    else:
        B.append(A[i])

if(cnt1==2):
    b=B[0]
    for i in range(2):
        if(b==B[i]):
            cnt2+=1
    if(cnt2==2):
        print("Yes")
    else:
        print("No")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import math
A,B,C,D=map(int,input().split())

sum1=(A-1)//C
sum2=B//C
sum3=sum2-sum1
sum1=(A-1)//D
sum2=B//D
sum4=sum2-sum1
num=(C*D)//math.gcd(C,D)
sum1=(A-1)//num
sum2=B//num
sum5=sum2-sum1
sum=sum3+sum4-sum5
sum=B-A+1-sum


print(sum)


Fixed submission:
import fractions

A,B,C,D=map(int,input().split())

sum1=(A-1)//C
sum2=B//C
sum3=sum2-sum1
sum1=(A-1)//D
sum2=B//D
sum4=sum2-sum1
num=(C*D)//fractions.gcd(C,D)
sum1=(A-1)//num
sum2=B//num
sum5=sum2-sum1
sum=sum3+sum4-sum5
sum=B-A+1-sum


print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
A,B,C,D=map(int,input().split())
sum=0
for i in range(A,B+1):
    #if(i%C!=0 and i%D!=0):
    if(i%C!=0):
        if(i%D!=0):
            sum+=1

print(sum)


Fixed submission:
import fractions

A,B,C,D=map(int,input().split())

sum1=(A-1)//C
sum2=B//C
sum3=sum2-sum1
sum1=(A-1)//D
sum2=B//D
sum4=sum2-sum1
num=(C*D)//fractions.gcd(C,D)
sum1=(A-1)//num
sum2=B//num
sum5=sum2-sum1
sum=sum3+sum4-sum5
sum=B-A+1-sum


print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
A,B,C,D=map(int,input().split())
sum=0

for i in range(A,B+1):
    if(i%C!=0 and i%D!=0):
        sum+=1

print(sum)


Fixed submission:
import fractions

A,B,C,D=map(int,input().split())

sum1=(A-1)//C
sum2=B//C
sum3=sum2-sum1
sum1=(A-1)//D
sum2=B//D
sum4=sum2-sum1
num=(C*D)//fractions.gcd(C,D)
sum1=(A-1)//num
sum2=B//num
sum5=sum2-sum1
sum=sum3+sum4-sum5
sum=B-A+1-sum


print(sum)
Buggy python submission (verdict: Runtime Error):
S=int(input())

a=S/100
b=S%100

if((a>12 or a==0) and 1<=b<=12):
        print("YYMM")

elif(1<=a<=12 and (b>12 or b==0)):
        print("MMYY")

elif(1<=a<=12 and 1<=b<=12):
        print('AMBIGUOUS')

else:
    print("NA")


Fixed submission:
N,K=(int(i) for i in input().split())
s=input()
S=list(s)

if(S[K-1]=='A'):
    S[K-1]='a'
elif(S[K-1]=='B'):
    S[K-1]='b'
elif(S[K-1]=='C'):
    S[K-1]='c'

A=''.join(S)
print(A)

Buggy python submission (verdict: Runtime Error):
S=int(input())

a=S/100
b=S%100

if(a>12 and b>12):
    print("NA")

elif(a==0 and b==0):
    print("NA")

elif((a>12 or a==0) and 1<=b<=12):
        print("YYMM")

elif(1<=a<=12 and (b>12 or b==0)):
        print("MMYY")

elif(1<=a<=12 and 1<=b<=12):
        print('AMBIGUOU')

else:
    print("NA")


Fixed submission:
N,K=(int(i) for i in input().split())
s=input()
S=list(s)

if(S[K-1]=='A'):
    S[K-1]='a'
elif(S[K-1]=='B'):
    S[K-1]='b'
elif(S[K-1]=='C'):
    S[K-1]='c'

A=''.join(S)
print(A)
Buggy python submission (verdict: Runtime Error):
S=int(input())

a=S/100
b=S%100

if(a>12 and b>12):
    print("NA")

elif(a==0 and b==0):
    print("NA")

elif((a>12 or a=0) and 1<=b<=12):
        print("YYMM")

elif(1<=a<=12 and (b>12 or b=0)):
        print("MMYY")

elif(1<=a<=12 and 1<=b<=12):
        print('AMBIGUOU')

else:
    print("NA")


Fixed submission:
n = int(input()[:4])
a = n//100
b = n%100
if 0<a<=12 and 0<b<=12:
    print('AMBIGUOUS')
elif 1<=a<=12 and (b>=13 or b==0):
    print('MMYY')
elif 1<=b<=12 and (13<=a or a==0):
    print('YYMM')
else:
    print('NA')
Buggy python submission (verdict: Runtime Error):
n=int(input())
v=list(map(int,input().split()))
c=list(map(int,input().split()))
num=0
for i in range(n):
            if(v[i]-c[i]>0):
                num+=v[i]-d[i]
print(num)


Fixed submission:
n=int(input())
v=list(map(int,input().split()))
c=list(map(int,input().split()))
d=[]
max=0
num=0
for i in range(n):
            d.append(v[i]-c[i])
"""
for i in range(n-1):
    num=d[i]

    for k in range(n-i-1):
        if(num+d[i+1+k]>max):
            max=num+d[i+1+k]
"""
d.sort()
d.reverse()
for i in range(n):
    num=max+d[i]
    if num>max:
        max=num

print(max)
Buggy python submission (verdict: Runtime Error):
#import math
import fraction

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

L=[0,0]
for ai in A:
    #L.append(gcd(L[-1],ai))
    L.append(fraction.gcd(L[-1],ai))
    print(L)

R=[0,0]
for ai in A[::-1]:
    #R.append(gcd(R[-1],ai))
    R.append(fraction.gcd(L[-1],ai))
    print(R)

print(max(fraction.gcd(l,r) for l,r in zip(L,reversed(R))))


Fixed submission:
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)
N=int(input())
A=list(map(int,input().split()))

L=[0,0]
for ai in A:
    L.append(gcd(L[-1],ai))
    #print(L)

R=[0,0]
for ai in A[::-1]:
    R.append(gcd(R[-1],ai))
    #print(R)

print(max(gcd(l,r) for l,r in zip(L,reversed(R))))

Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)
N=int(input())
A=list(map(int,input().split()))

L=[0,0]
for ai in A:
    L.append(gcd(L[-1],ai))
    print(L)

R=[0,0]
for ai in A[::-1]:
    R.append(gcd(R[-1],ai))
    print(R)

print(max(gcd(l,r) for l,r in zip(L,reversed(R))))

Fixed submission:
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)
N=int(input())
A=list(map(int,input().split()))

L=[0,0]
for ai in A:
    L.append(gcd(L[-1],ai))
    #print(L)

R=[0,0]
for ai in A[::-1]:
    R.append(gcd(R[-1],ai))
    #print(R)

print(max(gcd(l,r) for l,r in zip(L,reversed(R))))
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
l=(abs(i)  for i in A)
cnt=0
for i in A:
    if(i<0):
        cnt+=1
if cnt%2==0:
    print(sum(l))
else:
    print(sum(l)-2*min(l))

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
l=[abs(i)  for i in A]
cnt=0
for i in A:
    if(i<0):
        cnt+=1
if cnt%2==0:
    print(sum(l))
else:
    print(sum(l)-2*min(l))
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
S=input()

l=[0]
curr='1'

for c in S:
    if c !=curr:
        l.append(1)
        curr=c
    else:
        l[-1]+=1
if curr=='0':
    l.append(0)

n_group=len(1)
sum_=0
k =min(k,n_group)

for i in range(k):
    sum_+=l[2*i]+l[2*i+1]
sum_ +=l[2*k]
max_=sum_

for i in range(k,n_group):
    sum_ -=l[2*i-2*k]+l[2*i+1-2*k]
    sum_ +=l[2*i+1]+l[2*i+2]
    max_ =max(max_,sum_)

print(max_)   


Fixed submission:
a,b=map(int,input().split())
#a,b=(input().split())
c=max(a,b)
d=min(a,b)
if  c>d:
    print(2*c-1)

else:
    print(c+d)

Buggy python submission (verdict: Runtime Error):
A=int(input())
B=int(input())

if(A>B):
    print(2*A-1)
elif(A==B):
    print(A*2)
elif(B>A):
    print(B*2-1)


Fixed submission:
a,b=map(int,input().split())
#a,b=(input().split())
c=max(a,b)
d=min(a,b)
if  c>d:
    print(2*c-1)

else:
    print(c+d)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
S=input()

l=[0]
curr='1'

for c is S:
    if c !=curr:
        l.append(1)
        curr=c
    else:
        l[-1]+=1
if curr=='0':
    l.append(0)

n_group=len(1)
sum_=0
k =min(k,n_group)

for i in range(k):
    sum_+=l[2*i]+l[2*i+1]
sum_ +=l[2*k]
max_=sum_

for i in range(k,n_group):
    sum_ -=l[2*i-2*k]+l[2*i+1-2*k]
    sum_ +=l[2*i+1]+l[2*i+2]
    max_ =max(max_,sum_)

print(max_)   


Fixed submission:
N, K = map(int, input().split())
S = input()
 
l = [0]
curr = '1'
 
#0と1の塊を探索
for c in S:
    if c != curr:
        l.append(1)
        curr = c
    else:
        l[-1] += 1
if curr == '0':
    l.append(0)
 
n_group = len(l) // 2
sum_ = 0
k = min(K, n_group)
 
#初期値として左端から1の塊を算出
for i in range(k):
    sum_ += l[2 * i] + l[2 * i + 1]
sum_ += l[2 * k]
max_ = sum_
 
#左端から0の塊を１つずつ取り替えて、最大値を算出
for i in range(k, n_group):
    sum_ -= l[2 * i - 2 * K] + l[2 * i + 1 - 2 * K]
    sum_ += l[2 * i + 1] + l[2 * i + 2]
    max_ = max(max_, sum_)
 
print(max_)
Buggy python submission (verdict: Runtime Error):
b=input()

if(b="A"):
    print("T")
else:
    print("G")


Fixed submission:
b=input()

if(b=="A"):
    print("T")
elif(b=="T"):
    print("A")
elif(b=="G"):
    print("C")
else:
    print("G")
Buggy python submission (verdict: Time Limit Exceeded):
N =int(input())
nums = [int(input()) for _ in range(N)]

v = nums 
#max(v[0:0],W[i],W[i+1])):
#1番目を除いたmax
ans_f= max(v[1:N])
print(ans_f)
#forの範囲はiは1からN-1まで
i=N-1
#print(v[i:N]) #i+1番目からN番目の要素まで
#print(v[0:i])
#print(v[i+1:N])
for i in range(1,N-1,1):
    max1=max(v[0:i])
    max2=max(v[i+1:N])
    maxp=max(max1,max2)
    print(maxp)

ans_e= max(v[0:N-1])
print(ans_e)

Fixed submission:
N =int(input())
nums = [int(input()) for _ in range(N)]

v = nums 
v_sort = sorted(v, reverse=True)
v_max=v_sort[0]
v_max2=v_sort[1]

for i in range(N):
    if(v[i]!=v_max):
        print(v_max)
    else:
        print(v_max2)
Buggy python submission (verdict: Runtime Error):
import math
A,B,C,D  = map(int, input().split())
#Cの倍数
if A % C ==0:
    C_start = A // C
else:
    C_start = (A//C)+1

C_end = B//C
C_count =-C_start+C_end+1

#Dの倍数
if A % D ==0:
    D_start = A // D
else:
    D_start = (A//D)+1

D_end = B//D
D_count =-D_start+D_end+1

#CとDの倍数
CD=C*D//math.gcd(C, D)
if A % CD ==0:
    CD_start = A // CD
else:
    CD_start = (A//CD)+1

CD_end = B//CD
CD_count =-CD_start+CD_end+1

count = (B-A+1)-(C_count +D_count -CD_count)
print(count)

Fixed submission:
A,B,C,D  = map(int, input().split())

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

#Cの倍数
if A % C ==0:
    C_start = A // C
else:
    C_start = (A//C)+1

C_end = B//C
C_count =-C_start+C_end+1

#Dの倍数
if A % D ==0:
    D_start = A // D
else:
    D_start = (A//D)+1

D_end = B//D
D_count =-D_start+D_end+1

#CとDの倍数
CD=C*D//gcd(C, D)
if A % CD ==0:
    CD_start = A // CD
else:
    CD_start = (A//CD)+1

CD_end = B//CD
CD_count =-CD_start+CD_end+1

count = (B-A+1)-(C_count +D_count -CD_count)
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

X = [0]*N

for i in range(N):
    for j in range(N):
        if j+i < N:
            tmp_A = (-1)**(j+i)*A[j+i]
        else:
            tmp_A = (-1)**(j+i)*A[j+i-N]
        X[i] += tmp_A
    if i % 2 != 0:
        X[i] *= -1
print(" ".join(map(str, X)))

Fixed submission:
N = int(input())

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

X = [0]*N

for i in range(N):
    X[0] += (-1)**(i)*A[i]

for j in range(0,N-1):
    X[j+1] = 2 * (A[j] - int(X[j]/2))

print(" ".join(map(str, X)))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

X = [0]*N

for i in range(N):
    for j in range(N):
        if j+i < N:
            tmp_A = (-1)**(j+i)*A[j+i-N]
        else:
            tmp_A = (-1)**(j+i)*A[j+i-N]
        X[i] += tmp_A
    if i % 2 != 0:
        X[i] *= -1
print(" ".join(map(str, X)))

Fixed submission:
N = int(input())

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

X = [0]*N

for i in range(N):
    X[0] += (-1)**(i)*A[i]

for j in range(0,N-1):
    X[j+1] = 2 * (A[j] - int(X[j]/2))

print(" ".join(map(str, X)))
Buggy python submission (verdict: Runtime Error):
import math

A, B, C, D = map(int, input().split())
lcm = int(C * D / math.gcd(C, D))

num_B_C = B // C
num_B_D = B // D
num_B_CD = B // (lcm)

num_A_C = (A-1) // C
num_A_D = (A-1) // D
num_A_CD = (A-1) // (lcm)

num_all = (num_B_C - num_A_C) + (num_B_D - num_A_D) - (num_B_CD - num_A_CD)
result = (B - (A-1)) - num_all

print(result)

Fixed submission:

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z
        
A, B, C, D = map(int, input().split())
lcm = int(C * D / gcd(C, D))

num_B_C = B // C
num_B_D = B // D
num_B_CD = B // (lcm)

num_A_C = (A-1) // C
num_A_D = (A-1) // D
num_A_CD = (A-1) // (lcm)

num_all = (num_B_C - num_A_C) + (num_B_D - num_A_D) - (num_B_CD - num_A_CD)
result = (B - (A-1)) - num_all

print(result)
Buggy python submission (verdict: Runtime Error):
r, D, x0 = map.(int, input().split())
x_tmp = x0

for i in range(1, 11):
  x = r * x_tmp - D
  print(x)

Fixed submission:
r, D, x0 = map(int, input().split())
x_tmp = x0
 
for i in range(1, 11):
  x = r * x_tmp - D
  x_tmp = x
  print(x)
Buggy python submission (verdict: Runtime Error):
N = int(input())

sum = 0

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

for V_i, C_i in V, C:
  diff = V_i - C_i
  if diff >= 0:
    sum += diff

print(sum)

Fixed submission:
N = int(input())

sum = 0

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

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

print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
#-*- coding:utf-8 -*-

import bisect

N, M = map(int, input().split())
A = [int(a) for a in input().split()]
BC = [0]*M
for i in range(M):
    BC[i] = [int(n) for n in  input().split()]

A.sort()    # 昇順ソートO(NlogN)
BC.sort(key=(lambda x: x[1]), reverse=True)   # Ciの値で降順ソート

for i in range(M):
    b, c = BC[i]
    # cが降順なので、入替回数が減る？
    idx = bisect.bisect_left(A, c)
    if idx > 0:
        for j in range(min(idx,b)):
            A[j] = c
        A.sort()

print(sum(A))

Fixed submission:
#-*- coding:utf-8 -*-

import bisect

N, M = map(int, input().split())
A = [int(a) for a in input().split()]
BC = [0]*M
for i in range(M):
    BC[i] = [int(n) for n in  input().split()]

A.sort()    # 昇順ソートO(NlogN)
BC.sort(key=(lambda x: x[1]), reverse=True)   # Ciの値で降順ソート

st = 0 # 編集開始位置
for i in range(M):  # O(MlogN)
    b, c = BC[i]
    idx = bisect.bisect_left(A, c, st)  # A全体でのidxを返す
    edit = idx - st # 編集個数
    edit = min(b, edit)
    for j in range(edit):
        A[st+j] = c
    st += edit

print(sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
#-*- coding:utf-8 -*-

import bisect

N, M = map(int, input().split())
A = [int(a) for a in input().split()]
B, C = [0]*M, [0]*M
for i in range(M):
    B[i], C[i] = map(int, input().split())

A.sort()    # 昇順ソートO(NlogN)

for i in range(M):
    idx = bisect.bisect_left(A, C[i])
    if idx > 0:
        for j in range(min(idx,B[i])):
            A[j] = C[i]
        A.sort()

print(sum(A))

Fixed submission:
#-*- coding:utf-8 -*-

import bisect

N, M = map(int, input().split())
A = [int(a) for a in input().split()]
BC = [0]*M
for i in range(M):
    BC[i] = [int(n) for n in  input().split()]

A.sort()    # 昇順ソートO(NlogN)
BC.sort(key=(lambda x: x[1]), reverse=True)   # Ciの値で降順ソート

st = 0 # 編集開始位置
for i in range(M):  # O(MlogN)
    b, c = BC[i]
    idx = bisect.bisect_left(A, c, st)  # A全体でのidxを返す
    edit = idx - st # 編集個数
    edit = min(b, edit)
    for j in range(edit):
        A[st+j] = c
    st += edit

print(sum(A))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

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

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

if N <= 2:
    print(max(A))
    exit()

gc = [0] * (N-1)
for i in range(0,N-1):
    gc[i] = gcd(A[i],A[i+1])
#print(gc)
# このgcで最小のものが算出されるところを書き換えればよい？
# 連続してれば共通部、連続してないなら端とか？

mnd = -1
mn = 1e10
for i in range(0, N-1):
    if mn >= gc[i]:
        mnd = i
        mn = gc[i]

if mnd == N-1 and gc[-1] < gc[-2]:
    mnd = N-1

# 連続してれば後者になるのでmndはA[i]に対応することになる
# gcの長さはN-1

B = [a for a in A if a != A[mnd]]
#print(B)

lb = len(B)
if lb >= 2:
    g = B[0]
    for i in range(1, len(B)):
        g = gcd(g, B[i])
else:
    g = B[0]
print(g)


Fixed submission:
# -*- coding: utf-8 -*-

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

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

# GCDの結合則を利用する
# 左端、右端からの累積GCDを求めておくと、Aiを取り除いた場合のGCDがすぐに計算できる。
# つまり、
# L(i): n=0,...,iまでのGCD 
# R(i): n=i,...,N-1までのGCD
# このとき、Aiを除いた全体のGCDは、GCD(L(i-1), R(i+1))で計算できる。

L = [0] * N
R = [0] * N

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

mx = 0
for i in range(N):
    if i == N-1:
        v = L[N-2]
    elif i == 0:
        v = R[1]
    else:
        v = gcd(R[i+1], L[i-1])
    mx = max(v, mx)
print(mx)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

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

# 正の数p, 負の数nに対して、p+n=N
# 全探索は2^Nで爆発

while True:
    ch = False
    for i in range(0, N-1):
        if i < N-2 and 2*A[i]+3*A[i+1]+2*A[i+2] < 0:
            A[i] *= -1
            A[i+2] *= -1
            ch = True
        if A[i] + A[i+1] < 0:
            A[i] *= -1
            A[i+1] *= -1
            ch = True
    if ch is False:
        break

print(sum(A))



Fixed submission:
# -*- coding: utf-8 -*-

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

# かっこいい解法版
# Ai, Ai+1を反転して-Ai,-Ai+1であるが、これを繰り返すことで、
# -Ai, Ai+1, Ai+2,....,Aj-1, -Aj というように、
# i < jとなるi,jのみを反転させ、間はそのままという操作が可能。
# ここから、負の数が偶数個であれば、全てを正にすることができる
# 負の数が奇数個であれば、絶対値が一番小さい数を残して残りを正にすればよい

ng = [a for a in A if a < 0]    # 負の数の抽出
ab = [abs(a) for a in A]    # 絶対値の和

if len(ng) % 2 == 0:
    print(sum(ab))
else:
    mn = min(ab)
    print(sum(ab)-2*mn)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math

# 解説見ながら記述
# 延長魔法は、合成前・合成後で実施しても等価。
# 合成魔法が使えないパターンにのみ延長魔法を使うようにして全探索するみたい

N, A, B, C = map(int, input().split())
ls = [int(input()) for i in range(N)]

def rec(cur, a, b, c):
    """
    cur: 現在のlsのindex
    a: 合成中の1本目の長さ
    b: 合成中の1本目の長さ
    c: 合成中の1本目の長さ
    """
    if cur == N:
        if min(a, b, c) > 0:
            # 合成1回目：1本目は選ぶだけで合成する必要ないので10*3を引いておく
            return abs(A-a) + abs(B-b) + abs(C-c) - 30
        else:
            # 1回も合成していない場合は無効
            return math.inf
    else:
        r0 = rec(cur+1, a, b, c)    # ls[cur]に対して何もしない
        r1 = rec(cur+1, a+ls[cur], b, c) + 10    # ls[cur]をaに合成
        r2 = rec(cur+1, a, b+ls[cur], c) + 10    # ls[cur]をbに合成
        r3 = rec(cur+1, a, b, c+ls[cur]) + 10    # ls[cur]をcに合成
        return min(r0, r1, r2, r3)

r = rec(0, 0, 0, 0)

print(r)


Fixed submission:
# -*- coding: utf-8 -*-
# import math   # math.infが使えない？(3.5から。AtCoderは3.4)

# 解説見ながら記述
# 延長魔法は、合成前・合成後で実施しても等価。
# 合成魔法が使えないパターンにのみ延長魔法を使うようにして全探索するみたい

N, A, B, C = map(int, input().split())
ls = [int(input()) for i in range(N)]
INF = 10 ** 10  # int32.max = 2*10^9より大きくしている

def rec(cur, a, b, c):
    """
    cur: 現在のlsのindex
    a: 合成中の1本目の長さ
    b: 合成中の1本目の長さ
    c: 合成中の1本目の長さ
    """
    if cur == N:
        if min(a, b, c) > 0:
            # 合成1回目：1本目は選ぶだけで合成する必要ないので10*3を引いておく
            return abs(A-a) + abs(B-b) + abs(C-c) - 30
        else:
            # 1回も合成していない場合は無効
            # return math.inf
            return INF
    else:
        r0 = rec(cur+1, a, b, c)    # ls[cur]に対して何もしない
        r1 = rec(cur+1, a+ls[cur], b, c) + 10    # ls[cur]をaに合成
        r2 = rec(cur+1, a, b+ls[cur], c) + 10    # ls[cur]をbに合成
        r3 = rec(cur+1, a, b, c+ls[cur]) + 10    # ls[cur]をcに合成
        return min(r0, r1, r2, r3)

r = rec(0, 0, 0, 0)

print(r)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

N, M = map(int, input().split())
X = [int(v) for v in input().split()]
lx = len(X)

# N=10^5, M=10^5ならO(NM)は間に合わない

# 動的計画法M個の地点を1~N個のコマで回ることを考える。
coma = [0] * N
X.sort()    # 昇順にソート

# n=1
diff = [x2-x1 for x2, x1 in zip(X[1:], X[:-1])]
diff.sort() # 昇順にソート
coma[0] = sum(diff)

if coma[0] == 0:
    print(0)
else:
    for i in range(1, N):
        coma[i] = coma[i-1] - diff[-1]
        del diff[-1]

    print(coma[-1])


Fixed submission:
# -*- coding: utf-8 -*-

N, M = map(int, input().split())
X = [int(v) for v in input().split()]
lx = len(X)

# N=10^5, M=10^5ならO(NM)は間に合わない

if N >= M:
    print(0)
else:
    # 動的計画法M個の地点を1~N個のコマで回ることを考える。

    X.sort()    # 昇順にソート
    coma = [0] * N
    # n=1
    diff = [x2-x1 for x2, x1 in zip(X[1:], X[:-1])]
    diff.sort() # 昇順にソート
    coma[0] = sum(diff)

    # n >= 2
    for i in range(1, N):
        coma[i] = coma[i-1] - diff[-1]
        del diff[-1]

    print(coma[-1])
Buggy python submission (verdict: Runtime Error):
import numpy

L, R = map(int, input().split())
l, r = L % 2019, R % 2019

if l > r or (R - L) >= 2019:
    print(0)
else:
    print(numpy.min([(i * j) % 2019 for i in range(l, r)　for j in range(i + 1, r + 1)]))

Fixed submission:
import numpy

L, R = map(int, input().split())
l, r = L % 2019, R % 2019

if l > r or (R - L) >= 2019:
    print(0)
else:
    print(numpy.min([(i * j) % 2019 for i in range(l, r) for j in range(i + 1, r + 1)]))