Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math

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

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

def primelist(n):
    P = [2]
    flag = 0
    for i in range(3,n+1,2):
        for j in range(len(P)):
            if math.sqrt(i) < P[j]:
                break
            else:
                if i%P[j] == 0:
                    flag += 1
                    break
        if flag == 0:
            P.append(i)
        flag = 0
    P.append(1)
    return(P)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr[-1][0]

N=gcd(A,B)

if N==1:
    print(1)
else:
    ms = factorization(N)
    pl = primelist(ms)
    ans=0
    for i in range(len(pl)):
        if N%pl[i]==0:
            ans+=1
    print(ans)

Fixed submission:
N=int(input())
k=0
for i in range(N+1):
    if i%2==1:
        k+=1
print(k/N)
Buggy python submission (verdict: Time Limit Exceeded):
N,K,Q = map(int, input().split())
A = [int(input()) for i in range(Q)]
score = [K]*N

for i in range(Q):
    score[A[i]-1] += 1
    for j in range(N):
        score[j] -= 1

for i in range(N):
    if score[i] <= 0:
        print('No')
    else:
        print('Yes')

Fixed submission:
N,K,Q = map(int, input().split())
A = [int(input()) for i in range(Q)]
score = [0]*N

for i in range(Q):
    score[A[i]-1] += 1

for i in range(N):
    print('YNeos'[score[i] + K <= Q::2])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A= []
for i in range(N-1):
    A.append(i+2)

A.append(1)

count = 0

for i in range(N):
    count += (i+1)%A[i]

print(count)

