Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import copy
N,K=list(map(int,input().split()))
a=list(map(int,input().split()))

num=0
a_sum=[0]
for i in range(N):
  num+=a[i]
  a_sum.append(num)
  

a_mat=[[0 for i in range(N)] for j in range(N)]
non_zero=[]
for i in range(N):
  for j in range(i,N):
    a_mat[i][j] = a_sum[j+1]-a_sum[i]
    non_zero.append([i,j])

a_mat2=copy.deepcopy(a_mat)

maxbit=1
while True:
  if a_sum[N]<2**maxbit and a_sum[N]>=2**(maxbit-1): 
    break
  else:
    maxbit+=1
maxnum=0
num_rest=int(N*(N+1)/2)
num_rest_now=int(N*(N+1)/2)
for bit in range(maxbit):
  non_zero2=[]
  for i, j in non_zero:
    if a_mat[i][j]&(2**(maxbit-bit-1)) == 0 and a_mat[i][j]!=0:
      num_rest_now-=1
      a_mat2[i][j]=0
    else:
      non_zero2.append([i,j])
  #print(non_zero)
  #print(a_mat)
  #print(num_rest_now)
  
  if num_rest_now >= K:
    maxnum+=2**(maxbit-bit-1)
    a_mat=copy.deepcopy(a_mat2)
    num_rest=num_rest_now
    non_zero=copy.deepcopy(non_zero2)
  else:
    a_mat2=copy.deepcopy(a_mat)
    num_rest_now=num_rest
    
  
  
print(maxnum)
    

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

ave=sum(a)/N

mini=1000
argmin=-1
for i in range(N):
  if abs(ave-a[i])<mini:
    mini=abs(ave-a[i])
    argmin=i
    
print(argmin)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
Q = int(input())
k = list(map(int,input().split()))

D_list=[]
M_list=[]
C_list=[]

for i in range(N):
  if S[i] == "D":
    D_list.append(i)
  if S[i] == "M":
    M_list.append(i)
  if S[i] == "C":
    C_list.append(i)
    
k_list=[0]*Q
  
M_sum=[0]*N  
for i in range(1,N):
  if i in M_list:
    M_sum[i]=M_sum[i-1]+1
  else:
    M_sum[i]=M_sum[i-1] 

num=0
c_start=0
for d in D_list:
  time=0
  c_loc=c_start
  while C_list[c_loc] <= d+max(k):
   # print(d,C_list[c_loc])
    if C_list[c_loc] > d:
      if time==0:
        c_start=c_loc
        time+=1
      num=M_sum[C_list[c_loc]]-M_sum[d]
      #print(M_sum[C_list[c_loc]],M_sum[d])
      for q in range(Q):
        if k[q] > C_list[c_loc] - d:
          k_list[q]+=num
    c_loc+=1
    if c_loc >= len(C_list):
        break

for i in range(Q):
  print(k_list[i])
            
            
        
  
  

Fixed submission:

import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())
S = input()
Q = int(input())
k = list(map(int, input().split()))

DM_total = [(0,0,0)]
C_list = []

for i in range(N):
	if S[i] == "D":
		DM_total.append((DM_total[-1][0] + 1, DM_total[-1][1], DM_total[-1][2]))
	elif S[i] == "M":
		DM_total.append((DM_total[-1][0], DM_total[-1][1] + 1, DM_total[-1][2] + DM_total[-1][0]))
	else:
		DM_total.append(DM_total[-1])
	if S[i] == "C":
		C_list.append(i)

ans_list = [0]*Q

for c in C_list:
	for q in range(Q):
		if k[q] > c:
			ans_list[q] += DM_total[c + 1][2]
		else:
			ans_list[q] += DM_total[c + 1][2] - DM_total[c + 1 - k[q]][2]
			ans_list[q] -= DM_total[c + 1 - k[q]][0] * (DM_total[c + 1][1] - DM_total[c + 1 - k[q]][1])

for q in range(Q):
	print(ans_list[q])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
#sys.setrecursionlimit(10 ** 9)
import math
import heapq

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

areas = []
for i in range(M):
	a, b = list(map(int, input().split()))
	bisect.insort(areas, [b - 1, a])

num = 0
loc = 0
for i in range(M):
	if loc < areas[i][1]:
		num += 1
		loc = areas[i][0]

