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

Fixed submission:
S = input()

count_list = []
for i in S:
    if i == 'A' or i == 'C' or i == 'G' or i == 'T':
        count_list.append(True)
    else:
        count_list.append(False)

l = len(S)
freq_list = []
for i in range(l):
    count = 0
    for j in range(l-i):
        if count_list[i+j] is True:
            count += 1
            freq_list.append(count)
        else:
            freq_list.append(count)
            break

print(max(freq_list))

Buggy submission (verdict: Runtime Error):
S = input()

count_list = []
for i in S:
    if i == 'A' or i == 'C' or i == 'G' or i == 'T':
        count_list.append(True)
    else:
        count_list.append(False)

l = len(S)
freq_list = []
for i in range(l):
    count = 0
    for j in range(l-i):
        if count_list[i+j] is True:
            count += 1
        else:
            freq_list.append(count)
            break

print(max(freq_list))
Problem p03624 (python)

Fixed submission:
S = input()

S_list = []
for s in S:
    if s not in S_list:
        S_list.append(s)

S_list.sort()

al_list = [chr(i) for i in range(97, 97+26)]

check_list = []
for i in range(len(S_list)):
    if S_list[i] == al_list[i]:
        check_list.append(True)
    else:
        check_list.append(False)

count = 0
for c in check_list:
    if c is True:
        count += 1
    else:
        count += 0

if count == 26:
    print('None')
else:
    print(al_list[count])

Buggy submission (verdict: Runtime Error):
S = input()

S_list = []
for s in S:
    if s not in S_list:
        S_list.append(s)

S_list.sort()

al_list = [chr(i) for i in range(97, 97+26)]

check_list = []
for i in range(26):
    if S_list[i] != al_list[i]:
        print(al_list[i])
        break
    else:
        check_list.append(True)

if len(check_list) == 26:
    print('None')
Problem p03827 (python)

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

count = 0
count_list = [0]
for i in S:
    if i == 'I':
        count += 1
        count_list.append(count)
    elif i == 'D':
        count -= 1
    else:
        print('Error')
    
print(max(count_list))

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

count = 0
count_list = []
for i in S:
    if i == 'I':
        count += 1
        count_list.append(count)
    elif i == 'D':
        count -= 1
    else:
        print('Error')
    
max_count = max(count_list)
if max_count > 0:
    print(max_count)
else:
    print(0)
Problem p03080 (python)

