Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
n,k = map(int,input().split( ))
s = input()
r0 = list(reversed(s))
r = ''.join(r0)
s = s + r
l = len(s)
S = [s[i] for i in range(l)]

literal=list(set(S))
literal.sort()

small = literal[0]

i=0
mx=0
cnt = 0
now=-1
cnd=[]
while i<l:
    if s[i] == small:
        now = i
        cnt = 1
        i += 1
        try:
            while s[i] == small:
                cnt += 1
                i += 1
            if mx < cnt:
                cnd = []
                cnd.append(now)
                now == i
                mx = cnt
            elif mx == cnt:
                cnd.append(now)
                now = i
            else:
                now = i
        except:
            pass
    i += 1
if mx*2**k>=n:
    print(small*2**k)
    sys.exit
else:
    pass
cnd_string = []
addi = n - 2**k


for i in cnd:
    cnd_string.append(s[i + mx : i + mx + addi])
cnd_string.sort()
for t in cnd_string:
    if len(t) < addi:
        cnd_string.remove(t)
print(small*2**k + cnd_string[0])


Fixed submission:
import sys
S=input()
K=1

if len(S)==1:
    print(K)
    sys.exit
elif len(S)==2:
    if S[0]==S[1]:
        print(1)
        sys.exit
    else:
        print(2)
        sys.exit
else:
    pass
l=len(S)

S1=[]
S2=[]

S1.append(1)
if S[0]!=S[1]:
    S1.append(2)
else:
    S1.append(1)
S2.append(0)
S2.append(1)
for i in range(2,l):
    if S[i]!=S[i-1]:
        S1.append(max(S1[i-1]+1,S2[i-1]+1))
    else:
        S1.append(S2[i-1]+1)
    try:
        if S2[i]==S2[i-2] and S2[i-1]==S2[i-3]:
            S2.append(S1[i-2]+1)
    except:
        S2.append(max(S1[i-2]+1,S2[i-2]+1))

print(max(S2[l-1],S1[l-1]))

Buggy python submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split( )))
B=list(map(int,input().split( )))
count=0
flag=True
while flag:
    flag=False
    for i in range(-1,n-1):
        tonari=B[i-1]+B[i+1]
        tmp=(B[i]-A[i])//tonari
        if tmp>0:
            B[i]-=tonari*tmp
            count+=tmp
            flag=True
if A==B:
    print(count)
else:
    print(-1)

Fixed submission:
import sys
S=input()
K=1

if len(S)==1:
    print(K)
    sys.exit
elif len(S)==2:
    if S[0]==S[1]:
        print(1)
        sys.exit
    else:
        print(2)
        sys.exit
else:
    pass
l=len(S)

S1=[]
S2=[]

S1.append(1)
if S[0]!=S[1]:
    S1.append(2)
else:
    S1.append(1)
S2.append(0)
S2.append(1)
for i in range(2,l):
    if S[i]!=S[i-1]:
        S1.append(max(S1[i-1]+1,S2[i-1]+1))
    else:
        S1.append(S2[i-1]+1)
    try:
        if S2[i]==S2[i-2] and S2[i-1]==S2[i-3]:
            S2.append(S1[i-2]+1)
    except:
        S2.append(max(S1[i-2]+1,S2[i-2]+1))

print(max(S2[l-1],S1[l-1]))
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input())
sm=a+b,
sb=a-b
tms=a*b
mx=max(sm,sb,tms)
print(mx)

Fixed submission:
a,b=map(int,input().split( ))
sm=a+b
sb=a-b
tms=a*b
mx=max(sm,sb,tms)
print(mx)
Buggy python submission (verdict: Runtime Error):
k,x=map(int,input(),split())

ans=range(x-k+1,x+k-1)
print(*ans)

Fixed submission:
k,x=map(int,input().split())

ans=range(x-k+1,x+k)
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
p = int(input())
a = list(map(int, input().split( )))