print(num)

Fixed submission:

import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
#sys.setrecursionlimit(10 ** 9)
import math
import heapq

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

areas = []
for i in range(M):
	a, b = list(map(int, input().split()))
	areas.append([b - 1, a])
areas.sort()

num = 0
loc = 0
for i in range(M):
	if loc < areas[i][1]:
		num += 1
		loc = areas[i][0]

print(num)

Buggy python submission (verdict: Time Limit Exceeded):

import sys
from collections import deque, defaultdict
import copy
import bisect
#input=sys.stdin.readline
#sys.setrecursionlimit(10 ** 9)
import math
import heapq

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

areas = []
for i in range(M):
	a, b = list(map(int, input().split()))
	bisect.insort(areas, [b - 1, a])

num = 0
loc = 0
for i in range(M):
	if loc < areas[i][1]:
		num += 1
		loc = areas[i][0]

print(num)

Fixed submission:

import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
#sys.setrecursionlimit(10 ** 9)
import math
import heapq

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

areas = []
for i in range(M):
	a, b = list(map(int, input().split()))
	areas.append([b - 1, a])
areas.sort()

num = 0
loc = 0
for i in range(M):
	if loc < areas[i][1]:
		num += 1
		loc = areas[i][0]

print(num)
Buggy python submission (verdict: Time Limit Exceeded):

import sys
def input():
	return sys.stdin.readline().strip()

N, A, B, K = list(map(int, input().split()))

mod = 998244353

fact_list = [1]
for i in range(1, N + 1):
	fact_list.append((fact_list[-1]*i) % mod)

def pow(x, y, mod=1000000007):
	pow_list = [x]
	i = 1
	while 2**i <= y:
		a = pow_list[-1]**2
		if mod != 0:
			a = a % mod
		pow_list.append(a)
		i += 1
	ans = 1
	for bit in range(len(pow_list)):
		if (2**bit) & y != 0:
			ans *= pow_list[bit]
			if mod != 0:
				ans = ans % mod
	return ans

def fact(n, mod=1000000007):
	return fact_list[n]

def mod_rev(x, mod):
	"""
	関数powが必要
	"""
	return pow(x, mod - 2, mod)


def comb(a, b, mod=1000000007):
	"""
	関数mod_rev, fact, powが必要
	"""
	if a < b or b < 0:
		return 0
	a_fact = fact(a, mod)
	b_fact = fact(b, mod)
	a_b_fact = fact(a - b, mod)
	if mod != 0:
		return (a_fact * mod_rev(b_fact, mod) * mod_rev(a_b_fact, mod))%mod
	else:
		return a_fact//(b_fact*a_b_fact)

ans = 0
for r in range(N + 1):
	rest = K - r * A
	if rest % B == 0 and rest // B >= 0 and rest // B <= N:
		b = rest // B
		ans += comb(N, r, mod)*comb(N, b, mod)
		ans %= mod
print(ans)


Fixed submission:
import sys
def input():
	return sys.stdin.readline().strip()

N, A, B, K = list(map(int, input().split()))

mod = 998244353

fact_list = [1]
for i in range(1, N + 1):
	fact_list.append((fact_list[-1]*i) % mod)

def pow(x, y, mod=1000000007):
	pow_list = [x]
	i = 1
	while 2**i <= y:
		a = pow_list[-1]**2
		if mod != 0:
			a = a % mod
		pow_list.append(a)
		i += 1
	ans = 1
	for bit in range(len(pow_list)):
		if (2**bit) & y != 0:
			ans *= pow_list[bit]
			if mod != 0:
				ans = ans % mod
	return ans

def fact(n, mod=1000000007):
	return fact_list[n]
  
rev_list = [1]
for i in range(N):
  rev_list.append(pow(fact(i + 1, mod), mod - 2, mod))

def mod_rev(x, mod):
	"""
	関数powが必要
	"""
	return rev_list[x]


def comb(a, b, mod=1000000007):
	"""
	関数mod_rev, fact, powが必要
	"""
	if a < b or b < 0:
		return 0
	a_fact = fact(a, mod)
	b_fact = fact(b, mod)
	a_b_fact = fact(a - b, mod)
	if mod != 0:
		return (a_fact * mod_rev(b, mod) * mod_rev(a - b, mod))%mod
	else:
		return a_fact//(b_fact*a_b_fact)

