Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02706 (python)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
ct = 0
for i in range(m):
    ct += a[i]

if n - ct >= 0:
    print(n - ct)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split)
a = list(map(int, input().split()))
ct = 0
for i in range(m):
    ct += a[i]

if n - ct >= 0:
    print(n - ct)
else:
    print(-1)
Problem p02784 (python)

Fixed submission:
# ABC153
# B Common Raccoon VS Monster
h, n = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
if h <= s:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):

# ABC153
# B Common Raccoon VS Monster
h, n = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
if a <= s:
    print("Yes")
else:
    print("No")
Problem p02945 (python)

Fixed submission:

a, b = map(int, input().split())
x = a + b
y = a - b
z = a * b
O = [x,y,z]
O = sorted(O,reverse=1)
print(O[0])

Buggy submission (verdict: Runtime Error):

a, b = map(int, input().split())
x = a + b
y = a - b
z = a * b
O = [x,y,z]
O = sorted(O,reverse=1)
print(O[0]

Buggy submission (verdict: Runtime Error):
a, b = map(int,input().split())
x = a + b
y = a - b
z = a * b
O = sorted(list(x, y, z),reverse=True)
print(O[0])
Problem p02946 (python)

Fixed submission:

# ABC138
# B One Clue
# K個連続黒、Xが黒、座標-1000000+1000000
k, x = map(int, input().split())
L = []
for i in range(k):
    y = x + i
    z = x - i
    if y > 1000000:
        y = x
    L.append(y)
    if z < -1000000:
        z = x
    L.append(z)
I = set(L)
L = list(sorted(I))
for s in L:
    print(s,end = " ")

Buggy submission (verdict: Runtime Error):
L = []
for i in range(k):
    y = x + i
    z = x - i
    if y > 1000000:
        y = x
    L.append(y)
    if z < -1000000:
        z = x
    L.append(z)
I = set(L)
for s in I:
    print(s,end = "")

Buggy submission (verdict: Runtime Error):
k, x = map(int, input().split())
L = []
for i in range(k):
    y = x + i
    z = x - i
    if y > 1000000:
        y = x
    L.append(y)
    if z < -1000000:
        z = x
    L.append(z)
printset((L))
Problem p02999 (python)

Fixed submission:
# A Rounding

x, a = map(int, input().split())
if x < a:
    print(0)
else:
    print(10)

Buggy submission (verdict: Runtime Error):
x, a = map(int, input())
if x < a:
    print(0)
else:
    print(10)

Buggy submission (verdict: Runtime Error):
# A Rounding
x, a = map(int, input())
if x < a:
    print(0)
else:
    print(1o)
Problem p03105 (python)

Fixed submission:
a, b, c = map(int, input().split())
if a * c > b:
    print(b//a)
else:
    print(c)

Buggy submission (verdict: Runtime Error):
a, b, c = map(input().split())
if a * c > b:
    print(b//a)
else:
    print(c)
Problem p02628 (python)

Fixed submission:
from numpy import cumsum
n,k=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
p=cumsum(p)
print((p[k-1]))

Buggy submission (verdict: Runtime Error):
from numpy import cumsum
n,k=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
p=cumsum(p)
print((p[k-1]))
Problem p03161 (python)

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0] + [float('inf')]*(n-1)
for i in range(n):
    for j in range(max(0,i-k),i):
        dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
c=input()
print(chr(ord(c)+1))
Problem p03473 (python)

Fixed submission:
i=int(input())
print(48-i)

Buggy submission (verdict: Runtime Error):
i=(48-i)
print(input())

Buggy submission (verdict: Runtime Error):
print(48-i)
i=int(input())
Problem p02588 (python)

Fixed submission:
def how(c):
    if float(c).is_integer() == True:
        return int(float(c)),0
    else:
        dot=0
        while c[dot]!=".":
            dot+=1
        c = list(c)
        del c[dot]
        c ="".join(c)
        return int(c),len(c)-dot

def lo2(n):
    count = 0
    while n%2==0:
        n=n//2
        count+=1
    return count

def lo5(n):
    count=0
    while n%5==0:
        n=n//5
        count+=1
    return count

N = int(input())

A = []

for i in range(N):
    A.append(how(input()))


ruiseki = [[0]*120 for i in range(120)]

motoseisuu=0
for i in range(N):
    ruiseki[A[i][1]-lo2(A[i][0])+60][A[i][1]-lo5(A[i][0])+60]+=1
    if A[i][1]==0:
        motoseisuu +=1

for i in range(1,120):
    for j in range(1,120):
        ruiseki[i][j]=ruiseki[i-1][j]+ruiseki[i][j-1]-ruiseki[i-1][j-1]+ruiseki[i][j]


ans = 0
for i in range(N):
    ans+=ruiseki[lo2(A[i][0])+60-A[i][1]][lo5(A[i][0])+60-A[i][1]]

print((ans-motoseisuu)//2)

Buggy submission (verdict: Runtime Error):
def how(c):
    if float(c).is_integer() == True:
        return int(float(c)),0
    else:
        dot=0
        while c[dot]!=".":
            dot+=1
        c = list(c)
        del c[dot]
        c ="".join(c)
        return int(c),len(c)-dot

def lo2(n):
    count = 0
    while n%2==0:
        n=n//2
        count+=1
    return count

def lo5(n):
    count=0
    while n%5==0:
        n=n//5
        count+=1
    return count

N = int(input())

A = []

for i in range(N):
    A.append(how(input()))


ruiseki = [[0]*80 for i in range(80)]

motoseisuu=0
for i in range(N):
    ruiseki[A[i][1]-lo2(A[i][0])+60][A[i][1]-lo5(A[i][0])+60]+=1
    if A[i][1]==0:
        motoseisuu +=1

for i in range(1,80):
    for j in range(1,80):
        ruiseki[i][j]=ruiseki[i-1][j]+ruiseki[i][j-1]-ruiseki[i-1][j-1]+ruiseki[i][j]


ans = 0
for i in range(N):
    ans+=ruiseki[lo2(A[i][0])+60-A[i][1]][lo5(A[i][0])+60-A[i][1]]

print((ans-motoseisuu)//2)
Problem p02761 (python)

Fixed submission:
N,M = map(int,input().split())
n = [0]*N
n_used = [False]*N
if N > 1:
    n[0]=1
for i in range(0,M,1):
    s,c = map(int,input().split())
    if (n_used[s-1] and n[s-1]!=c) or (s==1 and c ==0 and N != 1):
        print(-1)
        exit()
    else:
        n[s-1]=c
        n_used[s-1]=True
st = "".join(list(map(str,n)))
print(st)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
n = [0]*N
n_used = [False]*N
if N > 1:
    n[0]=1
for i in range(0,M,1):
    s,c = map(int,input().split())
    if (n_used[s-1] and n[s-1]!=c) or (s==1 and c ==0 and N != 1):
        print(-1)
        exit()
    else:
        n[s-1]=c
        n_used[s-1]=True

print("{}{}{}".format(n[0],n[1],n[2]))
Problem p02813 (python)

Fixed submission:
import itertools

N = int(input())
P = input()
Q = input()
pn =0
qn =0
count =0
for x in itertools.permutations(range(1,N+1,1)):
    count+=1
    tmp = " ".join(list(map(str,x)))
    if tmp == P:
        pn = count
    if tmp == Q:
        qn = count
print(abs(qn-pn))

Buggy submission (verdict: Runtime Error):
pn =0
qn =0
count =0
for x in itertools.permutations(range(1,N+1,1)):
    count+=1
    tmp = " ".join(list(map(str,x)))
    if tmp == P:
        pn = count
    if tmp == Q:
        qn = count
print(abs(qn-pn))
Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
N = int(input())
nood = [[]for i in range(0,N+1,1)]
h_color = [1]*(N+1)
for i in range(1,N,1):
    a,b=map(int,input().split())
    nood[a].append([b,i])
    nood[b].append([a,i])

max_color_count = -1

def bfs(nowNood,preNood,preColor):
    global max_color_count
    colorCount=1
    for i in range(0,len(nood[nowNood]),1):
        if nood[nowNood][i][0]!=preNood:
            if colorCount == preColor:
                colorCount+=1
            h_color[nood[nowNood][i][1]]=colorCount
            bfs(nood[nowNood][i][0],nowNood,colorCount)
            max_color_count = max(max_color_count,colorCount)
            colorCount+=1

bfs(1,-1,-1)
print(max_color_count)
for i in range(1,N,1):
    print(h_color[i])

Buggy submission (verdict: Runtime Error):
N = int(input())
nood = [[]for i in range(0,N+1,1)]
h_color = [1]*(N+1)
for i in range(1,N,1):
    a,b=map(int,input().split())
    nood[a].append([b,i])
    nood[b].append([a,i])

max_color_count = -1

def bfs(nowNood,preNood,preColor):
    global max_color_count
    colorCount=1
    for i in range(0,len(nood[nowNood]),1):
        if nood[nowNood][i][0]!=preNood:
            if colorCount == preColor:
                colorCount+=1
            h_color[nood[nowNood][i][1]]=colorCount
            bfs(nood[nowNood][i][0],nowNood,colorCount)
            max_color_count = max(max_color_count,colorCount)
            colorCount+=1

bfs(1,-1,-1)
print(max_color_count)
for i in range(1,N,1):
    print(h_color[i])

Buggy submission (verdict: Runtime Error):
N = int(input())
nood = [[]for i in range(0,N+1,1)]
h_color = [1]*(N+1)
for i in range(1,N,1):
    a,b=map(int,input().split())
    nood[a].append([b,i])
    nood[b].append([a,i])

max_color_count = -1
def bfs(nowNood,preNood,preColor):
    global max_color_count
    colorCount=1
    for i in range(0,len(nood[nowNood]),1):
        if nood[nowNood][i][0]!=preNood:
            if colorCount == preColor:
                colorCount+=1
            h_color[nood[nowNood][i][1]]=colorCount
            bfs(nood[nowNood][i][0],nowNood,colorCount)
        max_color_count = max(max_color_count,colorCount)
        colorCount+=1

bfs(1,-1,-1)
print(max_color_count)
for i in range(1,N,1):
    print(h_color[i])
Problem p02900 (python)

Fixed submission:
import math

A,B = map(int,input().split())
G = math.gcd(A,B)

N = G
#素因数分解
sep = []
for i in range(2,int(math.sqrt(N))+2,1):
    if N % i ==0:
        count = 0
        while N % i == 0:
            N = N//i
            count += 1
        sep.append([i,count])
if N != 1:
    sep.append([N,1])

print(len(sep)+1)

Buggy submission (verdict: Runtime Error):
import math

A,B = map(int,input().split())
G = math.gcd(A,B)
count = 0
p = 1
for i in range(1,math.ceil(math.sqrt(G))+1,1):
    if G%i ==0:
        if math.gcd(p,i)==1:
            count +=1
            p = p*i
print(count)

Buggy submission (verdict: Runtime Error):
import fractions as math

A,B = map(int,input().split())
G = math.gcd(A,B)
count = 0
p = 1
for i in range(1,math.ceil(math.sqrt(G))+1,1):
    if G%i ==0:
        if math.gcd(p,i)==1:
            count +=1
            p = p*i
print(count)

Buggy submission (verdict: Runtime Error):
import math

A,B = map(int,input().split())
G = math.gcd(A,B)
count = 0
p = 1
for i in range(1,math.ceil(math.sqrt(G))+1,1):
    if G%i ==0:
        if math.gcd(p,i)==1:
            count +=1
            p = p*i
print(count)
Problem p02909 (python)

Fixed submission:
S = input()
dic = {"Sunny":"Cloudy","Rainy":"Sunny","Cloudy":"Rainy"}
print(dic[S])

Buggy submission (verdict: Runtime Error):
S = input()
dic = {"Sunny":"Cloudy","Rainy":"Sunny","Cloudy":"Rainy"}
print(dic(S))
Problem p02936 (python)

Fixed submission:
from collections import deque 
#スタック
s = deque([])

N,Q = map(int,input().split())
node = [[]for i in range(0,N+1,1)]
for i in range(0,N-1,1):
    a,b = map(int,input().split())
    node[a].append(b)
    node[b].append(a)
node_score = [0]*(N+1)#スコア
for i in range(0,Q,1):
    p,x = map(int,input().split())
    node_score[p] += x

ans = [0]*(N+1)

s.append([1,0])
while len(s) > 0:
    n,preN = s.pop()
    ans[n] = ans[preN]+node_score[n]
    for to in node[n]:
        if to != preN:
            s.append([to,n])

print(" ".join(list(map(str,ans[1:N+1]))))

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
node = [[]for i in range(0,N+1,1)]
for i in range(0,N-1,1):
    a,b = map(int,input().split())
    node[a].append(b)
node_score = [0]*(N+1)#スコア
for i in range(0,Q,1):
    p,x = map(int,input().split())
    node_score[p] += x

ans = [0]*(N+1)
def bfs(n,preN):
    ans[n] = ans[preN]+node_score[n]
    for to in node[n]:
        if to != preN:
            bfs(to,n)
bfs(1,0)
print(" ".join(list(map(str,ans[1:N+1]))))
Problem p03101 (python)

Fixed submission:
H,W = map(int,input().split())
h,w = map(int,input().split())
print((H-h)*(W-w))

Buggy submission (verdict: Runtime Error):
H,W = map(int,input())
h,w = map(int,input())
print((H-h)*(W-w))
Problem p03106 (python)

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

wari = []
count = 0
for i in range(1,A+B):
    if A%i==0 and B%i==0:
        wari.append(i)
print(wari[len(wari)-K])

Buggy submission (verdict: Runtime Error):
A,B,K = map(int,input().split())

wari = []
count = 0
for i in range(1,A+B):
    if A%i==0 and B%i==0:
        if count == K:
            wari.append(i)
print(wari[len(wari)-K])

Buggy submission (verdict: Runtime Error):
A,B,K = map(int,input().split())

count = 0
for i in range(A+B):
    if A%i==0 and B%i==0:
        count +=1
        if count == K:
            print(i)
            break
Problem p03111 (python)

Fixed submission:
#bit全探索の亜種(4種全探索)
#itertools.product([0,1,2,3],repeat=N)

import itertools
N,A,B,C = map(int,input().split())
l = [int(input()) for i in range(0,N,1)]

ans = 10**10
for ABCD in itertools.product([0,1,2,3],repeat=N):
    tmp = [[] for i in range(4)]
    for i in range(0,N,1):
        tmp[ABCD[i]].append(l[i])
    score = 0
    owaowari = False
    for i in range(3):#Dはくっ付ける必要なし
        if len(tmp[i])==0:
            owaowari = True
            break
        score+=10*max(len(tmp[i])-1,0)
    if owaowari: continue
    score+=abs(A-sum(tmp[0]))
    score+=abs(B-sum(tmp[1]))
    score+=abs(C-sum(tmp[2]))
    ans = min(ans,score)


print(ans)

Buggy submission (verdict: Runtime Error):
#bit全探索の亜種(4種全探索)
#itertools.product([0,1,2,3],repeat=N)

import itertools
N,A,B,C = map(int,input().split())
l = [int(input()) for i in range(0,N,1)]

ans = 10**10
for ABCD in itertools.product([0,1,2,3],repeat=N):
    tmp = [[] for i in range(4)]
    for i in range(0,N,1):
        tmp[ABCD[i]].append(l[i])
    score = 0
    owaowari = False
    for i in range(3):#Dはくっ付ける必要なし
        if len(tmp[i])==0:
            owaowari = True
            break
        score+=10*max(len(tmp[i])-1,0)
    if owaowari: continue
    score+=abs(A-sum(tmp[0]))
    score+=abs(B-sum(tmp[1]))
    score+=abs(C-sum(tmp[2]))
    ans = min(ans,score)
    if score == 120:

print(ans)
Problem p03112 (python)

Fixed submission:
import bisect
 
A, B, Q = map(int, input().split())
INF = float('inf')
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
 
for i in range(Q):
    x = int(input())
    b = bisect.bisect_right(s, x)
    d = bisect.bisect_right(t, x)
    ans = INF
    for S in [s[b-1], s[b]]:
        for T in [t[d-1], t[d]]:
            ans1 = abs(S-x) + abs(S-T)
            ans2 = abs(T-x) + abs(T-S)
            ans = min(ans, ans1, ans2)
    print(ans)

Buggy submission (verdict: Runtime Error):
#左右それぞれで一番近い神社
#その神社それぞれの左右それぞれで一番近い寺
#はい２ぶたん
from bisect import bisect_right

A,B,Q = map(int,input().split())
s = [int(input())for i in range(A)]
t = [int(input())for i in range(B)]

ans = []
for i in range(0,Q,1):
    q = int(input())
    sr = min(bisect_right(s,q),A-1)
    sl = max(0,sr-1)

    tr = min(bisect_right(t,q),B-1)
    tl = max(0,sl-1)


    ans.append(min(
    abs(q-s[sr])+ abs(t[min(bisect_right(t,s[sr]),B-1)]-s[sr]),
    abs(q-s[sl])+ abs(t[min(bisect_right(t,s[sl]),B-1)]-s[sl]),
    abs(q-t[tr])+ abs(s[min(bisect_right(s,t[tr]),A-1)]-t[tr]),
    abs(q-t[tl])+ abs(s[min(bisect_right(s,t[tl]),A-1)]-t[tl]),
    abs(q-s[sr])+ abs(t[max(bisect_right(t,s[sr])-1,0)]-s[sr]),
    abs(q-s[sl])+ abs(t[max(bisect_right(t,s[sl])-1,0)]-s[sl]),
    abs(q-t[tr])+ abs(s[max(bisect_right(s,t[tr])-1,0)]-t[tr]),
    abs(q-t[tl])+ abs(s[max(bisect_right(s,t[tl])-1,0)]-t[tl]))
    )

for i in range(0,Q,1):
    print(ans[i])
Problem p03260 (python)

Fixed submission:
A,B =map(int,input().split())
for i in range(1,4,1):
    if (A*B*i) %2 ==1:
        print("Yes")
        exit()
print("No")

Buggy submission (verdict: Runtime Error):
A,B =map(int,input().split())
for i in range(1,4,1):
    if (A*B*C) %2 ==1:
        print("Yes")
print("No")
Problem p03362 (python)

Fixed submission:
#サンプルが罠ってパターンもあるんだぜ


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError("n is int-type.")
    if n < 2:
        raise ValueError("n is more than 2")
    data = [i for i in range(2, n + 1)]
    for d in data:
        data = [x for x in data if (x == d or x % d != 0)]
    return data

N = int(input())
primes = get_sieve_of_eratosthenes(5000)
ans=[]

inde=0
while len(ans)<N:
    if primes[inde]%5 == 1:
        ans.append(primes[inde])
    inde+=1

print(" ".join(list(map(str,ans))))

Buggy submission (verdict: Runtime Error):
#サンプルが罠ってパターンもあるんだぜ


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError("n is int-type.")
    if n < 2:
        raise ValueError("n is more than 2")
    data = [i for i in range(2, n + 1)]
    for d in data:
        data = [x for x in data if (x == d or x % d != 0)]
    return data

N = int(input())
primes = get_sieve_of_eratosthenes(5000)
ans=[]

inde=0
while len(ans)<N:
    if primes[inde]%5 == 1:
        ans.append(primes[inde])
    inde+=1

print(" ".join(ans))
Problem p03386 (python)

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

for i in range(A,B+1,1):
    if i-A < K or B-i < K:
        print(i)

Buggy submission (verdict: Runtime Error):
A,B,K = map(int,input().split())

X = list(range(A,B+1,1))
ans = X[0:K]+X[len(X)-K:len(X)]
ans = list(set(ans))
for i in range(len(ans)):
    print(ans[i])
Problem p03695 (python)

Fixed submission:
is_alive = [0]*8#各ランク

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

count_over=0

for i in range(0,N,1):
    if a[i]>=3200:
        count_over +=1
    else:
        is_alive[a[i]//400]=1

print(max(1,sum(is_alive)),sum(is_alive)+count_over)

Buggy submission (verdict: Runtime Error):
is_alive = [0]*8#各ランク

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

count_over=0

for i in range(0,N,1):
    if a[i]>=3200:
        count_over +=1
    else:
        is_alive[a[i]//400]=1

print(max(1,sum(is_alive)),min(sum(is_alive)+count_over))
Problem p03069 (python)

Fixed submission:
from collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
bs = [0] * (N + 1)
ws = [0] * (N + 1)
total = float("inf")
left_b = 0
right_w = 0
for i, s in enumerate(S):
    if s == "#":
        left_b += 1
    bs[i + 1] = left_b
for i in reversed(range(N)):
    if S[i] == ".":
        right_w += 1
    ws[i] = right_w

for i in range(N):
    total = min(total, ws[i+1] + bs[i])

print(total)

Buggy submission (verdict: Runtime Error):
from collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
bs = [0] * (N + 1)
ws = [0] * (N + 1)
total = float("inf")
left_b = 0
right_w = 0
for i, s in enumerate(S):
    if s == "#":
        left_b += 1
        bs[i + 1] = left_b
for i in reversed(range(N))
    if S[i] == ".":
        right_w += 1
        ws[i] = right_w

for i in range(N):
    total = min(total, ws[i+1] + bs[i])

print(total)

Buggy submission (verdict: Runtime Error):
from collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
r = N - 1
l = 0
while S[r] == "#":
    r -= 1
while S[l] == ".":
    l += 1
cnt = Counter(S[l:r+1])
print(min(cnt["."], cnt["#"]))

Buggy submission (verdict: Runtime Error):
from collections import Counter
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
r = N - 1
while S[r] == "#":
    r -= 1
cnt = Counter(S[:r+1])
print(min(cnt["."], cnt["#"]))

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().rstrip()
N = ii()
S = ns()
print(S.counet("#."))
Problem p03074 (python)

Fixed submission:

from itertools import groupby
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
N, K = tuple(li())
S = stdin.readline() + "2"
# use window
l, r = 0, 0
cnt = 0
r_iter = groupby(S)
l_iter = groupby(S)
r_next = next(r_iter)
l_next = next(l_iter)
while r < N:
    # print(l, r, K)
    if K > 0:
        if r_next[0] == '1' and r > 0:
            K -= 1
        r += len(list(r_next[1]))
        r_next = next(r_iter)
        cnt = max(cnt, r - l)
    elif K == 0 and r_next[0] == "1":
        cnt = max(cnt, r - l)
        r += len(list(r_next[1]))
        r_next = next(r_iter)
        cnt = max(cnt, r - l)
    else:
        if l_next[0] == "0":
            K += 1
        l += len(list(l_next[1]))
        l_next = next(l_iter)
# print(l,r,K)
if r_next[0] == '1':
    cnt = max(cnt, r-l)
print(cnt)

Buggy submission (verdict: Runtime Error):

from itertools import groupby
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
N, K = tuple(li())
S = stdin.readline()
# use window
l, r = 0, 0
cnt = 0
r_iter = groupby(S)
l_iter = groupby(S)
r_next = next(r_iter)
l_next = next(l_iter)
while r < N:
    # print(l, r)
    if K > 0:
        if r_next[0] == '1':
            r += len(list(r_next[1]))
            r_next = next(r_iter)
            cnt = max(cnt, r - l)
            K -= 1
        elif r_next[0] == "0":
            pass
        r += len(list(r_next[1]))
        r_next = next(r_iter)
    elif K == 0 and r_next[0] == "1":
        r += len(list(r_next[1]))
        r_next = next(r_iter)
    else:
        if l_next[0] == "0":
            K += 1
        l += len(list(l_next[1]))
        l_next = next(l_iter)
if K > 0:
    cnt = max(cnt, r-l)
print(cnt)

Buggy submission (verdict: Runtime Error):

from itertools import groupby
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
N, K = tuple(li())
S = stdin.readline() + "2"
# use window
l, r = 0, 0
cnt = 0
r_iter = groupby(S)
l_iter = groupby(S)
r_next = next(r_iter)
l_next = next(l_iter)
while r_next[0] != "2":
    # print(l, r)
    if r_next[0] == '1' and K >= 0:
        r += len(list(r_next[1]))
        r_next = next(r_iter)
        cnt = max(cnt, r - l)
        K -= 1
        continue
    elif K >=0:
        if r_next[0] == "0":
            pass
        r += len(list(r_next[1]))
        r_next = next(r_iter)
        continue
    if l_next[0] == "0":
        K += 1
    elif l_next[0] == "1":
        pass
    l += len(list(l_next[1]))
    l_next = next(l_iter)
if K > 0:
    cnt = max(cnt, r-l)
while K <= 0:
    if l_next[0] == "0":
        K += 1
    elif l_next[0] == "1":
        pass
    l += len(list(l_next[1]))
    l_next = next(l_iter)
    cnt = max(cnt, r-l)
print(cnt)