Fixed submission:
N = int(input())
print(N*(N-1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [list(input()) for i in range(N)]

for i in range(N):
    S[i] = sorted(S[i])

count = 0

for i in range(N):
    for j in range(i+1,N):
        if S[i] == S[j]:
            count += 1

print(count)

Fixed submission:
N = int(input())
S = [list(input()) for i in range(N)]

for i in range(N):
    S[i] = sorted(S[i])

S = sorted(S)
count = 0

a = [1]
for i in range(N-1):
    if S[i] == S[i+1]:
        a[-1] += 1
    else:
        a.append(1)
    
for i in range(len(a)):
    count += a[i]*(a[i]-1)/2
        
count = int(count)
        
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
count = 0

for i in range(N):
    while A[i] != 0 and B[i] != 0:
        A[i] -= 1
        B[i] -= 1
        count += 1
    while A[i+1] != 0 and B[i] != 0:
        A[i+1] -= 1
        B[i] -= 1
        count += 1

print(count)


Fixed submission:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
count = 0

for i in range(N):
    if A[i] != 0 and B[i] != 0:
        k = min(A[i],B[i])
        A[i] -= k
        B[i] -= k
        count += k
    if A[i+1] != 0 and B[i] != 0:
        l = min(A[i+1],B[i])
        A[i+1] -= l
        B[i] -= l
        count += l

print(count)
Buggy python submission (verdict: Runtime Error):
l,r = map(int,input().split())
L = l%2019
R = r%2019  #2019 = 3*673
N = r-l+1

if N >= 2019 or L>R:
    print(0)
else:
    ans = l*(l+1)%2019
    for i in range(L,R):  #この時点でL<Rは決定済み
        for j in range(i+1,R+1):
            ans = min(ans,(j*i)%2019)
        if ans == 0:
            break

print(ans)

Fixed submission:
l,r = map(int,input().split())
L = l%2019
R = r%2019  #2019 = 3*673
N = r-l+1

if N >= 2019 or L>R:
    print(0)
else:
    ans = l*(l+1)%2019
    for i in range(L,R):  #この時点でL<Rは決定済み
        for j in range(i+1,R+1):
            ans = min(ans,(j*i)%2019)
        if ans == 0:
            break
    print(ans)

Buggy python submission (verdict: Runtime Error):
l,r = map(int,input().split())
L = l%2019
R = r%2019  #2019 = 3*673
N = r-l+1

if N >= 2019 or L>R:
    print(0)
else:
    ans = l*(l+1)%2019
    for i in range(L,R):  #この時点でL<Rは決定済み
        for j in range(i+1,R+1):
            if (i*j)%2019 < ans:
                ans = (i*j)%2019
                if ans == 0:
                    break
        if ans == 0:
            break

print(ans)

Fixed submission:
l,r = map(int,input().split())
L = l%2019
R = r%2019  #2019 = 3*673
N = r-l+1

if N >= 2019 or L>R:
    print(0)
else:
    ans = l*(l+1)%2019
    for i in range(L,R):  #この時点でL<Rは決定済み
        for j in range(i+1,R+1):
            ans = min(ans,(j*i)%2019)
        if ans == 0:
            break
    print(ans)

Buggy python submission (verdict: Runtime Error):
l,r = map(int,input().split())
L = l%2019
R = r%2019  #2019 = 3*673
N = r-l+1

if N >= 2019 or L>R:
    print(0)
else:
    ans = l*(l+1)%2019
    for i in range(L,R):  #この時点でL<Rは決定済み
        for j in range(i+1,R+1):
            if (i*j)%2019 < ans:
                ans = (i*j)%2019
                if ans == 0:
                    break

print(ans)

Fixed submission:
l,r = map(int,input().split())
L = l%2019
R = r%2019  #2019 = 3*673
N = r-l+1

if N >= 2019 or L>R:
    print(0)
else:
    ans = l*(l+1)%2019
    for i in range(L,R):  #この時点でL<Rは決定済み
        for j in range(i+1,R+1):
            ans = min(ans,(j*i)%2019)
        if ans == 0:
            break
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
L,R = map(int,input().split())
ans = L*(L+1)%2019

for i in range(L,R):
    for j in range(i+1,R+1):
        if (i*j)%2019 < ans:
            ans = (i*j)%2019

print(ans)

Fixed submission:
l,r = map(int,input().split())
L = l%2019
R = r%2019  #2019 = 3*673
N = r-l+1

if N >= 2019 or L>R:
    print(0)
else:
    ans = l*(l+1)%2019
    for i in range(L,R):  #この時点でL<Rは決定済み
        for j in range(i+1,R+1):
            ans = min(ans,(j*i)%2019)
        if ans == 0:
            break
    print(ans)
Buggy python submission (verdict: Runtime Error):
import heapq
N,K=map(int,input().split())
V=list(map(int,input().split()))

#a:左からとる b:右からとる K-a-b:捨てる
score=0
torikata=[]
for d in range(101):
    for a in range(101):
        for b in range(101):
            if d+a+b<=K:
                torikata.append((a,b,d))

for i in range(len(torikata)):
    A,B,D=torikata[i][0],torikata[i][1],torikata[i][2]
    H=[]
    for i in range(A):
        H.append(V[i])
    for i in range(B):
        H.append(V[-(i+1)])
    heapq.heapify(H)
    for i in range(min(D,A+B)):
        heapq.heappop(H)
    score=max(score,sum(H))

print(score)

Fixed submission:
import heapq
N,K=map(int,input().split())
V=list(map(int,input().split()))

#a:左からとる b:右からとる K-a-b:捨てる
score=0
torikata=[]
for d in range(101):
    for a in range(101):
        for b in range(101):
            if d+a+b<=K and a+b<=N:
                torikata.append((a,b,d))

for i in range(len(torikata)):
    A,B,D=torikata[i][0],torikata[i][1],torikata[i][2]
    H=[]
    for i in range(A):
        H.append(V[i])
    for i in range(B):
        H.append(V[-(i+1)])
    heapq.heapify(H)
    for i in range(min(D,A+B)):
        heapq.heappop(H)
    score=max(score,sum(H))

print(score)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
G=[]
for i in range(N-1):
    u,v,w=map(int,input().split())
    u-=1;v-=1
    G.append([u,v,w])
G.sort()
col=[-1 for i in range(N)]
col[0]=0

from collections import deque
G=deque(G)

while len(G)>0:
    e=G.popleft()
    if col[e[0]]!=-1:
        col[e[1]]=(e[2]+col[e[0]])%2
    elif col[e[1]]!=-1:
        col[e[0]]=(e[2]+col[e[1]])%2
    else:
        G.append(e)

for i in col:
    print(i)

Fixed submission:
N=int(input())
G=[[] for i in range(N)]
for i in range(N-1):
    u,v,w=map(int,input().split())
    u-=1; v-=1; w%=2
    G[u].append([v,w])
    G[v].append([u,w])
col=[-1 for i in range(N)]
col[0]=0

from collections import deque
dq=deque([0])

while len(dq)>0:
    p=dq.popleft()
    for i in range(len(G[p])):
        if col[G[p][i][0]]==-1:
            dq.append(G[p][i][0])
            col[G[p][i][0]]=(col[p]+G[p][i][1])%2
        
for i in col:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
UVW=[list(map(int,input().split())) for i in range(N-1)]
UVW.sort(key=lambda x:x[1])
UVW.sort()
L=[-1]*(N+1)
L[1]=0

while -1 in L[1:]:
    for i in range(N-1):
        if L[UVW[i][0]]==0:
            if UVW[i][2]%2==0:
                L[UVW[i][1]]=0
            else:
                L[UVW[i][1]]=1
        elif L[UVW[i][0]]==1:
            if UVW[i][2]%2==0:
                L[UVW[i][1]]=1
            else:
                L[UVW[i][1]]=0
        else:
            if L[UVW[i][1]]==0:
                if UVW[i][2]%2==0:
                    L[UVW[i][0]]=0
                else:
                    L[UVW[i][0]]=1
            elif L[UVW[i][1]]==1:
                if UVW[i][2]%2==0:
                    L[UVW[i][0]]=1
                else:
                    L[UVW[i][0]]=0

L.pop(0)
for i in L:
    print(i)

Fixed submission:
N=int(input())
G=[[] for i in range(N)]
for i in range(N-1):
    u,v,w=map(int,input().split())
    u-=1; v-=1; w%=2
    G[u].append([v,w])
    G[v].append([u,w])
col=[-1 for i in range(N)]
col[0]=0

from collections import deque
dq=deque([0])

while len(dq)>0:
    p=dq.popleft()
    for i in range(len(G[p])):
        if col[G[p][i][0]]==-1:
            dq.append(G[p][i][0])
            col[G[p][i][0]]=(col[p]+G[p][i][1])%2
        
for i in col:
    print(i)
Buggy python submission (verdict: Runtime Error):
def ranlength(A):
    num = list(A)
    count = 1
    result = ''
    table = []
    for i in range(len(num)):
        try:
            if num[i] == num[i+1]:
               count = count + 1
            else:
                result += str(num[i]) + str(count)
                table.append(count)
                count = 1
        except:
            result += str(num[i]) + str(count)
            table.append(count)
    return(table)
    
N,K=map(int,input().split())
S=input()

RL=ranlength(S)
#print(RL)

#しゃくとり法
if int(S[0])==1:
    cnt1=RL[0]
    ans1=RL[0]
    for i in range(len(RL)):
        if i%2==0 and i>=2:
            cnt1+=RL[i]
            cnt1+=RL[i-1]
            if i>=K*2+2:
                cnt1-=RL[i-(K*2+1)]
                cnt1-=RL[i-(K*2+2)]
            ans1=max(ans1,cnt1)
            #print(cnt1)
    print(ans1)
elif int(S[0])==0:
    cnt2=RL[0]+RL[1]
    ans2=RL[0]+RL[1]
    for i in range(len(RL)):
        if i%2==1 and i>=3:
            cnt2+=RL[i]
            cnt2+=RL[i-1]
            if i>=K*2+1:
                cnt2-=RL[i-(K*2+1)]
                cnt2-=RL[i-(K*2)]
            ans2=max(ans2,cnt2)
            #print(cnt2)
    print(ans2)


Fixed submission:
def ranlength(A):
    num = list(A)
    count = 1
    result = ''
    table = []
    for i in range(len(num)):
        try:
            if num[i] == num[i+1]:
               count = count + 1
            else:
                result += str(num[i]) + str(count)
                table.append(count)
                count = 1
        except:
            result += str(num[i]) + str(count)
            table.append(count)
    return(table)
    
N,K=map(int,input().split())
S=input()

RL=ranlength(S)
if S[0]=='0':
    RL=[0]+RL
if S[-1]=='0':
    RL.append(0)

#しゃくとり法
cnt=RL[0]
ans=RL[0]
for i in range(len(RL)):
    if i%2==0 and i>=2:
        cnt+=RL[i]
        cnt+=RL[i-1]
        if i>=K*2+2:
            cnt-=RL[i-(K*2+1)]
            cnt-=RL[i-(K*2+2)]
        ans=max(ans,cnt)
        #print(cnt)
print(ans)
Buggy python submission (verdict: Runtime Error):
ABCDE = []
for i in range(5):
    ABCDE.append(int(input()))
K = int(input())

out = 0
for i in range(5):
    for j in range(i+1,5):
        if ABCDE[j] - ABCDE[i] > K:
            out += 1
            break

print(['Yay!',':('][out])

Fixed submission:
ABCDE = []
for i in range(5):
    ABCDE.append(int(input()))
K = int(input())

out = 0
for i in range(5):
    for j in range(i+1,5):
        if ABCDE[j] - ABCDE[i] > K:
            out += 1
            break

if out == 0:
    print('Yay!')
else:
    print(':(')
Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
LR=[]
for i in range(Q):
    LR.append(list(map(int, input().split())))
A=[0]*N

for i in range(N-1):
    if S[i]=='A' and S[i+1]=='C':
        A[i]+=1

for i in range(Q):
    print(sum(A[LR[i][0]-1:LR[i][1]])\
          - int(A[LR[i][1]-1]==1))

Fixed submission:
N,Q=map(int,input().split())
S=input()
LR=[]
for i in range(Q):
    LR.append(list(map(int, input().split())))

L=[0]*N
R=[0]*N
for i in range(N-1):
    if S[i]=='A' and S[i+1]=='C':
        L[i]+=1
for i in range(1,N):
    L[i]+=L[i-1]

for i in range(1,N):
    if S[i]=='C' and S[i-1]=='A':
        R[i]+=1
for i in range(1,N):
    R[i]+=R[i-1]

for i in range(Q):
    print(min(L[LR[i][1]-1],R[LR[i][1]-1])-\
          min(L[LR[i][0]-1],R[LR[i][0]-1]))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().split()))