ans = 0
for r in range(N + 1):
	rest = K - r * A
	if rest % B == 0 and rest // B >= 0 and rest // B <= N:
		b = rest // B
		ans += comb(N, r, mod)*comb(N, b, mod)
		ans %= mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().split()))

def kuriagari(n, m):
  if n+m == n^m:
    return 0
  else:
    return 1
  
num=0

for i in range(N):
  judge = 0
  num2 = 0
  j=0
  while judge == 0 and i+j<N:
    judge=kuriagari(num2, A[i+j])
    if judge==0:
      num2+=A[i+j]
      num+=1
    j+=1
      
print(num)
  

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

def kuriagari(n, m):
  if n+m == n^m:
    return 0
  else:
    return 1
  
num=0

zero_list = [0] * (N-1)
zero_list.append(N)
for i in range(N-1):
  if A[N-1-i] == 0:
    zero_list[N-2-i]=zero_list[N-1-i]
  else:
    zero_list[N-2-i]=N-1-i

for i in range(N):
  judge = 0
  num2 = 0
  j=0
  while judge == 0 and i+j<N:
    judge=kuriagari(num2, A[i+j])
    if judge==0:
      num2+=A[i+j]
      num+=zero_list[i+j]-(i+j)
    j+=zero_list[i+j]-(i+j)
      
print(num)
Buggy python submission (verdict: Runtime Error):

import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())
ans = 0
d = defaultdict(int)
for i in range(N):
	di = int(input())
	if d[di] == 0:
		ans += 1
		d[di] += 1
print(ans)

Fixed submission:

import sys
from collections import deque, defaultdict
import copy
import bisect
#sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import combinations, permutations

import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())
ans = 0
d = defaultdict(int)
for i in range(N):
	di = int(input())
	if d[di] == 0:
		ans += 1
		d[di] += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions

import sys
def input():
	return sys.stdin.readline().strip()

S = input()

alpha = defaultdict(int)
N = len(S)
for i in range(N):
	alpha[S[i]] += 1

num = 0
for n in alpha:
	if alpha[n] % 2 == 1:
		num += 1

if num >= 2:
	print(-1)
	exit()

alpha_num = defaultdict(deque)
for i in range(N):
	alpha_num[S[i]].append(i)

loc_list = [-1]*N
num = 0
for i in range(N):
	if len(alpha_num[S[i]]) >= 2:
		x = alpha_num[S[i]].popleft()
		y = alpha_num[S[i]].pop()
		loc_list[x] = num
		loc_list[y] = N - 1 - num
		num += 1
	elif len(alpha_num[S[i]]) == 1:
		x = alpha_num[S[i]].popleft()
		loc_list[x] = N // 2

G = []
ans = 0
for i in range(N):
	x = bisect.bisect(G, loc_list[i])
	bisect.insort(G, loc_list[i])
	ans += i - x
print(ans)

Fixed submission:

import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions

import sys
def input():
	return sys.stdin.readline().strip()

S = input()

alpha = defaultdict(int)
N = len(S)
for i in range(N):
	alpha[S[i]] += 1

num = 0
for n in alpha:
	if alpha[n] % 2 == 1:
		num += 1

if num >= 2:
	print(-1)
	exit()

alpha_num = defaultdict(deque)
for i in range(N):
	alpha_num[S[i]].append(i)

loc_list = [-1]*N
num = 0
for i in range(N):
	if len(alpha_num[S[i]]) >= 2:
		x = alpha_num[S[i]].popleft()
		y = alpha_num[S[i]].pop()
		loc_list[x] = num
		loc_list[y] = N - 1 - num
		num += 1
	elif len(alpha_num[S[i]]) == 1:
		x = alpha_num[S[i]].popleft()
		loc_list[x] = N // 2

class Bit:
	def __init__(self, n):
		self.size = n
		self.tree = [0] * (n + 1)

	def sum(self, i):
		s = 0
		while i > 0:
			s += self.tree[i]
			i -= i & -i
		return s

	def add(self, i, x):
		while i <= self.size:
			self.tree[i] += x
			i += i & -i


bit = Bit(N)
ans = 0