#よくある補間だとiごとにO(p)次多項式をx-j倍する操作が入ってO(p**3),間に合わない

#editorial
#1-(x-j)**(p-1)

ans = [0 for _ in range(p)]

chs = [1]

deno = 1
nume = 1

for i in range(1,p):
    nume*=p-i
    deno *= pow(i,p-2,p)
    chs.append(nume*deno)

for i in range(p):
    if not a[i]:
        continue
    for j in range(p):
        ans[j] -= chs[j]*pow(p-i,p-j-1,p)
    ans[0]+=1
    

for i in range(p):
    ans[i]%=p 


print(*ans)
    

Fixed submission:
p = int(input())
a = list(map(int, input().split( )))

#よくある補間だとiごとにO(p)次多項式をx-j倍する操作が入ってO(p**3),間に合わない

#editorial
#1-(x-j)**(p-1)

ans = [0 for _ in range(p)]

chs = [1]

deno = 1
nume = 1

for i in range(1,p):
    nume*=p-i
    deno *= pow(i,p-2,p)
    chs.append(nume*deno%p)

#pow使っていたの修正
for i in range(p):
    tmp = 1
    if not a[i]:
        continue
    for j in range(p):
        ans[p-1-j] -= chs[p-1-j]*tmp
        tmp *= p-i
        tmp %= p
    ans[0]+=1
    

for i in range(p):
    ans[i]%=p 


print(*ans)
Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
a = list(map(int, input().split( )))

#3つ置きに一致する
S = {}
for ai in a:
    if ai in S:
        S[ai]+=1
    else:
        S[ai] = 1

if len(S)>3:
    print("No")
    sys.exit()
    
if len(S) ==3:
    A = list(S.keys())
    if A[0]==A[1]^A[2] and S[A[0]]==S[A[1]] and S[A[1]] == S[A[2]]:
        print("Yes")


elif len(S)==2:
    if S[A[0]]==0 and S[A[1]] == 2*S[A[0]]:
        print("Yes")
    elif S[A[1]]==0 and S[A[0]] == 2*S[A[1]]:
        print("Yes")
    else:
        print("No")


elif len(S)==1:
    if S.values()==[0]:
        print("Yes")
else:
    print("No")



Fixed submission:
import sys
n = int(input())
a = list(map(int, input().split( )))

#3つ置きに一致する
S = {}
for ai in a:
    if ai in S:
        S[ai]+=1
    else:
        S[ai] = 1
A = list(S.keys())
#print(S)
#print(A)
#print(list(S.keys()))
#print(S.values())
if len(S) ==3:
    if A[0]==A[1]^A[2] and S[A[0]]==S[A[1]] and S[A[1]] == S[A[2]]:
        print("Yes")
    else:
        print("No")##漏れ


elif len(S)==2:#一番の漏れ
    if A[0]==0 and S[A[1]] == 2*S[A[0]]:#S[A[0]]==0じゃない
        print("Yes")
    elif A[1]==0 and S[A[0]] == 2*S[A[1]]:
        print("Yes")
    else:
        print("No")


elif len(S)==1:
    if list(S.keys())==[0]:#1.dict_keys、dict_valuesはリストでない 2.keysのほう
        print("Yes")
    else:###
        print("No")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split( )))

#3つ置きに一致する
S = {}
for ai in a:
    if ai in S:
        S[ai]+=1
    else:
        S[ai] = 1

if len(S)>3:
    print("No")
    sys.exit()
    
if len(S) ==3:
    A = list(S.keys())
    if A[0]==A[1]^A[2] and S[A[0]]==S[A[1]] and S[A[1]] == S[A[2]]:
        print("Yes")

elif len(S) == 2:
    A = list(S.keys())
    if A[0]== 0 or  A[1]==0 and S[A[0]] == S[A[1]]:
        print("Yes")
elif len(S)==1:
    if S.values()==[0]:
        print("Yes")
else:
    print("No")

