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

Fixed submission:
A, B = map(int, input().split())
if (A*B % 2 == 0):
  print("No")
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
if (A*B % 2 = 0):
  print("No")
else:
  print("Yes")
Problem p03262 (python)

Fixed submission:
import fractions
  

N, X = map(int, input().split())
town = list(map(int, input().split()))
 
for i in range(N):
  if town[i] < X:
    town[i] = X - town[i]
  else:
    town[i] = town[i] - X
  
gcd = town[0]
for i in range(1, N):
  gcd = fractions.gcd(gcd, town[i])
print(gcd)

Buggy submission (verdict: Runtime Error):
import math
 
N, X = map(int, input().split())
town = list(map(int, input().split()))
 
for i in range(N):
  if town[i] < X:
    town[i] = X - town[i]
  else:
    town[i] = town[i] - X
    
if N == 1:
  print("qaaq")
  
gcd = town[0]
for i in range(1, N):
  gcd = math.gcd(gcd, town[i])
print(gcd)

Buggy submission (verdict: Runtime Error):
import math
 
N, X = map(int, input().split())
town = list(map(int, input().split()))
 
for i in range(N):
  if town[i] < X:
    town[i] = X - town[i]
  else:
    town[i] = town[i] - X
  
gcd = town[0]
for i in range(1, N):
  gcd = math.gcd(gcd, town[i])
print(gcd)

Buggy submission (verdict: Runtime Error):
import math

N, X = map(int, input().split())
town = list(map(int, input().split()))

for i in range(N):
  if town[i] < X:
    town[i] = X - town[i]
  else:
    town[i] = town[i] - X

if N ==1:
  print(town[0])
  
else:
  gcd = math.gcd(town[0], town[1])
  for i in range(2, N):
    gcd = math.gcd(gcd, town[i])
  print(gcd)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

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

N, X = map(int, input().split())
town = list(map(int, input().split()))

for i in range(N):
  if town[i] < X:
    town[i] = X - town[i]
  else:
    town[i] = town[i] - X

print(gcd_list(town))
Problem p03280 (python)

Fixed submission:
A, B = map(int, input().split())
print(A*B - A - B + 1)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
ans = A*B - A - B + 1
print(ans)

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

print(A*B - A - B + 1)
Problem p03282 (python)

Fixed submission:
import math
N = 5000000000000000
S = input()
K = math.log(int(input()))
for i in S:
  num = int(i)
  if num == 1:
    if num == int(math.exp(K)):
      print(num)
      break
    else:
      K = math.log(int(math.exp(K)-1))
      continue
  kk = N * math.log(num)
  if kk >= K:
    print(num)
    break
  else:
    K -= kk

Buggy submission (verdict: Runtime Error):
import math
N = 5000000000000000
print(N)
S = input()
K = int(input())
for i in S:
  num = int(i)
  if N * math.log(num) > math.log(K):
    print(num)
    break
  else:
    K -= num
Problem p03324 (python)

Fixed submission:
D, N = map(int, input().split())
if N < 100:
  print((100**D)*N)
else:
  print((100**D)*101)

Buggy submission (verdict: Runtime Error):
D, N = map(int, input().split())
if N < 100:
  print((100**D)*N)