for i, p in enumerate(loc_list):
	bit.add(p + 1, 1)
	ans += i + 1 - bit.sum(p + 1)

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque, defaultdict
import copy
import bisect
#sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations


import sys
def input():
	return sys.stdin.readline().strip()

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

ans = T[0]
for i in range(N - 1):
	ans = (ans * T[i + 1])//math.gcd(ans, T[i + 1])
print(ans)


Fixed submission:
import fractions

import sys
def input():
	return sys.stdin.readline().strip()

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

ans = T[0]
for i in range(N - 1):
	ans = (ans * T[i + 1])//fractions.gcd(ans, T[i + 1])
print(ans)
Buggy python submission (verdict: Runtime Error):

import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions

import sys
def input():
	return sys.stdin.readline().strip()

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

top_list = [0]


for i in range(1, N):

	if a[i] > a[top_list[-1]]:
		top_list.append(i)

num_list = [0]*N
com = []
for i in range(len(top_list)):
	bisect.insort(com, a[top_list[i]])


for i in range(N - 1, top_list[-1], -1):
	bisect.insort(com, a[i])

stock = 0
#print(com, top_list, num_list)
for top in range(len(top_list) - 2, -1, -1):
	for i in range(top_list[top + 1] - 1, top_list[top], -1):
		#bisect.insort(com, a[i])
		com.append(a[i])
	com.sort()
	judge = 0
	total = stock*(a[top_list[top + 1]] - a[top_list[top]])
	#print(total, (a[top_list[top + 1]] - a[top_list[top]])*stock,  top)
	while judge == 0:
		x = com.pop()
		if x > a[top_list[top]]:
			total += x - a[top_list[top]]
			stock += 1
		else:
			bisect.insort(com, x)
			judge = 1
	num_list[top_list[top + 1]] = total
	#print(com, top_list, num_list, stock)


num_list[top_list[0]] = sum(a) - sum(num_list)
for i in range(N):
	print(num_list[i])

Fixed submission:
import sys
def input():
	return sys.stdin.readline().strip()

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

if 2*N >= M:
	print(M // 2)
else:
	x = M - 2*N
	print(N + x//4)
Buggy python submission (verdict: Runtime Error):

N, M = list(map(int,input().split()))
graph = [dict() for i in range(N)]
for i in range(N):
	graph[i]["edge"] = []
for i in range(M):
	a, b = list(map(int, input().split()))
	graph[a - 1]["edge"].append(b - 1)
	graph[b - 1]["edge"].append(a - 1)

def pow(N):
	ans = 1
	for i in range(N):
		ans *= i + 1
	return  ans

total = 0
for i in range(pow(N - 1)):
	node = [a+1 for a in range(N - 1)]
	num = i
	zyun = [0]
	for j in range(N - 1, 0 , -1):
		mod = num % j
		num -= num % j
		num = num//j
		zyun.append(copy.deepcopy(node[mod]))
		del node[mod]
	judge = 1
	for loc in range(N - 1):
		if not zyun[loc + 1] in graph[zyun[loc]]["edge"]:
			judge = 0
	total += judge

print(total)

Fixed submission:
import copy


N, M = list(map(int,input().split()))
graph = [dict() for i in range(N)]
for i in range(N):
	graph[i]["edge"] = []
for i in range(M):
	a, b = list(map(int, input().split()))
	graph[a - 1]["edge"].append(b - 1)
	graph[b - 1]["edge"].append(a - 1)

def pow(N):
	ans = 1
	for i in range(N):
		ans *= i + 1
	return  ans

total = 0
for i in range(pow(N - 1)):
	node = [a+1 for a in range(N - 1)]
	num = i
	zyun = [0]
	for j in range(N - 1, 0 , -1):
		mod = num % j
		num -= num % j
		num = num//j
		zyun.append(copy.deepcopy(node[mod]))
		del node[mod]
	judge = 1
	for loc in range(N - 1):
		if not zyun[loc + 1] in graph[zyun[loc]]["edge"]:
			judge = 0
	total += judge

print(total)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())
nums = map(int, raw_input().split())
 
result = n
stack = 0, nums[0]
 
for i in xrange(1, n):
    st, nu = stack
    for j in range(st, i):
        if (nu + nums[i]) == (nu ^ nums[i]):
            result += i - j
            break
        nu -= nums[j]
    else:
        stack = i, nums[i]
        continue
    stack = j, nu + nums[i]
 
print result

Fixed submission:
n = int(raw_input())
nums = map(int, raw_input().split())

sums = [0] * (n + 1)
xors = [0] * (n + 1)

for i in xrange(n):
    sums[i + 1] = sums[i] + nums[i]
    xors[i + 1] = xors[i] ^ nums[i]

results = 0

for i in xrange(0, n):
    left, right = i + 1, n + 1
    while right - left > 1:
        mid = (left + right) / 2
        if sums[mid] - sums[i] == xors[mid] ^ xors[i]:
            left = mid
        else:
            right = mid
    results += left - i

print results

Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())
nums = map(int, raw_input().split())