Fixed submission:
import sys
n = int(input())
a = list(map(int, input().split( )))

#3つ置きに一致する
S = {}
for ai in a:
    if ai in S:
        S[ai]+=1
    else:
        S[ai] = 1
A = list(S.keys())
#print(S)
#print(A)
#print(list(S.keys()))
#print(S.values())
if len(S) ==3:
    if A[0]==A[1]^A[2] and S[A[0]]==S[A[1]] and S[A[1]] == S[A[2]]:
        print("Yes")
    else:
        print("No")##漏れ


elif len(S)==2:#一番の漏れ
    if A[0]==0 and S[A[1]] == 2*S[A[0]]:#S[A[0]]==0じゃない
        print("Yes")
    elif A[1]==0 and S[A[0]] == 2*S[A[1]]:
        print("Yes")
    else:
        print("No")


elif len(S)==1:
    if list(S.keys())==[0]:#1.dict_keys、dict_valuesはリストでない 2.keysのほう
        print("Yes")
    else:###
        print("No")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
#editorial参照
import sys
from collections import deque
n,m = map(int, input().split( ))
G = [[] for _ in range(n)]

for _ in range(m):
    a,b = map(int, input().split( ))
    a-=1;b-=1
    G[a].append(b)
    G[b].append(a)

if m&1:
    print(-1)
    sys.exit()

Tr = [0]*n#k木に属しているか
Q = deque()
Q.append(0)
Tr[0] = 1
TrE = [[] for _ in range(n)]
P = [-1]*n#親
Leaf = []
while Q:
    v = Q.popleft()
    leaf_v = True
    for u in G[v]:
        if not Tr[u]:
            Tr[u] = 1
            P[u]=v
            TrE[v].append(u)
            Q.append(u)
            leaf_v = False
    if leaf_v:
        Leaf.append(v)

out = [0]*n
D = set()             
for v in range(n):
    for u in G[v]:
        if (u,v) not in D and P[v]!=u and P[u]!=v:
            D.add((v,u))
            out[v]^=1
            

"""
幅優先探索で葉から辿ったところ、
すべての子を考慮する前にpのdegreeが決まってしまっている。
深さ優先探索に修正
"""
def dfs(x = 0, parent = -1):
    for y in TrE[x]:
        if y == parent:
            continue
        dfs(y,x)
        if out[y]:
            D.add((y,x))
            out[y] ^= 1
        else:
            D.add((x,y))
            out[x] ^= 1
 
dfs()

for u,v in D:
    print(u+1,v+1)

Fixed submission:
#editorial参照

import sys
from collections import deque
sys.setrecursionlimit(200000)

n,m = map(int, input().split( ))
G = [[] for _ in range(n)]

for _ in range(m):
    a,b = map(int, input().split( ))
    a-=1;b-=1
    G[a].append(b)
    G[b].append(a)

if m&1:
    print(-1)
    sys.exit()

Tr = [0]*n#k木に属しているか
Q = deque()
Q.append(0)
Tr[0] = 1
TrE = [[] for _ in range(n)]
P = [-1]*n#親
Leaf = []
while Q:
    v = Q.popleft()
    leaf_v = True
    for u in G[v]:
        if not Tr[u]:
            Tr[u] = 1
            P[u]=v
            TrE[v].append(u)
            Q.append(u)
            leaf_v = False
    if leaf_v:
        Leaf.append(v)

out = [0]*n
D = set()             
for v in range(n):
    for u in G[v]:
        if (u,v) not in D and P[v]!=u and P[u]!=v:
            D.add((v,u))
            out[v]^=1
            

"""
幅優先探索で葉から辿ったところ、
すべての子を考慮する前にpのdegreeが決まってしまっている。
深さ優先探索に修正
"""
def dfs(x = 0, parent = -1):
    for y in TrE[x]:
        if y == parent:
            continue
        dfs(y,x)
        if out[y]:
            D.add((y,x))
            out[y] ^= 1
        else:
            D.add((x,y))
            out[x] ^= 1
 