if N%2==1:
    A.append(A[-1])

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

P=[]
for i in range(len(A)//2):
    P.append(gcd(A[2*i],A[2*i+1]))

ans=1
for i in range(1,min(P)+1):
    g=1
    for j in range(len(P)):
        if P[j]%i!=0:
            g-=1
            break
    if g==1:
        ans=i

print(ans)

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

def gcd_list(L):
    b=min(L)
    for i in L:
        while True:
            if i%b==0:
                break
            c=b
            b=i%b
            i=c
    return(b)

print(gcd_list(A))

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

import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

print(gcd_list(A))

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

def gcd_list(L):
    b=min(L)
    for i in L:
        while True:
            if i%b==0:
                break
            c=b
            b=i%b
            i=c
    return(b)

print(gcd_list(A))
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=list(map(int,input().split()))

T=[0,2,5,5,4,5,6,3,7,6]
B=[]
for i in A:
    B.append(T[i])
B=sorted(list(set(B)))
dp=[0 for i in range(N+1)]
AB=[[i,T[i]] for i in A]
AB=sorted(AB,reverse=True)

for i in range(1,N+1):
    for j in B:
        if i-j>=0 and dp[i-j]!=-1:
            dp[i]=max(dp[i],dp[i-j]+1)
            #print(i,j,dp[i])
    if dp[i]==0:
        dp[i]=-1
#print(dp)
#print(AB)

c=N
U=[0 for i in range(8)]
while c>0:
    for i in range(len(AB)):
        if dp[c]==dp[c-AB[i][1]]+1:
            U[AB[i][1]]+=1
            c-=AB[i][1]
            break
#print(U)

ans=""
if 9 in A:
    ans+='9'*U[6]
    U[6]=0
if 8 in A:
    ans+='8'*U[7]
if 7 in A:
    ans+='7'*U[3]
if 6 in A:
    ans+='6'*U[6]
if 5 in A:
    ans+='5'*U[5]
    U[5]=0
if 4 in A:
    ans+='4'*U[4]
if 3 in A:
    ans+='3'*U[5]
    U[5]=0
if 2 in A:
    ans+='2'*U[5]
if 1 in A:
    ans+='1'*U[2]

print(ans)

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

T=[0,2,5,5,4,5,6,3,7,6]
B=[]
for i in A:
    B.append(T[i])
B=sorted(list(set(B)))
dp=[0 for i in range(N+1)]
AB=[[i,T[i]] for i in A]
AB=sorted(AB,reverse=True)

for i in range(1,N+1):
    for j in B:
        if i-j>=0 and dp[i-j]!=-1:
            dp[i]=max(dp[i],dp[i-j]+1)
            #print(i,j,dp[i])
    if dp[i]==0:
        dp[i]=-1
#print(dp)
#print(AB)

c=N
U=[0 for i in range(8)]
while c>0:
    for i in range(len(AB)):
        if c-AB[i][1]>=0 and dp[c]==dp[c-AB[i][1]]+1:
            U[AB[i][1]]+=1
            c-=AB[i][1]
            break
#print(U)

ans=""
if 9 in A:
    ans+='9'*U[6]
    U[6]=0
if 8 in A:
    ans+='8'*U[7]
if 7 in A:
    ans+='7'*U[3]
if 6 in A:
    ans+='6'*U[6]
if 5 in A:
    ans+='5'*U[5]
    U[5]=0
if 4 in A:
    ans+='4'*U[4]
if 3 in A:
    ans+='3'*U[5]
    U[5]=0
if 2 in A:
    ans+='2'*U[5]
if 1 in A:
    ans+='1'*U[2]

print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
H=list(map(int,input().split()))

def dp(x):
    if x==0:
        return 0
    elif x==1:
        return abs(H[1]-H[0])
    else:
        a=dp(x-1)+abs(H[x]-H[x-1])
        b=dp(x-2)+abs(H[x]-H[x-2])
        return min(a,b)

print(dp(N-1))

Fixed submission:
import numpy as np

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

dp=np.empty(N,dtype=int)
dp[0]=0
dp[1]=abs(H[1]-H[0])

for i in range(2,N):
    a=dp[i-1]+abs(H[i]-H[i-1])
    b=dp[i-2]+abs(H[i]-H[i-2])
    dp[i]=min(a,b)

print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,W=map(int,input().split())
w=[0 for _ in range(110)]
v=[0 for _ in range(110)]
for i in range(1,N+1):
    w[i],v[i]=map(int,input().split())
dp=[[0 for i in range(110000)] for j in range(110)]
for i in range(1,110000):
    dp[0][i]=10**15

for i in range(1,N+1):
    for j in range(110000):
        dp[i][j]=dp[i-1][j]
        if j-v[i]>=0:
            dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i])