Fixed submission:
N = int(input())
print("Yes" if input().count("R") > N//2 else "No")

Buggy submission (verdict: Runtime Error):
4
BRBR
Problem p03262 (python)

Fixed submission:
# from math import gcd
def gcd(x, y):
    if y > x:
        x, y = y, x
    if y == 0:
        return x
    return gcd(y, x % y)


N, X = map(int, input().split())
x = [abs(X-int(x)) for x in input().split()]
if N == 1:
    print(x[0])
else:
    GCD = gcd(x[0], x[1])
    for i in range(2, N):
        GCD = gcd(GCD, x[i])
    print(GCD)

Buggy submission (verdict: Runtime Error):
from math import gcd

N, X = map(int, input().split())
x = [abs(X-int(x)) for x in input().split()]
if N==1:
    print(x[0])
else:
    GCD = gcd(x[0],x[1])
    for i in range(2,N):
        GCD = gcd(GCD,x[i])
    print(GCD)
Problem p03274 (python)

Fixed submission:
N, K = map(int, input().split())
arr = [int(x) for x in input().split()]
ps = []
ms = []
for i in range(N):
    if arr[i] == 0:
        K -= 1
    elif arr[i] < 0:
        ms.append(abs(arr[i]))
    elif arr[i] > 0:
        ps.append(arr[i])
ms = ms[::-1]
if K <= 0:
    ans = 0
else:
    ans = ps[K-1] if K <= len(ps) else 10**18
    ans = min(ans, ms[K-1]) if K <= len(ms) else ans
if len(ps) > 0 and len(ms) > 0:
    for i in range(len(ms)):
        if K-(i+1)-1 < len(ps):
            ans = min(ans, ms[i]*2 + ps[K-(i+1)-1])
    for i in range(len(ps)):
        if K-(i+1)-1 < len(ms):
            ans = min(ans, ps[i]*2 + ms[K-(i+1)-1])
print(ans)

Buggy submission (verdict: Runtime Error):
N,K =map(int,input().split())
arr = [int(x) for x in input().split()]
ps = []
ms = []
for i in range(N):
    if arr[i] == 0:
        K -= 1
    elif arr[i] < 0:
        ms.append(abs(arr[i]))
    elif arr[i] > 0:
        ps.append(arr[i])
ms = ms[::-1]
if K <= 0:
    ans = 0
else:
    ans = ps[K-1] if K <= len(ps) else 10**18
    ans = min(ans,ms[K-1]) if K <= len(ms) else ans
if len(ps) > 0 and len(ms) > 0:
    for i in range(K):
        if i == len(ms):
            break
        ans = min(ans,ms[i]*2 + ps[K-(i+1)-1])
    for i in range(K):
        if i == len(ps):
            break
        ans = min(ans,ps[i]*2 + ms[K-(i+1)-1])
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
N,K =map(int,input().split())
arr = [int(x) for x in input().split()]
ps = []
ms = []
for i in range(N):
    if arr[i] == 0:
        K -= 1
    elif arr[i] < 0:
        ms.append(abs(arr[i]))
    elif arr[i] > 0:
        ps.append(arr[i])
ms = ms[::-1]
if K == 0:
    ans = 0
else:
    ans = ps[K-1] if K <= len(ps) else 10**18
    ans = min(ans,ms[K-1]) if K <= len(ms) else ans
if len(ps) > 0 and len(ms) > 0:
    for i in range(K):
        if i == len(ms):
            break
        ans = min(ans,ms[i]*2 + ps[K-(i+1)-1])
    for i in range(K):
        if i == len(ps):
            break
        ans = min(ans,ps[i]*2 + ms[K-(i+1)-1])
print(ans)
Problem p03363 (python)

Fixed submission:
from itertools import accumulate

N = int(input())
count = {}
count.setdefault(0, 1)
for i in accumulate([int(x) for x in input().split()]):
    count.setdefault(i, 0)
    count[i] += 1
ans = 0
for i in count.values():
    ans += (i*(i-1)) // 2
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate

N = int(input())
count = [0 for i in range(N+1)]
count[0] += 1
for i in accumulate([int(x) for x in input().split()]):
    count[i] += 1
ans = 0
for i in count:
    ans += (i*(i-1)) // 2
print(ans)
Problem p03393 (python)

Fixed submission:
def solv(S):
    c = []
    for i in range(25, 0, -1):
        for j in range(i-1, -1, -1):
            if S[i] > S[j]:
                c.append(S[:j]+S[i])
    print(sorted(c)[0])
    return


alph = "abcdefghijklmnopqrstuvwxyz"
S = input()
for c in S:
    alph = alph.replace(c, "")
if alph != "":
    print(S+alph[0])
else:
    alph = "abcdefghijklmnopqrstuvwxyz"
    if S == alph[::-1]:
        print(-1)
    else:
        solv(S)

Buggy submission (verdict: Runtime Error):
def solv(S):
    c = []
    for i in range(25, 0, -1):
        for j in range(i-1, -1, -1):
            if S[i] > S[j]:
                c.append(S[:j]+S[i])
    print(sorted(c)[0])
    return


alph = "abcdefghijklmnopqrstuvwxyz"
S = input()
for c in S:
    alph = alph.replace(c, "")
if alph != "":
    print(S+alph[0])
else:
    if S == alph[::-1]:
        print(-1)
    else:
        solv(S)
Problem p02830 (python)

Fixed submission:
n = int(input())
s,t = map(str, input().split())
moji = ""

for i in range(n):
  moji += s[i] + t[i]

print(moji)

Buggy submission (verdict: Runtime Error):
2
ip cc
Problem p03145 (python)

Fixed submission:
a,b,c = map(int, input().split())

if (a >= b) and (a >= c):
    print(int(b*c/2))
if (b >= a) and (b >= c):
    print(int(a*c/2))
if (c >= a) and (c >= b):
    print(int(a*b/2))

Buggy submission (verdict: Runtime Error):
#a,b,c = map(int, input().split())

if (a >= b) and (a >= c):
    print(b*c/2)
if (b >= a) and (b >= c):
    print(a*c/2)
if (c >= a) and (c >= b):
    print(a*b/2)
Problem p03316 (python)

Fixed submission:
s = int(input())
s_hold = s
sum = 0
i = 0

while i < 9:
  sum = sum + s % 10
  s = s // 10
  i = i + 1

if sum == 0:
  print("Yes")
elif s_hold % sum == 0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = int(input())
s_hold = s
sum = 0
i = 0

while i < 9:
  sum = sum + s % 10
  s = s // 10
  i = i + 1

if s_hold % sum == 0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = input()
s_hold = s
sum = 0
i = 0

while i < 9:
  sum = sum + s % 10
  s = s // 10
  i = i + 1

if s_hold % sum == 0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = raw_input()
s_hold = s
sum = 0
i = 0

while i < 9:
  sum = sum + s % 10
  s = s // 10
  i = i + 1

if s_hold % sum == 0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = input()
s_hold = s
sum = 0
i = 0

while i < 9:
  sum = sum + s % 10
  s = s // 10
  i = i + 1

if s_hold % sum == 0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = input()
sum = 0
i = 0

while i < 9:
  sum = sum + s % 10
  s = s // 10
  i = i + 1

if s % sum == 0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = input()
sum = 0
i = 0

while i < 9:
  sum = sum + s % 10
  s = s // 10
  i = i + 1

if s % sum = 0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = 123456789
sum = 0
i = 0

while i < 9:
  sum = sum + s % 10
  s = s // 10
  i = i + 1

if s % sum = 0:
  print("Yes")
else:
  print("No")
Problem p02780 (python)

Fixed submission:
N,K = list(map(int,input().split(' ')))
pi = list(map(int,input().split(' ')))
value = sum(pi[:K])
max_value = value
for i in range(N-K):
  value -= pi[i]
  value += pi[i+K]
  max_value = max(value, max_value)
print((max_value+K)/2)

Buggy submission (verdict: Runtime Error):
N,K = list(map(int,input().split(' ')))
pi = list(map(int,input().split(' ')))
value = pi[:K]
max_value = value
for i in range(K, N):
  value -= pi[i-K]
  value += pi[K]
  if value>max_value:
    max_value = value
print(max_value/float(K))
Problem p02818 (python)

Fixed submission:
A, B, K = map(int, input().split())
if A > K:
    print(A-K, B)
elif A+B > K:
    print(0, A+B-K)
else:
    print(0, 0)

Buggy submission (verdict: Runtime Error):
a,b,k = map(int,input().spit())
if a > k:
  print(a-k, b)
elif a+b >k:
  print(0, a+b -k)
else:
  print(0,0)
Problem p02981 (python)

Fixed submission:
n,a,b = map(int, input().split())

d = n * a
t = b

ans = min([d,t])
print(ans)

Buggy submission (verdict: Runtime Error):
n,a,b = map(int, input().split())
print( min(n*a,b)
Problem p03136 (python)

Fixed submission:
n= int(input())
l = [int(x) for x in input().split()]
print('Yes' if max(l)<sum(l)-max(l) else 'No')

Buggy submission (verdict: Runtime Error):
n= int(input())
list = [int(x) for x in input().split()]

if max(list) <  (sum(list) - max(list)):
  print('Yes')
else:
  print('No'
Problem p03280 (python)

Fixed submission:
a,b =map(int, input().split())
print((a-1)*(b-1))

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

print((A-1)*(B-1))
Problem p03284 (python)

Fixed submission:
n,k = map(int, input().split())

if n %k :
  print(1)
else:
  print(0)

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

if n %k !=0:
  print(m%k)
else:
  print(0)
Problem p03544 (python)

Fixed submission:

l = [2,1]
for i in range(2,100):
  a = l[i-2]+l[i-1]
  l.append(a)
print(l[int(input())])

Buggy submission (verdict: Runtime Error):
n = int(input())
l = [2,1]
for i in range(2,100):
  a = l[i-2]+l[i-1]
  l.append(a)
print(l[int(input())])
Problem p03635 (python)

Fixed submission:
n,m = map(int, input().split())

print((n-1)*(m-1))

Buggy submission (verdict: Runtime Error):
n=int(input())
m=int(input())
print((n-1)*(m-1))
Problem p03944 (python)

Fixed submission:
w,h,n = map(int,input().split())
a = [list(map(int,input().split()))for _ in range(n)]
z1 = [0,0]
z2 = [w,h]
for i in range (n):
    if a[i][2] == 1 and z1[0] <= a[i][0]:
        z1[0] = a[i][0]
    elif a[i][2] == 2 and z2[0] >= a[i][0]:
        z2[0] = a[i][0]
    elif a[i][2] == 3 and z1[1] <= a[i][1] :
        z1[1] = a[i][1]
    elif a[i][2] == 4 and z2[1] >= a[i][1] :
        z2[1] = a[i][1]
if z2[0] > z1[0] and z2[1] > z1[1]:
    print((z2[0]-z1[0])*(z2[1]-z1[1]))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
h,n = map(int,input().split())
a = [list(map(int,input().split()))for _ in range(n)]
z1 = [0,0]
z2 = [w,h]
for i in range (n):
    if a[i][2] == 1 and z1[0] <= a[i][0]:
        z1[0] = a[i][0]
    elif a[i][2] == 2 and z2[0] >= a[i][0]:
        z2[0] = a[i][0]
    elif a[i][2] == 3 and z1[1] <= a[i][1] :
        z1[1] = a[i][1]
    elif a[i][2] == 4 and z2[1] >= a[i][1] :
        z2[1] = a[i][1]
if z2[0] > z1[0] and z2[1] > z1[1]:
    print((z2[0]-z1[0])*(z2[1]-z1[1]))
else:
    print(0)
Problem p04044 (python)

Fixed submission:
n,l = map(int,input().split())
s = list(input() for i in range(n))

c = sorted(s)
ans =''.join(c)
print(ans)

Buggy submission (verdict: Runtime Error):
n,l = map(int,input().split())
ss =[]
for i in range(n):
  s = input()
  ss.append(s)
ss.sort()
print(''.join(ss)
Problem p03212 (python)

Fixed submission:
n = int(raw_input().split()[0])

o1 = [3,5,7]
arr = [n]
ans = 0
def check(num):
    l = len(str(num))
    s = []
    for i in range(l):
        if str(num)[i] not in s:
            s.append(str(num)[i])
    if len(s) == 3:
        return True
    else:
        return False

for i in range(8):
    o2 = []
    for num in o1:
        new1 = num*10+3
        new2 = num*10+5
        new3 = num*10+7
        o2.append(new1)
        o2.append(new2)
        o2.append(new3)
        if check(new1):
            arr.append(new1)
            if n == new1:
                ans += 1
        if check(new2):
            arr.append(new2)
            if n == new2:
                ans += 1
        if check(new3):
            arr.append(new3)
            if n == new3:
                ans += 1
    o1 = o2
arr.sort()
print arr.index(n) + ans

Buggy submission (verdict: Runtime Error):
n = int(raw_input())
nd = len(str(n))

a3 = [357, 375, 537, 573, 735, 753]
arr_a = [[]for i in range(nd-2)]
arr_a[0] = a3
all_num = [357, 375, 537, 573, 735, 753]
for i in range(1, nd-2):
    for j in arr_a[i-1]:
        arr_a[i].append(j*10+3)
        arr_a[i].append(j*10+5)
        arr_a[i].append(j*10+7)
    for k in arr_a[i]:
        all_num.append(k)
# print arr_a

def only_2kind(a,b,n):
    if n <= 3:
        return []
    else:
        all_num = []
        o = [10 * a + b, 10 * b + a, 10 * a + a, 10 * b + b]
        for j in range(n-3):
            o2 = []
            for i in range(len(o)):
                o2.append(o[i]*10+a)
                o2.append(o[i] * 10 + b)
            # print o2
            for i in range(len(o2)):
                if o2[i] != int(str(a)*(j+3)) and o2[i] != int(str(b) * (j + 3)):
                    all_num.append(o2[i]*10+(15-a-b))
            o = o2
        return all_num

all_num+=(only_2kind(3,5,nd)+only_2kind(5,7,nd)+only_2kind(3,7,nd))
all_num.append(n)
all_num.sort()
# print len(all_num)
# for i in all_num:
#     print i
print all_num.index(n)
Problem p03241 (python)

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

yueshu = []
state = 0
if m % n == 0:
    print m / n
else:
    for i in range(1, int(m**0.5)+1):
        if m % i == 0:
            yueshu.insert(0, m/i)
            if i >= n:
                print m / i
                state = 1
                break
    if state == 0:
        for i in yueshu:
            if m % i == 0:
                if i >= n:
                    print m / i
                    state = 1
                    break
    if state == 0:
        print 1

Buggy submission (verdict: Runtime Error):
n, m = map(int, raw_input().split())

yueshu = []
for i in range(1, int(m**0.5)+1):
    if m % i == 0:
        yueshu.insert(0, m/i)
        if i >= n:
            print m / i
            break
for i in range(int(m**0.5)+1, m):
    if m % i == 0:
        if i >= n:
            print m / i
            break
Problem p03407 (python)

Fixed submission:
a, b, c = map(int, raw_input().split())
if a + b >= c:
  print "Yes"
else:
  print "No"

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,raw_input().split())
if a+b=>c:
  print "Yes"
else:
  print "No"
Problem p02780 (python)

Fixed submission:
n, k = [int(x) for x in input().split()]
p = [1/2 + int(x)/2 for x in input().split()]
sum_p =[]
buf = 0
for i in p:
    buf += i
    sum_p.append(buf)
max_t = 0
for i in range(n - k + 1):
    buf = sum_p[i+k-1]
    if i > 0:
        buf -= sum_p[i-1]
    if max_t < buf:
        max_t = buf
print(max_t)

Buggy submission (verdict: Runtime Error):
n,k = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
max_t = 0
ans = 0
for i in range(n - k +1):
	buf = sum(p(i:i+k))
	if max_t < buf:
		max_t = buf
		ans = 0
		for j in range(k):
			ans += (1+p[i+j]) * p[i+j] / 2
print(ans)

Buggy submission (verdict: Runtime Error):
n,k = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
max_t = 0
ans = 0
for i in range(n - k +1):
  buf = sum(p(i:i+k))
  if max_t < buf:
  	max_t = buf
    ans = 0
    for j in range(k):
      ans += (1+p[i+j]) * p[i+j] / 2
print(ans)
Problem p02786 (python)

Fixed submission:
print(2**(len(bin(int(input()))) - 2) - 1)

Buggy submission (verdict: Runtime Error):
print(2**(len(bin(int(nput()))) - 2) - 1)
Problem p02791 (python)

Fixed submission:
n = int(input())
p = [int(x) for x in input().split()]
ans = 0
mn = n
for i in p:
  if mn > i:
    mn = i
  if mn >= i:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
p = [int(x) for x in input.split()]
ans = 0
mn = n
for i in p:
  if mn > i:
    mn = i
  if mn >= i:
    ans += 1
print(ans)
Problem p02801 (python)

Fixed submission:
s = input()
print(chr(ord(s)+1))

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

Fixed submission:
a, b = map(int, input().split())
def factor(n):
    a = []
    while not n%2:
       n//=2
       a.append(2)
    i = 3
    while i*i<=n:
        while not n%i:
            n//=i
            a.append(i)
        i+=2
    if n>1:
        a.append(n)
    return a
print(len(set(factor(a))&set(factor(b)))+1)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
g = []
from math import gcd
g.append(gcd(a,b))
g.append(1)
if not a%2 and not b%2:
    g.append(2)
for i in range(3,g[0],2):
    if not a%i and not b%i:
        c = True
        for k in range(2, len(g)):
            if gcd(g[k],i)!=1:
                c = False
                break
        if c:
            g.append(i)
c = True
for i in range(1, len(g)):
    if gcd(g[0],g[i])!=1:
        c = False
        break
if c and g[0] != 1:
    print(len(g))
else:
    print(len(g)-1)
Problem p02924 (python)

Fixed submission:
n = int(input())
print((n*(n-1))//2)

Buggy submission (verdict: Runtime Error):
n = int(input())
print((n*(n-1)//2)
Problem p03160 (python)

Fixed submission:
N=int(input())

try:
    h = list(input().split())
    #listA<-[1,2,2,3,1]
    #print(listA)
    #ここに逐次処理を書けばいいと思う。
except:
    quit();
    #または、quit(),os.exit()をして止める。

dp=[]

for i in range(N):
    dp.append(0)

dp[1]=abs(int(h[0])-int(h[1]))

for j in range(2,N):
    min=float('inf')
    for i in range(j-2,j):
        num=abs(int(h[i])-int(h[j])) + dp[i]
        if num < min:
            min=num
    dp[j]=min

print(dp[N-1])

Buggy submission (verdict: Runtime Error):
import numpy as np

list1=[]

try:
    list1=list(map(int, input().split()))
except:
    quit();

N=list1[0]
W=list1[1]

inp=[]

for _ in range(N):
    try:
        inp.append(list(map(int, input().split())))
    except:
        quit();

inp=np.array(inp)
inp=inp.T
wlist=inp[0]
vlist=inp[1]

dp=np.zeros((N+1,W+1))

for i in range(N+1):
    if i >= 1:
        for j in range(W+1):
            if wlist[i-1] > j:
                dp[i][j]=dp[i-1][j]
            else:
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-wlist[i-1]]+vlist[i-1])

print(int(dp[N][W]))
Problem p02780 (python)

Fixed submission:
N, K = map(int,input().split())
p = list(map(int,input().split()))
p = list(map(lambda x:(x+1)/2,p))
from itertools import accumulate
A =  [0] + list(accumulate(p))
M = 0
index = 0
for x in range(N - K +  1):
    M = max(M,A[x + K] - A[x])
print(M)

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
p = sorted(list(map(int,input().split())))[::-1]
p = print(sum(map(lambda x:(x+1)/2,p)[:K]))
Problem p02899 (python)

Fixed submission:
N = int(input())
L = list(map(int,input().split()))
a = []
for i in range(len(L)):
    t = (L[i],i)
    a.append(t)
a = sorted(a)
for i in a:
    print(i[1]+1,end = ' ')

Buggy submission (verdict: Runtime Error):
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

typedef struct {
    int ipt; int num;
} tpl;

int asc(const void *a, const void *b) {
    return ((*(tpl *)a)).ipt - ((*(tpl *)b)).ipt;
}

int main(void){
    int N;
    scanf("%d", &N);
    int a[100000 + 10];
    tpl array[100000 + 10];
    for (int i = 0; i < N; i++) {
        scanf("%d", &array[i].ipt);
        array[i].num = i + 1;
    }
    qsort(array,N,sizeof (tpl), asc);
    for (int i = 0; i < N; i++) {
        printf("%d ",array[i].num);
    }

}
Problem p02918 (python)

Fixed submission:
a,b = map(int,input().split())
S = input()
tmp = S[0]
cnt = 0
L = []
for x in S:
    if tmp == x:
        cnt += 1
    else:
        L.append(cnt)
        cnt = 1
        tmp = x
L.append(cnt)
tmp = 0
for _ in range(b):
    for _ in range(2):
        try:
            tmp += L.pop(0)
        except:
            print(a- 1)
            quit()
try:
    tmp += L.pop(0)
except:
    print(a-1)
    quit()
L = [tmp] + L
print(sum(L) - len(L))

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
S = input()
tmp = S[0]
cnt = 0
L = []
for x in S:
    if tmp == x:
        cnt += 1
    else:
        L.append(cnt)
        cnt = 1
        tmp = x
L.append(cnt)
tmp = 0
for _ in range(b):
    for _ in range(2):
        tmp += L.pop(0)
tmp += L.pop(0)
L = [tmp] + L
print(sum(L) - len(L))
Problem p03074 (python)

Fixed submission:
N , K = map(int,input().split())
S = input()
L = []
flag = int(S[0])
for x in S:
    L.append(x)
cnt = 1
C = []
for i in range(len(L)):
    try:
        if L[i] == L[i+1]:
            cnt += 1
        else:
            C.append(cnt)
            cnt = 1
    except:
        pass
C.append(cnt)
ans = 0
from itertools import accumulate
accumulated =  [0]+list(accumulate(C))
ans = 0
A = 0
if flag == 0:
    if len(C) % 2 == 0:
        k = min(K,len(C)//2)
    else:
        k = min(K,len(C)//2+1)
else:
    k = min(K,len(C)//2)
for i in range(len(C)):
    try:
        if (flag + i) % 2 == 0:
            A =max(A, accumulated[i+2*k-1] - accumulated[i])
            ans = accumulated[i+2*k] - accumulated[i]
        else:
            A =max(A, accumulated[i+2*k-1] - accumulated[i])
            A =max(A, accumulated[i+2*k] - accumulated[i])
            ans = accumulated[i+2*k+1] - accumulated[i]
        A = max(ans,A)
    except:
        pass
print(A)

Buggy submission (verdict: Runtime Error):
N , K = map(int,input().split())
S = input()
L = []
flag = int(S[0])
for x in S:
    L.append(x)
cnt = 1
C = []
for i in range(len(L)):
    try:
        if L[i] == L[i+1]:
            cnt += 1
        else:
            C.append(cnt)
            cnt = 1
    except:
        pass
C.append(cnt)
ans = 0
from itertools import accumulate
accumulated =  [0]+list(accumulate(C))
ans = 0
A = 0
for i in range(len(C)):
    try:
        if (flag + i) % 2 == 0:
            K = min(K,len(C)//A+1)
            ans = accumulated[i+2*K] - accumulated[i]
        else:
            K = min(K,len(C)//2)
            ans = accumulated[i+2*K+1] - accumulated[i]
        A = max(ans,A)
    except:
        pass
print(A)