dfs()

for u,v in D:
    print(u+1,v+1)
Buggy python submission (verdict: Runtime Error):
l, r = map(int, input().split( ))
ans = []
if r - l>=2019:
  print(0)
else:
  for i in range(l,r):
    for j in range(i+1,r+1):
      tmp = i*j%2019
      ans.append(tmp)
      
print(min(ans))

Fixed submission:
l, r = map(int, input().split( ))
ans = []
if r - l>=2019:
    print(0)
else:
    for i in range(l,r):
        for j in range(i+1,r+1):
            tmp = i*j%2019
            ans.append(tmp)
    print(min(ans))

Buggy python submission (verdict: Runtime Error):
l, r = map(int, input().split( ))
ans = []
if r - l>=2019:
  print(0)
else:
  for i in range(l,r):
    for j in range(i+1,r+1):
      tmp = i*j%2019
      ans.append(tmp)
      
pritn(mimn(ans))

Fixed submission:
l, r = map(int, input().split( ))
ans = []
if r - l>=2019:
    print(0)
else:
    for i in range(l,r):
        for j in range(i+1,r+1):
            tmp = i*j%2019
            ans.append(tmp)
    print(min(ans))
Buggy python submission (verdict: Time Limit Exceeded):
#editorial参照
#そもそもの漸化式
#2次元累積和
#dp累積和のdpを含む漸化式 & dp消せる
n,m = map(int, input().split( ))

s = list(map(int, input().split( )))
t = list(map(int, input().split( )))

mod = 10**9 + 7

dp_sum = [[0]*(m+1) for _ in range(n+1)]

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp_sum[i][j] = dp_sum[i-1][j] + dp_sum[i][j-1] + 1
            dp_sum[i][j] %= mod
        else:
            dp_sum[i][j] = dp_sum[i-1][j] + dp_sum[i][j-1] - dp_sum[i-1][j-1]
            dp_sum[i][j] %= mod
#print(dp_sum)
print(dp_sum[n-1][m-1]+1)#空集合で+1



Fixed submission:
#editorial参照
#そもそもの漸化式
#2次元累積和
#dp累積和のdpを含む漸化式 & dp消せる
n,m = map(int, input().split( ))

s = list(map(int, input().split( )))
t = list(map(int, input().split( )))

mod = 10**9 + 7

dp_sum = [[0]*(m+1) for _ in range(n+1)]

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp_sum[i][j] = dp_sum[i-1][j] + dp_sum[i][j-1] + 1
            dp_sum[i][j] %= mod
        else:
            dp_sum[i][j] = dp_sum[i-1][j] + dp_sum[i][j-1] - dp_sum[i-1][j-1]
            dp_sum[i][j] %= mod
#print(dp_sum)
print(dp_sum[n-1][m-1]+1)#空集合で+1
Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split( ))
a = [] 
mod = 10**9+7
for _ in range(m):
    a.append(int(input()))

dp = [0]*(n+1)
dp[0] = 1
if a[0]!=1:
    dp[1] = 1

A = set(a)
 
for i in range(2,n+1):
    if i not in A:
        dp[i] = (dp[i-1]+dp[i-2])%mod
print(dp[n])




Fixed submission:
import sys
n,m = map(int, input().split( ))
a = [] 

mod = 10**9+7
for _ in range(m):
    a.append(int(input()))

dp = [0]*(n+1)
dp[0] = 1
dp[1] = 1
if a:
    if a[0]==1:
        dp[1] = 0

A = set(a)
 
for i in range(2,n+1):
    if i not in A:
        dp[i] = (dp[i-1]+dp[i-2])%mod
print(dp[n])
Buggy python submission (verdict: Runtime Error):
mod = 1000003
"""
for i in range(2,57000):
    if n%i==0:
        print("nonPrime")
        exit()
print("prime")
"""
q = int(input())
fct = [0]
tmp = 1
for i in range(1,mod):
    tmp *=i
    tmp%=mod
    fct.append(tmp)