ans=0
for V in range(110000):
    if dp[N][V]<=W:
        ans=max(ans,V)

print(ans)

Fixed submission:
N,W=map(int,input().split())
w=[0 for _ in range(110)]
v=[0 for _ in range(110)]
for i in range(1,N+1):
    w[i],v[i]=map(int,input().split())
dp=[[0 for i in range(110000)] for j in range(110)]
for i in range(1,110000):
    dp[0][i]=10**15

for i in range(1,N+1):
    for j in range(110000):
        dp[i][j]=dp[i-1][j]
        if j-v[i]>=0:
            dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i])

ans=0
for V in range(110000):
    if dp[N][V]<=W:
        ans=max(ans,V)

print(ans)
Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
S=[]
for i in range(H):
    S.append(input())
T=[]
for i in range(H):
    T.append([])
    for j in range(W):
        T[-1].append(int(S[i][j]=='#'))

#横
for i in range(H):
    if T[i].count(1)==0:
        for j in range(W):
            T[i][j]=2

#縦
for i in range(W):
    tate=0
    for j in range(H):
        if T[j][i]!=1:
            tate+=1
    if tate==H:
        for j in range(H):
            T[j][i]=2

A=[]
for i in range(H):
    A.append([])
    for j in range(W):
        if T[i][j]!=2:
            A[i].append('#.'[T[i][j]==0])