result = n
stack = [nums[0]]

for i in xrange(1, n):
    ns = [nums[i]]
    for s in stack:
        if s + nums[i] == s ^ nums[i]:
            result += 1
            ns.append(s + nums[i])
    stack = ns

print result

Fixed submission:
n = int(raw_input())
nums = map(int, raw_input().split())

sums = [0] * (n + 1)
xors = [0] * (n + 1)

for i in xrange(n):
    sums[i + 1] = sums[i] + nums[i]
    xors[i + 1] = xors[i] ^ nums[i]

results = 0

for i in xrange(0, n):
    left, right = i + 1, n + 1
    while right - left > 1:
        mid = (left + right) / 2
        if sums[mid] - sums[i] == xors[mid] ^ xors[i]:
            left = mid
        else:
            right = mid
    results += left - i

print results
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline
    
    n = int(input().split())
    arr = list(map(int, input().split()))
    
    ok = 1
    for i in reversed(range(n - 1)):
        if arr[i] > arr[i + 1]:
            arr[i] -= 1
        if arr[i] > arr[i + 1]:
            ok = 0
    
    if ok:
        print("Yes")
    else:
        print("No")
    
    return 0

main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    
    n = int(input())
    arr = list(map(int, input().split()))
    
    ok = 1
    for i in reversed(range(n - 1)):
        if arr[i] > arr[i + 1]:
            arr[i] -= 1
        if arr[i] > arr[i + 1]:
            ok = 0
    
    if ok:
        print("Yes")
    else:
        print("No")
    
    return 0

main()
Buggy python submission (verdict: Runtime Error):
n, d = map(int, input().split())
points = [[]] * n
for i in range(n):
  points[i] = list(map(int, input().split()))

def helper(a, b):
  s = 0
  for i in range(n):
    s += (a[i] - b[i]) ** 2
  a = int(0.5 + (s ** 0.5))
  if a * a == s:
    return 1
  return 0

ans = 0
for i in range(n):
	for j in range(i + 1, n):
		ans += helper(points[i], points[j])
print(ans)

Fixed submission:
n, d = map(int, input().split())
points = [[]] * n
for i in range(n):
  points[i] = list(map(int, input().split()))
 
def helper(a, b):
  s = 0
  for i in range(d):
    s += (a[i] - b[i]) ** 2
  a = int(0.5 + (s ** 0.5))
  if a * a == s:
    return 1
  return 0
 
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        ans += helper(points[i], points[j])
print(ans)
Buggy python submission (verdict: Runtime Error):
a = input()
ok = 1
for i in range(1, 4):
	if a[i] == a[i - 1]:
      ok = 0
if ok:
  print("Good")
else:
	print("Bad")

Fixed submission:
a = input()
ok = 1
for i in range(1, 4):
    if a[i] == a[i - 1]:
        ok = 0
if ok:
    print("Good")
else:
    print("Bad")
Buggy python submission (verdict: Runtime Error):
n, l = map(int, input().split())
s = 0
for i in range(1, n + 1):
    s += l + i - 1

x = 1 - l
if x <= n and x >= i:
    print(s)
else:
    a = L
    b = L + n - 1
    if abs(a) < abs(b):
        print(s - a)
    else:
        print(s - b)

Fixed submission:
n, l = map(int, input().split())
s = 0
for i in range(1, n + 1):
    s += l + i - 1
 
x = 1 - l
if x <= n and x >= 1:
    print(s)