for i in range(q):
    x,d,n = map(int, input().split( ))
    if d%mod == 0:
        print(pow(x,mod-2,mod))
        continue
    if n>=mod:
        print(0)
        continue
    rev_d = pow(d,mod-2,mod)
    x*=rev_d
    x%=mod
    tmp = pow(d,n,mod)
    tmp*=fct[x+n-1]
    if x>=1:
        tmp*=pow(fct[x-1],mod-2,mod)
    tmp%=mod
    print(tmp)

Fixed submission:
mod = 1000003
"""
for i in range(2,57000):
    if n%i==0:
        print("nonPrime")
        exit()
print("prime")
"""
q = int(input())
fct = [0]
tmp = 1
for i in range(1,mod+3):
    tmp *=i
    tmp%=mod
    fct.append(tmp)
for i in range(q):
    x,d,n = map(int, input().split( ))
    if d%mod == 0:
        print(pow(x,n,mod))
        continue
    if n>=mod:
        print(0)
        continue
    rev_d = pow(d,mod-2,mod)
    x*=rev_d
    x%=mod
    tmp = pow(d,n,mod)
    try:
        tmp*=fct[x+n-1]
    except:
        print(0)
        continue
    if x>=2:
        tmp*=pow(fct[x-1],mod-2,mod)
    tmp%=mod
    print(tmp)
Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split( ))

mod = 10**9 + 7

def chs(a,b, md):
    res = 1
    for i in range(a-b+1,a+1):
        res *=  i
        res %= md
    rev = 1
    for i in range(1,b+1):
        rev *= i
        rev %= md
    rev2 = pow(rev,md-2,md)
    
    res *= rev2
    res %= md
    
    return res

ans = 0

for i in range(1,n):
    ans += chs(n*m-2,k-2,mod)*i*(n-i)*m**2
    ans %= mod

        

for i in range(1,m):
    ans += chs(n*m-2,k-2,mod)*i*(m-i)*n**2
    ans %=mod
    
print(ans)


Fixed submission:
n, m, k = map(int, input().split( ))

mod = 10**9 + 7

def chs(a,b, md):
    res = 1
    for i in range(a-b+1,a+1):
        res *=  i
        res %= md
    rev = 1
    for i in range(1,b+1):
        rev *= i
        rev %= md
    rev2 = pow(rev,md-2,md)
    
    res *= rev2
    res %= md
    
    return res

ans = 0
c = chs(n*m-2,k-2,mod)

for i in range(1,n):
    ans += i*(n-i)*m**2
    ans %= mod

        

for i in range(1,m):
    ans +=i*(m-i)*n**2
    ans %=mod
ans *= c
ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
#n//m=kかつn%m=kはつまりn=k(m+1)、また、k<m

n=int(input())
fct =[]

sq = int(n**(1/2))+2
ans = 0
for i in range(1,sq):
    if n%i==0:
        j = n//i-1
        if n//j==n%j:#境界処理が面倒なので試す
            ans +=j

print(ans)



Fixed submission:
#n//m=kかつn%m=kはつまりn=k(m+1)、また、k<m

n=int(input())

sq = int(n**(1/2))+2
ans = 0
for i in range(1,sq):
    if n%i==0:
        j = n//i-1
        if j:#nが小さいと0になる？
            if n//j==n%j:#境界処理が面倒なので試す
                ans +=j

print(ans)
Buggy python submission (verdict: Runtime Error):
#(ai,ai+1),(ai+1,ai+2)...(aj-1,aj)に-1を掛けると
#ai,ajに-1を掛けることができる

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

mns = [ai for ai in a if ai<0]
pls = [ai for ai in a if ai>=0]

mns.sort()
pls.sort()