for i in range(H-1):
    if len(A[i])==0:
        A.pop(i)

for i in range(len(A)):
    print(''.join(A[i]))

Fixed submission:
H,W=map(int,input().split())
A=[input() for i in range(H)]

#'#'が入っている行および列を列挙する
Tate=[0]*H
Yoko=[0]*W
for i in range(H):
    for j in range(W):
        if A[i][j]=='#':
            Tate[i]+=1
            Yoko[j]+=1

ans=['']*H
for i in range(H):
    for j in range(W):
        if Tate[i]*Yoko[j]>0:
            ans[i]+=A[i][j]

for i in ans:
    if i!='':
        print(i)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
X=list(map(int,input().split()))
X.sort()
ans=10**10

for i in range(N-K+1):
    L=X[i:i+K]
    if L[0]>0 and L[0]*L[-1]>0:
        ans=min(ans,L[-1])
    elif L[0]<0 and L[0]*L[-1]>0:
        ans=min(ans,-L[0])
    else:
        ans=L[-1]-L[0]+min(L[-1],-L[0])

print(ans)

Fixed submission:
N,K=map(int,input().split())
X=list(map(int,input().split()))
X.sort()
ans=10**10

for i in range(N-K+1):
    R=X[i+K-1]
    L=X[i]
    A=[ans, abs(L)+abs(R-L), abs(R)+abs(R-L)]
    ans=min(A)

