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

I=[0]

for i in range(n-1):
    if s[i]!=s[i+1]:
        I.append(i+1)
        
r=len(I)

for _ in range(10**5):
        I.append(n)

X=[]

for i in range(r):
    if s[I[i]]=='0':
        X.append(I[i+2*k]-I[i])
    else:
        X.append(I[i+2*k+1]-I[i])

print(max(X))

Fixed submission:

n,k=map(int,input().split())
s=input()

I=[0]

for i in range(n-1):
    if s[i]!=s[i+1]:
        I.append(i+1)
        
r=len(I)

for _ in range(10**6):
        I.append(n)

X=[]

for i in range(r):
    if s[I[i]]=='0':
        X.append(I[i+2*k]-I[i])
    else:
        X.append(I[i+2*k+1]-I[i])

print(max(X))

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

I=[0,]

for i in range(n-1):
    if s[i]!=s[i+1]:
        I.append(i+1)

if len(I)<k:
    for _ in range(10**5):
        I.append(n)

print(I)

X=[]

for i in range(len(I)):
    if s[I[i]]=='0':
        X.append(I[i+2*k]-I[i])
    else:
        X.append(I[i+2*k+1]-I[i])

print(max(X))

Fixed submission:

n,k=map(int,input().split())
s=input()

I=[0]

for i in range(n-1):
    if s[i]!=s[i+1]:
        I.append(i+1)
        
r=len(I)

for _ in range(10**6):
        I.append(n)

X=[]

for i in range(r):
    if s[I[i]]=='0':
        X.append(I[i+2*k]-I[i])
    else:
        X.append(I[i+2*k+1]-I[i])

print(max(X))

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

I=[0,]

for i in range(n-1):
    if s[i]!=s[i+1]:
        I.append(i+1)

if len(I)<k:
    I.extend([n]*(10**5))

X=[]

for i in range(len(I)):
    if s[I[i]]=='0':
        X.append(I[i+2*k]-I[i])
    else:
        X.append(I[i+2*k+1]-I[i])

print(max(X))

Fixed submission:

n,k=map(int,input().split())
s=input()

I=[0]

for i in range(n-1):
    if s[i]!=s[i+1]:
        I.append(i+1)
        
r=len(I)

for _ in range(10**6):
        I.append(n)

X=[]

for i in range(r):
    if s[I[i]]=='0':
        X.append(I[i+2*k]-I[i])
    else:
        X.append(I[i+2*k+1]-I[i])

print(max(X))

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

I=[0,]

for i in range(n-1):
    if s[i]!=s[i+1]:
        I.append(i+1)

if len(I)<k:
    I.extend([n+1]*(2*k+1))

X=[]

for i in range(len(I)):
    if s[I[i]]=='0':
        X.append(I[i+2*k]-I[i])
    else:
        X.append(I[i+2*k+1]-I[i])

print(max(X))

Fixed submission:

n,k=map(int,input().split())
s=input()

I=[0]

for i in range(n-1):
    if s[i]!=s[i+1]:
        I.append(i+1)
        
r=len(I)

for _ in range(10**6):
        I.append(n)

X=[]

for i in range(r):
    if s[I[i]]=='0':
        X.append(I[i+2*k]-I[i])
    else:
        X.append(I[i+2*k+1]-I[i])

print(max(X))

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

I=[0,]

for i in range(n-1):
    if s[i]!=s[i+1]:
        I.append(i+1)

if len(I)<k:
    I.extend([n+1]*(k-len(I)))

X=[]

for i in range(len(I)):
    if s[I[i]]=='0':
        X.append(I[i+2*k]-I[i])
    else:
        X.append(I[i+2*k+1]-I[i])

print(max(X))

Fixed submission:

n,k=map(int,input().split())
s=input()

I=[0]

for i in range(n-1):
    if s[i]!=s[i+1]:
        I.append(i+1)
        
r=len(I)

for _ in range(10**6):
        I.append(n)

X=[]

for i in range(r):
    if s[I[i]]=='0':
        X.append(I[i+2*k]-I[i])
    else:
        X.append(I[i+2*k+1]-I[i])

print(max(X))

Buggy python submission (verdict: Runtime Error):

n,k=map(int,input().split())
s=input()

X=[]
cnt=0
if len(s)>=2:
    for i in range(n-1):
        cnt+=1
        if s[i]=='0' and s[i+1]=='1':
            X.append(cnt)
            cnt=0
        elif s[i]=='1' and s[i+1]=='0':
            X.append(cnt)
            cnt=0
        elif i==n-2:
            X.append(cnt)
    
    if s[-1]!=s[-2]:
        X.append(1)
    else:
        X[-1]+=1
else:
    X=[s]


if s[0]=='1':
    if k>=len(X[1::2]):
        print(n)
    else:
        z=X[1::2]
        o=X[::2]
        ans=sum(o[:k+1])+sum(z[:k])
        for i in range(len(z)-k):
            ans=max(ans,ans-z[i]-o[i]+z[i+k]+o[i+k+1])
        print(ans)
else:
    if k>=len(X[0::2]):
        print(n)
    else:
        z=X[::2]
        o=X[1::2]
        ans=sum(z[:k])+sum(o[:k])
        for i in range(len(o)-k):
            ans=max(ans,ans-o[i]-z[i]+o[i+k]+z[i+k+1])
        print(ans)

Fixed submission:

n,k=map(int,input().split())
s=input()

I=[0]

for i in range(n-1):
    if s[i]!=s[i+1]:
        I.append(i+1)
        
r=len(I)

for _ in range(10**6):
        I.append(n)

X=[]

for i in range(r):
    if s[I[i]]=='0':
        X.append(I[i+2*k]-I[i])
    else:
        X.append(I[i+2*k+1]-I[i])

print(max(X))