else:
  print(((100**D)*101)
Problem p03331 (python)

Fixed submission:
N = int(input())
while(N%10 == 0):
 N /= 10
if N == 1:
 print(10)
else:
 s = str(N)
 array = list(map(int, list(s)))
 print(sum(array))

Buggy submission (verdict: Runtime Error):
N, C, D = map(int, input().split())
check = [i*i for i in range(N+1)]
time = 0
stop = N * N
 
print(check)
if C * D % 2 ==1:
 for i in range(2*N):
  for j in range(2*N):
   if (i + j) % 2 == 0:
    print(i, j)
    time += 1
    if stop == time:
     break
  if stop == time:
   break
elif (C+D) % 2 == 0:
 for i in range(2*N):
  for j in range(2*N):
   if (i + j) % 2 == 1:
    print(i, j)
    time += 1
    if stop == time:
     break
  if stop == time:
   break
else:
 for i in range(2*N):
  tt = i * i
  if C - tt in check or D - tt in check:
   continue
  else:
   for j in range(2*N):
    print(i,j)
    time += 1
    if stop == time:
     break
  if stop == time:
   break

Buggy submission (verdict: Runtime Error):
N, C, D = map(int, input().split())
check = [i*i for i in range(N)]
time = 0
stop = N * N

if C * D % 2 ==1:
 for i in range(2*N):
  for j in range(2*N):
   if (i + j) % 2 == 0:
    print(i, j)
    time += 1
    if stop == time:
     break
  if stop == time:
   break
elif (C+D) % 2 == 0:
 for i in range(2*N):
  for j in range(2*N):
   if (i + j) % 2 == 1:
    print(i, j)
    time += 1
    if stop == time:
     break
  if stop == time:
   break
else:
 for i in range(2*N):
  for j in range(2*N):
   if (i + j) % 2 == 0:
    if C % 2 == 1:
     if D - j * j not in check:
      print(i, j)
      time += 1
      if stop == time:
       break
    else:
     if C - j * j not in check:
      print(i, j)
      time += 1
      if stop == time:
       break
   if stop == time:
    break

Buggy submission (verdict: Runtime Error):
N, C, D = map(int, input().split())
check = [i*i for i in range(N)]
time = 0
stop = N * N

if C * D % 2 ==1:
 for i in range(2*N):
  for j in range(2*N):
   if (i + j) % 2 == 0:
    print(i, j)
    time += 1
    if stop == time:
     break
  if stop == time:
   break
elif (C+D) % 2 == 0:
 for i in range(2*N):
  for j in range(2*N):
   if (i + j) % 2 == 1:
    print(i, j)
    time += 1
    if stop == time:
     break
  if stop == time:
   break
Problem p03347 (python)

Fixed submission:
N = int(input())

start = int(input())
flag = 0
if start != 0:
 flag = 1
t = 0

for i in range(N-1):
 k = int(input())
 if k == start:
  t += start
 elif k == start + 1:
  t += 1
  start = k
 elif k == 0:
  start = 0
 elif k > start + 1:
  t = -1
  break
 else:
  t += k
  start = k

if flag ==1:
 t = -1
print(t)

Buggy submission (verdict: Runtime Error):
N = int(input())

start = int(input())
flag = 0
if start != 0:
flag = 1
t = 0

for i in range(N-1):
 k = int(input())
 if k == start:
  t += start
 elif k == start + 1:
  t += 1
  start = k
 elif k == 0:
  start = 0
 elif k > start + 1:
  t = -1
  break
 else:
  t += k
  start = k

if flag ==1:
 t = -1
print(t)

Buggy submission (verdict: Runtime Error):
N = int(input())

start = int(input())
flag = 0
if start != 0:
flag = 1
t = 0

for i in range(N-1):
 k = int(input())
 if k == start:
  t += start
 elif k == start + 1:
  t += 1
  start = k
 elif k == 0:
  start = 0
 elif k > start + 1:
  t = -1
  break
 else:
  t += k
  start = k

if flag ==1:
 t = -1
print(t)
Problem p03633 (python)

Fixed submission:
#ABC 070: C [beta]
from fractions import gcd

N = int(input())
clocks = []
for i in range(N):
  clocks.append(int(input()))

b = clocks[0]
for i in range(1, N):
  a = gcd(b, clocks[i])
  b = b * clocks[i] // a

print(b)

Buggy submission (verdict: Runtime Error):
#ABC 070: C [beta]
from fractions import gcd

N = int(input())
clocks = []
for i in range(N):
  clocks.append(int(input()))

a = clocks[0]
for i in range(1, N):
  a = gcd(a, clocks[i])
  b = b * clocks[i] / a

print(b)

Buggy submission (verdict: Runtime Error):
#ABC 070: C [beta]
from fractions import gcd

N = int(input())
clocks = []
for i in range(N):
  clocks.append(int(input()))

a = clocks[0]
for i in range(1, N):
  a = gcd(a, clocks[i])
  b = a * clocks[i] / a

print(b)

Buggy submission (verdict: Runtime Error):
#ABC 070: C [beta]
from fraction import gcd

N = int(input())
clocks = []
for i in range(N):
  clocks.append(int(input()))

a = clocks[0]
for i in range(1, N):
  a = gcd(a, clocks[i])
  b = a * clocks[i] / a

print(b)
Problem p03074 (python)

Fixed submission:
from collections import deque

N, K = map(int, input().split())
S = [int(x) for x in input()]

count = 0
flag = True

la = deque([])
for c in S:
    if int(flag) == c:
        count += 1
    else:
        la.append(count)
        count = 1
        flag = not flag

la.append(count)

if K >= (len(la) / 2):
    print(N)
    exit()

ltmp = deque([])
sum_la = 0
for _ in range((K-1)*2 + 1):
    tmp = la.popleft()
    sum_la += tmp
    ltmp.append(tmp)

last_a = [sum_la]
while len(la) > 0 :
    tmp = la.popleft()
    sum_la += tmp
    ltmp.append(tmp)
    if len(la) > 0:
        tmp = la.popleft()
        sum_la += tmp
        ltmp.append(tmp)

    last_a.append(sum_la)

    if len(ltmp) > 0:
        tmp = ltmp.popleft()
        sum_la -= tmp
    if len(ltmp) > 0:
        tmp = ltmp.popleft()
        sum_la -= tmp
    last_a.append(sum_la)

print(max(last_a))

Buggy submission (verdict: Runtime Error):
from collections import deque

N, K = map(int, input().split())
S = [int(x) for x in input()]

count = 0
flag = True

la = deque([])
for c in S:
    if int(flag) == c:
        count += 1
    else:
        la.append(count)
        count = 1
        flag = not flag

la.append(count)

ltmp = deque([])
sum_la = 0
for _ in range((K-1)*2 + 1):
    tmp = la.popleft()
    sum_la += tmp
    ltmp.append(tmp)

last_a = [sum_la]
while len(la) > 0 :
    tmp = la.popleft()
    sum_la += tmp
    ltmp.append(tmp)
    if len(la) > 0:
        tmp = la.popleft()
        sum_la += tmp
        ltmp.append(tmp)

    last_a.append(sum_la)

    if len(ltmp) > 0:
        tmp = ltmp.popleft()
        sum_la -= tmp
    if len(ltmp) > 0:
        tmp = ltmp.popleft()
        sum_la -= tmp
    last_a.append(sum_la)

print(max(last_a))

Buggy submission (verdict: Runtime Error):
from collections import deque

N, K = map(int, input().split())
S = [int(x) for x in input()]

count = 0
flag = True

la = deque([])
for c in S:
    if int(flag) == c:
        count += 1
    else:
        la.append(count)
        count = 1
        flag = not flag

la.append(count)

print(la)

ltmp = deque([])
sum_la = 0
for _ in range((K-1)*2 + 1):
    tmp = la.popleft()
    sum_la += tmp
    ltmp.append(tmp)

last_a = [sum_la]
while len(la) > 0 :
    tmp = la.popleft()
    sum_la += tmp
    ltmp.append(tmp)
    if len(la) > 0:
        tmp = la.popleft()
        sum_la += tmp
        ltmp.append(tmp)

    last_a.append(sum_la)

    if len(ltmp) > 0:
        tmp = ltmp.popleft()
        sum_la -= tmp
    if len(ltmp) > 0:
        tmp = ltmp.popleft()
        sum_la -= tmp
    last_a.append(sum_la)

# for i in range(K, len(l) - K, 2):
#     last_a.append(sum(l[i-K:i+K+1]))

# last_b = []
# K = K-1
# for i in range(K, len(l) - K, 2):
#     last_b.append(sum(l[i-K:i+K+1]))

print(max(last_a))
# for i in range(len(l)):
#     l =
Problem p03060 (python)

Fixed submission:
a=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
cost=0
for i in range(a):
    if p[i] - q[i] > 0:
        cost += (p[i]-q[i])   
print(cost)

Buggy submission (verdict: Runtime Error):
a=input()
p=list(map(int,input().split()))
q=list(map(int,input().split()))
cost=0
for i in range(a):
    if p[i] - q[[i] > 0:
        cost += (p[i]-q[i])   
print(n)
Problem p03086 (python)

Fixed submission:
#ATCGを小文字へ置き換え、小文字を抽出する作戦
S=input().replace("A","a").replace("T","t").replace("C","c").replace("G","g")

#小文字の列を取得
import re
list=re.findall(r"[a-z]+",S)

#各列の文字列の長さをリストに
list2=[]
for i in range(len(list)):
  list2.append(len(list[i]))
  
#リストが空の場合との場合分け
if list2 ==[]:
  print(0)
else:
  print(max(list2))

Buggy submission (verdict: Runtime Error):
#ATCGを小文字へ置き換え、小文字を抽出する作戦
S=input().replace("A","a").replace("T","t").replace("C","c").replace("G","g")

#小文字の列を取得
import re
list=re.findall(r"[a-z]+",S)

#各列の文字列の長さをリストに
list2=[]
for i in range(len(list)):
  list2.append(len(list[i]))

print(max(list2))
Problem p03106 (python)

Fixed submission:
a,b,k=map(int,input().split())
list=[]

for i in range(1,min(a,b)+1):
  if a % i == 0 and b % i == 0:
    list.append(i)
  else:
    pass
print(list[-k])

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
list=[]

for i in range(1,min(a,b)):
  if a % i == 0 and b % i == 0:
    list.append(i)
  else:
    pass
print(list[-k])

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
list=[]

for i in range(1,min(a,b)):
  if a % i == 0 and b % i == 0:
    list.append(i)
  else:
    pass
print(list[k-1])
Problem p03239 (python)

Fixed submission:
n,t=map(int,input().split())
clis=[]
tlis=[]
for i in range(n):
  a,b=map(int,input().split())
  clis.append(a)
  tlis.append(b)
lis2=[]
for i in range(n):
  if tlis[i] > t:
    pass
  else:
    lis2.append(clis[i])
if len(lis2)==0:
  print("TLE")
else:
  print(min(lis2))

Buggy submission (verdict: Runtime Error):
n,t=map(int,input().split())
clis=[]
tlis=[]
for i in range(n):
  a,b=map(int,input().split())
  clis.append(a)
  tlis.append(b)
lis2=[]
for i in range(n):
  if tlis[i] > t:
    pass
  else:
    lis2.append(clis[i])
if len(lis2)==0:
  print(TLE)
else:
  print(min(lis2))
Problem p03316 (python)

Fixed submission:
# coding: utf-8
# Your code here!
N = int(input())
N2 = N
sum = 0
while True:
    sum += N % 10
    N = N // 10
    if N == 0:
        break
if N2 % sum == 0:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N2 = N
sum = 0
while True:
    sum += N % 10
    N = N // 10
    if N == 0:
        break
if N2 % sum == 0:
    print('Yes')
else:
    print('No')
Problem p03030 (python)

Fixed submission:
n = int(input())
dat = []
for i in range(n):
    std_in = input().split()
    dat.append([std_in[0], int(std_in[1])])
     
for i, e in enumerate(dat, start=1):
    e[1] = -e[1]  # 点数を降順ソートするために点数をマイナスにする。
    e.append(i)  # ソート前の順序
     
sorted_list = sorted(dat)  # 都市名と点数のマイナス値で昇順ソート
     
for i, s in enumerate(sorted_list):
    # 順序を出力
    print(sorted_list[i][2])

Buggy submission (verdict: Runtime Error):
n = int(input)
for i in range(n):
    std_in = input().split()
    dat.append([std_in[0], int(std_in[1])])

for i, e in enumerate(dat, start=1):
    e[1] = -e[1]  # 点数を降順ソートするために点数をマイナスにする。
    e.append(i)  # ソート前の順序
 
    sorted_list = sorted(dat)  # 都市名と点数のマイナス値で昇順ソート
 
for i, s in enumerate(sorted_list):
    # 順序を出力
    print(sorted_list[i][2])

Buggy submission (verdict: Runtime Error):
n = int(input)
for i in range(n):
    std_in = input.split()
    dat.append([std_in[0], int(std_in[1])])

for i, e in enumerate(dat, start=1):
    e[1] = -e[1]  # 点数を降順ソートするために点数をマイナスにする。
    e.append(i)  # ソート前の順序

    sorted_list = sorted(dat)  # 都市名と点数のマイナス値で昇順ソート

for i, s in enumerate(sorted_list):
    # 順序を出力
    print(sorted_list[i][2])
Problem p03125 (python)

Fixed submission:
A, B = (int(x) for x in input().split())
if B % A == 0:
  print(A + B)
else:
  print(B - A)

Buggy submission (verdict: Runtime Error):
N, M = (int(x) for x in input().split())
KA = [[int(x) for x in l] for l in [input().split() for i in range(N)]]
[x.pop(0) for x in KA]
x = []
for s in KA:
  x.extend(s)
c = 0
for i in range(1, M + 1):
  c = c + (1 if x.count(i) == N else 0)
print(c)

Buggy submission (verdict: Runtime Error):
A, B = (int(x) for x in input().split())
if B % A == 0:
  return A + B
else:
  return B - A
Problem p03136 (python)

Fixed submission:
s = [input() for i in range(2)]
N = int(s[0])
L = list(map(int, s[1].split()))
print('Yes' if max(L) < sum(L) - max(L) else 'No')

Buggy submission (verdict: Runtime Error):
s = [input() for i in range(2)]
N = int(s[0])
L = map(int, s[1].split())
print(if('Yes', max(L) < sum(L) - max(L), 'No'))
Problem p03147 (python)

Fixed submission:
# Grand Garden
N = int(input().strip())
h = list(map(int, input().strip().split()))

def mizu(h, s):
	for k in range(s, len(h)):
		if h[k] > 0:
			h[k] -= 1
		else:
			break
	return h
	
def find_start(h):
	s = 0
	for k in range(len(h)):
		if h[k] > 0:
			s = k
			break
	return s

def is_finish(h):
	if sum(h) == 0:
		return True
	else:
		return False

count = 0
while True:
	if is_finish(h):
		break
	s = find_start(h)
	h = mizu(h, s)
	count += 1

print(count)

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

def solve_range(h, start):
	ans = 0
	for i in range(start, len(h)):
		if h[i] > 0:
			h[i] -= 1
		else:
			break
	start = min((i for i in range(len(h)) if h[i] >0), default = -1)
	if start == -1:
		return ans+1
	else:
		ans += solve_range(h, start) + 1
		return ans

start = min((i for i in range(len(h)) if h[i] > 0), default = -1)
a=solve_range(h,start)
print(a)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n=int(input())
G=[[]for i in range(n+1)]
for i in range(n-1):
    a, b, c = map(int,input().split())
    G[a] += (b,c),
    G[b] += (a,c),
    
d = [0]*(n+1) #1から各点への距離
def f(v,p,u): #v:今見ているとこ p:一つ前に見たとこ u:1からの距離
    d[v] = u
    for t, c in G[v]:
        if p != t:
            f(t,v,u+c)
f(1,0,0)
for i in range(n):
    if d[i+1] % 2 == 0:
        print(1)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        # 根への距離を管理
        self.weight = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    # 併合
    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]

N = int(input())
ps = [list(map(int, input().split())) for _ in range(N-1)]
ps.sort()
tree = WeightedUnionFind(N)
for i, j, d in ps:
    tree.union(i, j, d)
for i in range(1, N+1):
    if diff(1, i) % 2 == 0:
        print(1)
    else:
        print(0)
Problem p03046 (python)

Fixed submission:
M, K =map(int, input().split())
if K >= 2**M:
    ans = [-1]
elif M == 0:
    ans = [0, 0]
elif M == 1:
    if K == 1:
        ans = [-1]
    else:
        ans = [0, 0, 1, 1]
else:
    ans = list(range(K)) + list(range(K+1, 2**M)) +[K] + list(range(2**M-1, K, -1))+list(range(K-1, -1, -1)) +[K]
print(*ans)

Buggy submission (verdict: Runtime Error):
M, K =map(int, input().split())
if K >= 2**M:
    ans = -1
elif M == 0:
    ans = [0, 0]
elif M == 1:
    if K == 0:
        ans = [0, 1, 1, 0]
    else:
        ans = [0, 0, 1, 1]
else:
    ans = list(range(K-1)) + list(range(K+1, 2**M)) +[K] + list(range(2**M-1, K, -1))+list(range(K-1, -1, -1)) +[K]
print(*ans)
Problem p03061 (python)

Fixed submission:
import fractions
import collections
N = int(input())
As = list(map(int, input().split()))
lgcd = [As[0]]
rgcd = collections.deque([As[-1]])
l = As[0]
r = As[-1]
for i in range(1, N):
    l = fractions.gcd(l, As[i])
    r = fractions.gcd(r, As[-(i+1)])
    lgcd.append(l)
    rgcd.appendleft(r)
ans = [lgcd[N-2], rgcd[1]]
for i in range(1, N-1):
    ans.append(fractions.gcd(lgcd[i-1], rgcd[i+1]))
print(max(ans))

Buggy submission (verdict: Runtime Error):
import fractions
N = int(input())
As = list(map(int, input().split()))
As.sort()
ans = 1
odd = 0
even = 0
for a in As:
    if a%2 == 0:
        even += 1
    else:
        odd += 1
if even >= 2 and odd >= 2:
    print(1)
elif even == 1:
    c = 0
    for b in As:
        if b % 2 == 1:
            c = b
            break
    for a in As:
        if a % 2 == 1:
            c = fractions.gcd(c, a)
    print(c)
elif odd == 1:
     c = 0
    for b in As:
        if b % 2 == 0:
            c = b
            break
    for a in As:
        if a % 2 == 0:
            c = fractions.gcd(c, a)
    print(c)
    
else:
    
    for i in range(N):
        flag = True
        if i == 0:
            a = As[1]
        else:
            a = As[0]
        for j in range(N):
            if j != i:
                a = fractions.gcd(a, As[j])
                if a <= ans:
                    flag = False
                    break
        if flag:  
            ans = a
    print(ans)
Problem p03074 (python)

Fixed submission:
import collections
n, k = map(int, input().split())
s = input()
zero =[]
cnt = 0
d = collections.deque()
for i, j in enumerate(s):
    if j == '0':
        cnt += 1
    if j == '1' and i > 0:
        if cnt > 0:
            zero.append((cnt, i-1))
            cnt = 0
if cnt > 0:
    zero.append((cnt, n-1))
idx = n-1
one= []
while zero:
    d.append(zero.pop())
    if len(d) < k:
        continue
    if zero:    
        i, j = zero[-1]
        one.append(idx-j)
    else:
        one.append(idx +1)
    k, l = d.popleft()
    idx = l-k
if one == []:
    one.append(n)
print(max(one))

Buggy submission (verdict: Runtime Error):
import collections
n, k = map(int, input().split())
s = [int(i) for i in input()]
c = []
prv = 1
cnt = 0
for i in s:
    if prv != i:
        c.append(cnt)
        cnt = 1
        prv = i
    else:
        cnt += 1
if cnt > 0:
    c.append(cnt)
if prv == 0:
    c.append(0)
que = collections.deque(c[0])
res =c[0]
ans = c[0]
m = len(c) // 2
for i in range(m):
    if len(que) == 2*k + 1:
        res -= que.popleft() + que.popleft()
    que.append(c[2*i +1])
    que.append(c[2*i +2])
    res += c[2*i+1] + c[2*i+2]
    ans = max(res, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
import collections
n, k = map(int, input().split())
s = input()
nums = collections.deque()
anss = collections.deque(maxlen = 2*k +1)
ans = []
c_zero = 0
c_one = 0
if s[1] == '0':
    nums.append(0)
for i in s:
    if i == '0':
        c_zero += 1
        if c_one > 0:
            nums.append(c_one)
            c_one = 0
    elif i == '1':
        c_one += 1
        if c_zero > 0:
            nums.append(c_zero)
            c_zero = 0
if s[-1] == '1':
    nums.append(c_one)
elif s[-1] == '0':
    nums.append(c_zero)
while len(anss) < 2*k +1:
    if len(nums) == 0:
        print(n)
        break
    anss.append(nums.popleft())
if len(nums) == 0:
    print(n)
while nums:
    ans.append(sum(anss))
    if len(nums) == 0:
        break
    anss.append(nums.popleft())
    if len(nums) == 0:
        break
    anss.append(nums.popleft())
    if len(nums) == 0:
        ans.append(sum(anss))
if ans:
    print(max(ans))