print(ans)

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
X=list(map(int,input().split()))

cost=10**10

Plus=[i for i in X if i>=0]
Minus=[-i for i in X if i<=0]

if len(Plus)>=K:
    cost=Plus[K-1]
if len(Minus)>=K:
    cost=min(cost,Minus[-K])

i=0
while X[i]<0 and i<=K:
    if i+K-1<N:
        cost=min(cost,X[i+K-1]-X[i]+abs(X[i]))
    i+=1

print(cost)

Fixed submission:
N,K=map(int,input().split())
X=list(map(int,input().split()))
X.sort()
ans=10**10

for i in range(N-K+1):
    R=X[i+K-1]
    L=X[i]
    A=[ans, abs(L)+abs(R-L), abs(R)+abs(R-L)]
    ans=min(A)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
X=list(map(int,input().split()))

cost=10**10

Plus=[i for i in X if i>=0]
Minus=[-i for i in X if i<=0]

if len(Plus)>=K:
    cost=Plus[K-1]
if len(Minus)>=K:
    cost=min(cost,Minus[-K])

i=0
while X[i]<0 and i+K-1<N:
    L=[j-X[i] for j in X]
    cost=min(cost,L[i+K-1]+abs(X[i]))
    i+=1

print(cost)

Fixed submission:
N,K=map(int,input().split())
X=list(map(int,input().split()))
X.sort()
ans=10**10