else:
    a = l
    b = l + n - 1
    if abs(a) < abs(b):
        print(s - a)
    else:
        print(s - b)

Buggy python submission (verdict: Runtime Error):
n, l = map(int, input().split())
s = 0
for i in range(1, n + 1):
  	s += l + i - 1

x = 1 - l
if x <= n and x >= i:
	print(s)
else:
    a = L
    b = L + n - 1
    if abs(a) < abs(b):
      print(s - a)
    else:
      print(s - b)

Fixed submission:
n, l = map(int, input().split())
s = 0
for i in range(1, n + 1):
    s += l + i - 1
 
x = 1 - l
if x <= n and x >= 1:
    print(s)
else:
    a = l
    b = l + n - 1
    if abs(a) < abs(b):
        print(s - a)
    else:
        print(s - b)
Buggy python submission (verdict: Runtime Error):
def main():
    n, k = map(int, input().split())
    s = input()
    
    arr = []
    if s[0] == '0':
        arr.append(0)
    cnt = 1
    i = 1
    while i != n:
        if s[i] != s[i - 1]:
            arr.append(cnt)
            cnt = 1
        else:
            cnt += 1
        i += 1
    arr.append(cnt)
    if s[-1] == '0':
        arr.append(0)
    
    ans = 0
    curr = arr[0]
    j = 1
    if len(arr) - 1 <= 2 * k:
        print(n)
        return 0
    for i in range(1, len(arr), 2):
        curr += arr[i] + arr[i + 1]
        if i - j == 2 * k:
            curr -= arr[j] + arr[j - 1]
            j += 2
        ans = max(ans, curr)
    print(ans)
    return 0
main()

Fixed submission:
def main():
    a, b = map(int, input().split())
    ans = 0
    if a > b:
        ans += a
        a -= 1
    else:
        ans += b
        b -= 1
    print(ans + max(a, b))
    return 0
main()
Buggy python submission (verdict: Runtime Error):
def main():
    s = input()
    n = len(s)
    a = 0
    b = 0
    for i in range(n):
        if i & 1:
            if arr[i] == '1':
                a += 1
            else:
                b += 1
        else:
            if arr[i] == '1':
                b += 1
            else:
                a += 1
        print(min(a, b))
    return 0
main()

Fixed submission:
def main():
    s = input()
    n = len(s)
    a = 0
    b = 0
    for i in range(n):
        if i & 1:
            if s[i] == '1':
                a += 1
            else:
                b += 1
        else:
            if s[i] == '1':
                b += 1
            else:
                a += 1
    print(min(a, b))
    return 0
main()
Buggy python submission (verdict: Runtime Error):
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    
    vector<int> arr;
    if (s[0] == '0') arr.push_back(0);
    int cnt = 1;
    for (int i = 1; i != n; ++i)
    {
        if (s[i] != s[i - 1])
        {
            arr.push_back(cnt);
            cnt = 1;
        }
        else ++cnt;
    }
    arr.push_back(cnt);
    if (s[n - 1] == '0') arr.push_back(0);
    
    int ans = 0;
    int curr = arr[0];
    int j = 1;
    for (int i = 1; i != arr.size(); i += 2)
    {
        curr += arr[i] + arr[i + 1];
        if (i - j == k << 1)
        {
            curr -= arr[j] + arr[j - 1];
            j += 2;
        }
        ans = max(ans, curr);
    }
    cout << ans << endl;
    return 0;
}

Fixed submission:
def main():
    ans = 0
    n, k = map(int, input().split())
    s = input()
    arr = []
    if s[0] == '0':
        arr.append(0)
    cnt = 1
    i = 1
    while i != n:
        if s[i] != s[i - 1]:
            arr.append(cnt)
            cnt = 1
        else:
            cnt += 1
        i += 1
    arr.append(cnt)
    if s[-1] == '0':
        arr.append(0)
    ans = 0
    curr = arr[0]
    j = 1
    if len(arr) - 1 <= 2 * k:
        print(n)
        return 0
    for i in range(1, len(arr), 2):
        curr += arr[i] + arr[i + 1]
        if i - j == 2 * k:
            curr -= arr[j] + arr[j - 1]
            j += 2
        ans = max(ans, curr)
    print(ans)
    return 0
main()