lm = len(mns)
m_rem = 0
if lm%2:
    if pls[0]<-1*mns[-1]:
        tmp = -1*mns[-1]
        mns[-1] = -1*pls[0]
        pls[0] = tmp
    m_rem = mns.pop()

print(sum(pls)-sum(mns) + m_rem)

Fixed submission:
#(ai,ai+1),(ai+1,ai+2)...(aj-1,aj)に-1を掛けると
#ai,ajに-1を掛けることができる

n = int(input())
a = list(map(int, input().split()))
n=len(a)
mns = [ai for ai in a if ai<0]
pls = [ai for ai in a if ai>=0]

mns.sort()
pls.sort()
#print(mns)
#print(pls)
lm = len(mns)
m_rem = 0
if lm%2:
    if pls:
        if pls[0]<-1*mns[-1]:
            tmp = -1*mns[-1]
            mns[-1] = -1*pls[0]
            pls[0] = tmp
    m_rem = mns.pop()

print(sum(pls)-sum(mns) + m_rem)

Buggy python submission (verdict: Runtime Error):
#(ai,ai+1),(ai+1,ai+2)...(aj-1,aj)に-1を掛けると
#ai,ajに-1を掛けることができる

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

mns = [ai for ai in a if ai<0]
pls = [ai for ai in a if ai>=0]

mns.sort()
pls.sort()

lm = len(mns)
m_rem = 0
if lm%2:
    if pls[0]<-1*mns[-1]:
        tmp = -1*mns[-1]
        mns[-1] = -1*pls[0]
        pls[0] = tmp
    m_rem = mns.pop()

print(sum(pls)-sum(mns) + m_rem)

Fixed submission:
#(ai,ai+1),(ai+1,ai+2)...(aj-1,aj)に-1を掛けると
#ai,ajに-1を掛けることができる

n = int(input())
a = list(map(int, input().split()))
n=len(a)
mns = [ai for ai in a if ai<0]
pls = [ai for ai in a if ai>=0]

mns.sort()
pls.sort()
#print(mns)
#print(pls)
lm = len(mns)
m_rem = 0
if lm%2:
    if pls:
        if pls[0]<-1*mns[-1]:
            tmp = -1*mns[-1]
            mns[-1] = -1*pls[0]
            pls[0] = tmp
    m_rem = mns.pop()

print(sum(pls)-sum(mns) + m_rem)
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.read
*x,=map(int, input().split("\n"))
tmp=100
for i in range(5):
    if x[i]%10:
        tmp = min(tmp,x[i]%10)
        x[i]//=10
        x[i]*= 10
        x[i]+=10
ans= sum(x)
if tmp<100:
    ans-=10
    ans+=tmp
print(ans)
    


Fixed submission:
#import sys
#input=sys.stdin.read
#*x,=map(int, input().split("\n"))
x=[int(input()) for _ in range(5)]
tmp=100
for i in range(5):
    if x[i]%10:
        tmp = min(tmp,x[i]%10)
        x[i]//=10
        x[i]*= 10
        x[i]+=10
ans= sum(x)
if tmp<100:
    ans-=10
    ans+=tmp
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.read
*x,=map(int, input().split("\n"))
tmp=100
for i in range(5):
    if x[i]%10:
        tmp = min(tmp,x[i]%10)
        x[i]//=10
        x[i]*= 10
        x[i]+=10
ans= sum(x)
if tmp<100:
    ans-=10
    ans+=tmp
print(ans)
    


Fixed submission:
#import sys
#input=sys.stdin.read
#*x,=map(int, input().split("\n"))
x=[int(input()) for _ in range(5)]
tmp=100
for i in range(5):
    if x[i]%10:
        tmp = min(tmp,x[i]%10)
        x[i]//=10
        x[i]*= 10
        x[i]+=10
ans= sum(x)
if tmp<100:
    ans-=10
    ans+=tmp
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.read
*x,=map(int, input().split("\n"))
tmp=100
for i in range(5):
    if x[i]%10:
        tmp = min(tmp,x[i]%10)
        x[i]//=10
        x[i]*= 10
        x[i]+=10