for i in range(N-K+1):
    R=X[i+K-1]
    L=X[i]
    A=[ans, abs(L)+abs(R-L), abs(R)+abs(R-L)]
    ans=min(A)

print(ans)

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
X=list(map(int,input().split()))

cost=10**10
P=X.copy()
i=0
while P[i]<0:
    P.pop(0)
if len(P)>=K:
    cost=P[K-1]    

for i in range(N-K+1):
    if X[i] >= 0:
        break
    else:
        L=[j-X[i] for j in X]
        cost=min(cost,L[i+K-1]+abs(X[i]))

print(cost)

Fixed submission:
N,K=map(int,input().split())
X=list(map(int,input().split()))
X.sort()
ans=10**10

for i in range(N-K+1):
    R=X[i+K-1]
    L=X[i]
    A=[ans, abs(L)+abs(R-L), abs(R)+abs(R-L)]
    ans=min(A)

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

i=0
while S[i]=='1':
    i+=1

print([1,S[i]][K>i])

Fixed submission:
S=input()
K=int(input())

i=0
while S[i]=='1' and i<len(S)-1:
    i+=1

print([1,S[i]][K>i])
Buggy python submission (verdict: Time Limit Exceeded):
def find_root(root,x):
    y = root[x]
    if x == y:
        return x
    z = find_root(root,y)
    root[x] = z
    return z
 
def merge(root,size,x,y):
    x = find_root(root,x)
    y = find_root(root,y)
    if x == y:
        return
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    size[x] += sy
    
def UF_check(root,x,y):
    if find_root(root,x) == find_root(root,y):
        return True
    else:
        return False
    
def UF_make(graph,n):  #グラフと最大項を与えると、塊ごとにグルーピングする
    Root=list(range(n+1))
    Size=[1] * (n+1)
    for i in range(len(graph)):
        merge(Root,Size,graph[i][0],graph[i][1])
    for i in range(n+1):  #これを入れれば、UF_checkを使わずに一塊になる
        Root[i] = find_root(Root,i)
    Root.pop(0)  #
    return Root

N,M=map(int,input().split())
P=list(map(int,input().split()))
XY=[list(map(int,input().split())) for i in range(M)]

UF=UF_make(XY,N)
#print(UF)

groups=[[] for i in range(N+1)]
for i in range(N):
    groups[UF[i]].append(P[i])

#print(groups)
ans=0
for i in range(N):
    if i+1 in groups[UF[i]]:
        ans+=1

print(ans)

Fixed submission:
def find_root(root,x):
    y = root[x]
    if x == y:
        return x
    z = find_root(root,y)
    root[x] = z
    return z
 
def merge(root,size,x,y):
    x = find_root(root,x)
    y = find_root(root,y)
    if x == y:
        return
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    size[x] += sy
    
def UF_check(root,x,y):
    if find_root(root,x) == find_root(root,y):
        return True
    else:
        return False
    
def UF_make(graph,n):  #グラフと最大項を与えると、塊ごとにグルーピングする
    Root=list(range(n+1))
    Size=[1] * (n+1)
    for i in range(len(graph)):
        merge(Root,Size,graph[i][0],graph[i][1])
    for i in range(n+1):  #これを入れれば、UF_checkを使わずに一塊になる
        Root[i] = find_root(Root,i)
    Root.pop(0)  #
    return Root

N,M=map(int,input().split())
P=list(map(int,input().split()))
XY=[list(map(int,input().split())) for i in range(M)]

UF=UF_make(XY,N)
#print(UF)

groups=[[] for i in range(N+1)]
for i in range(N):
    groups[UF[i]].append(P[i])

for i in range(N+1):
    groups[i].sort()

import bisect
ans=0
for i in range(N):
    num=bisect.bisect_left(groups[UF[i]],i+1)
    if num!=len(groups[UF[i]]) and groups[UF[i]][num]==i+1:
        ans+=1

print(ans)