ans= sum(x)
if tmp<100:
    ans-=10
    ans+=tmp
print(ans)
    


Fixed submission:
#import sys
#input=sys.stdin.read
#*x,=map(int, input().split("\n"))
x=[int(input()) for _ in range(5)]
tmp=100
for i in range(5):
    if x[i]%10:
        tmp = min(tmp,x[i]%10)
        x[i]//=10
        x[i]*= 10
        x[i]+=10
ans= sum(x)
if tmp<100:
    ans-=10
    ans+=tmp
print(ans)
Buggy python submission (verdict: Runtime Error):
import fractions

n = int(input())
a = list(map(int, input().split( )))
ans = 0
for i in range(n):
    ans = math.gcd(ans,a[i])
print(ans)

Fixed submission:
import fractions

n = int(input())
a = list(map(int, input().split( )))
ans = 0
for i in range(n):
    ans = fractions.gcd(ans,a[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
import math

n = int(input())
a = list(map(int, input().split( )))
ans = 0
for i in range(n):
    ans = math.gcd(ans,a[i])
print(ans)

Fixed submission:
import fractions

n = int(input())
a = list(map(int, input().split( )))
ans = 0
for i in range(n):
    ans = fractions.gcd(ans,a[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
#どの 2 つの街の間も、道を何本か通ることで行き来することができる
cnts=[0]*4
for i in range(3):
    ai,bi=map(int, input().split())
    ai-=1;bi-=1
    cnts[ai]+=1;cnts[bi]+=1
for i in range(4):
    if cnts>2:
        print("NO")
        exit()
print("YES")


Fixed submission:
#どの 2 つの街の間も、道を何本か通ることで行き来することができる
cnts=[0]*4
for i in range(3):
    ai,bi=map(int, input().split())
    ai-=1;bi-=1
    cnts[ai]+=1;cnts[bi]+=1
for i in range(4):
    if cnts[i]>2:
        print("NO")
        exit()
print("YES")
Buggy python submission (verdict: Runtime Error):
#editorial参照
import sys
input = sys.stdin.read
n,*a, = map(int, input().split( ))
m = min(a)
ans = (n+m-1)//m + 4
print(ans)


Fixed submission:
n=int(input())
*h,=map(int, input().split())
import numpy as np
h=np.array(h)

def rec(hh):
    if len(hh)==0:
        return 0
    if len(hh)==1:
        return hh[0]
    i=np.argmin(hh)
    res=hh[i]
    l=rec(hh[:i]-hh[i])
    r=rec(hh[i+1:]-hh[i])
    return res+l+r
print(rec(h))
Buggy python submission (verdict: Runtime Error):
n,a,b=map(int, input().split())
*p,=map(int, input().split())
mn,md,mx=0,0,0
for pi in p:
    if pi<=a:
        mn+=1
    elif pi<=b:
        md+=1
    else:
        mx+=1
print(min(mn,md,mx))


Fixed submission:
n=int(input())
a,b=map(int, input().split())
*p,=map(int, input().split())
mn,md,mx=0,0,0
for pi in p:
    if pi<=a:
        mn+=1
    elif pi<=b:
        md+=1
    else:
        mx+=1
print(min(mn,md,mx))
Buggy python submission (verdict: Runtime Error):
n,w_max = map(int,input().split())
w = [0]
v = [0]

for _ in range(n):
    W,V = map(int,input().split())
    w.append(W)
    v.append(V)
v_sum = sum(v)
lrg = 10**12
dp = [[lrg]*(v_sum+1) for i in range(n+1)]
for i in range(n+1):
    dp[i][0] = 0
for i in range(1,n+1):
    for u in range(v_sum+1):
        if u>=v[i]:
            dp[i][u] = min(dp[i-1][u-v[i]]+w[i],dp[i-1][u])
        else:###
            dp[i][u] = min(w[i],dp[i-1][u])

ans = []
for u in range(v_sum+1):
    if dp[n][u] <= w_max:
        ans.append(u)
#print(*dp[n])
print(max(ans))


Fixed submission:
n = int(input())
h = list(map(int, input().split( )))
dp =[0,0]

dp[1] = abs(h[1]-h[0])

for i in range(2,n):
    ad0 = abs(h[i]-h[i-1])
    ad1 = abs(h[i]-h[i-2])
    dp.append(min(dp[i-1]+ad0,dp[i-2]+ad1))
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
n, m = map(int, input().split( ))
Edg = [[] for _ in range(n)]
#rev_Edg =  [[] for _ in range(n)]

Visited = [0]*n
Root_check = [1]*n
Dist = [0]*n
for i in range(m):
    v1,v2 = map(int, sys.stdin.readline().split( ))
    v1-=1
    v2-=1
    Edg[v1].append(v2)
    Root_check[v2] = 0
    
Roots = []
for i in range(n):
    if Root_check[i] == 1:
        Roots.append(i)
Q =deque()
for r in Roots:
    Q.append(r)
    while len(Q) > 0:
        v = Q.popleft()
        for w in Edg[v]:
            Dist[w] = max(Dist[w],Dist[v] +1)####
            Q.append(w)

print(max(Dist))


Fixed submission:
import sys
from collections import deque
n, m = map(int, input().split( ))
Edg = [[] for _ in range(n)]
rev_Edg = [[] for _ in range(n)]
deg = [len(rev_Edg[i]) for i in range(n)]


Root_check = [1]*n
Dist = [0]*n
for i in range(m):
    v1,v2 = map(int, sys.stdin.readline().split( ))
    v1-=1
    v2-=1
    Edg[v1].append(v2)
    rev_Edg[v2].append(v1)
    deg[v2] += 1
    Root_check[v2] = 0
    

Q =deque()
for i in range(n):
    if Root_check[i] == 1:
        Q.append(i)

while len(Q) > 0:
    v = Q.popleft()
    for w in Edg[v]:
        Dist[w] = max(Dist[w],Dist[v] +1)####
        deg[w] -=1 ############
        if deg[w] == 0:##########
            Q.append(w)###########
            


print(max(Dist))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n, m = map(int, input().split( ))
Edg = [[] for _ in range(n)]

Root_check = [1]*n
Dist = [0]*n
for i in range(m):
    v1,v2 = map(int, input().split( ))
    v1-=1
    v2-=1
    Edg[v1].append(v2)
    Root_check[v2] = 0
    
Roots = []
for i in range(n):
    if Root_check[i] == 1:
        Roots.append(i)
Q = deque()
for r in Roots:
    Q.append(r)
    while len(Q) > 0:
        v = Q.popleft()
        for w in Edg[v]:
            Dist[w] = max(Dist[w],Dist[v] +1)####
            Q.append(w)

print(max(Dist))


Fixed submission:
import sys
from collections import deque
n, m = map(int, input().split( ))
Edg = [[] for _ in range(n)]
rev_Edg = [[] for _ in range(n)]
deg = [len(rev_Edg[i]) for i in range(n)]


Root_check = [1]*n
Dist = [0]*n
for i in range(m):
    v1,v2 = map(int, sys.stdin.readline().split( ))
    v1-=1
    v2-=1
    Edg[v1].append(v2)
    rev_Edg[v2].append(v1)
    deg[v2] += 1
    Root_check[v2] = 0
    

Q =deque()
for i in range(n):
    if Root_check[i] == 1:
        Q.append(i)

while len(Q) > 0:
    v = Q.popleft()
    for w in Edg[v]:
        Dist[w] = max(Dist[w],Dist[v] +1)####
        deg[w] -=1 ############
        if deg[w] == 0:##########
            Q.append(w)###########
            


print(max(Dist))