Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import math

N = int(input())
s = input()
for t in ["SS","SW","WS","WW"]:
    for i in range(1,N-1):
        if (s[i] =="o" and t[i]=="S") or (s[i]=="x" and t[i]=="W"):
            t += t[i-1]
        else:
            if t[i-1] =="S":
              t += "W"
            else:
              t +="S"
    if (t[N-2]==t[0] and ((s[N-1]=="o" and t[N-1]=="S") or (s[N-1]=="x" and t[N-1]=="W"))) or (t[N-2]!=t[0] and ((s[N-1]=="o" and t[N-1]=="W") or (s[N-1]=="x" and t[N-1]=="S"))):
         if (t[N-1]==t[1] and ((s[0]=="o" and t[0]=="S") or (s[0]=="x" and t[0]=="W"))) or (t[N-1]!=t[1] and ((s[0]=="o" and t[0]=="W") or (s[0]=="x" and t[0]=="S"))):
             print(t)
             break
else:
    print(-1)

Fixed submission:
N = int(input())
s = input()
for t in ["SS","SW","WS","WW"]:
    for i in range(1,N-1):
        if (s[i] =="o" and t[i]=="S") or (s[i]=="x" and t[i]=="W"):
            t += t[i-1]
        else:
            if t[i-1] =="S":
              t += "W"
            else:
              t +="S"
    if (t[N-2]==t[0] and ((s[N-1]=="o" and t[N-1]=="S") or (s[N-1]=="x" and t[N-1]=="W"))) or (t[N-2]!=t[0] and ((s[N-1]=="o" and t[N-1]=="W") or (s[N-1]=="x" and t[N-1]=="S"))):
         if (t[N-1]==t[1] and ((s[0]=="o" and t[0]=="S") or (s[0]=="x" and t[0]=="W"))) or (t[N-1]!=t[1] and ((s[0]=="o" and t[0]=="W") or (s[0]=="x" and t[0]=="S"))):
             print(t)
             break
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
inf = 10**18

N,Ma,Mb = map(int,input().split())
abc = [list(map(int,input().split())) for _ in range(N)]
inf = 10**9
dp = [[inf for i in range(N*10)] for i in range(N*10)]
dp[0][0] = 0
max_a = 0
max_b = 0
for i in range(N):
    max_a += abc[i][0]
    max_b += abc[i][1]
    for ai in range(abc[i][0],max_a+1)[::-1]:
        for bi in range(abc[i][1],max_b+1)[::-1]:
            dp[ai][bi] = min(dp[ai][bi],dp[ai-abc[i][0]][bi-abc[i][1]]+abc[i][2])
ans = inf
for i in range(1,min(max_a//Ma,max_b//Mb)):
    ans = min(ans,dp[i*Ma][i*Mb])
if ans == inf:
    print(-1)
else:
    print(ans)

Fixed submission:
N,Ma,Mb = map(int,input().split())
abc = [list(map(int,input().split())) for _ in range(N)]
inf = 10**9
dp = [[inf for i in range(N*10+1)] for i in range(N*10+1)]
dp[0][0] = 0
max_a = 0
max_b = 0
for i in range(N):
    max_a += abc[i][0]
    max_b += abc[i][1]
    for ai in range(abc[i][0],max_a+1)[::-1]:
        for bi in range(abc[i][1],max_b+1)[::-1]:
            dp[ai][bi] = min(dp[ai][bi],dp[ai-abc[i][0]][bi-abc[i][1]]+abc[i][2])
ans = inf
for i in range(1,min(max_a//Ma,max_b//Mb)):
    ans = min(ans,dp[i*Ma][i*Mb])
if ans == inf:
    print(-1)
else:
    print(ans)

Buggy python submission (verdict: Runtime Error):
N,Ma,Mb = map(int,input().split())
abc = [list(map(int,input().split())) for _ in range(N)]
inf = 10**9
dp = [[inf for i in range(N*10)] for i in range(N*10)]
dp[0][0] = 0
max_a = 0
max_b = 0
for i in range(N):
    max_a += abc[i][0]
    max_b += abc[i][1]
    for ai in range(abc[i][0],max_a+1)[::-1]:
        for bi in range(abc[i][1],max_b+1)[::-1]:
            dp[ai][bi] = min(dp[ai][bi],dp[ai-abc[i][0]][bi-abc[i][1]]+abc[i][2])
ans = inf
for i in range(1,min(max_a//Ma,max_b//Mb)):
    ans = min(ans,dp[i*Ma][i*Mb])
if ans == inf:
    print(-1)
else:
    print(ans)

Fixed submission:
N,Ma,Mb = map(int,input().split())
abc = [list(map(int,input().split())) for _ in range(N)]
inf = 10**9
dp = [[inf for i in range(N*10+1)] for i in range(N*10+1)]
dp[0][0] = 0
max_a = 0
max_b = 0
for i in range(N):
    max_a += abc[i][0]
    max_b += abc[i][1]
    for ai in range(abc[i][0],max_a+1)[::-1]:
        for bi in range(abc[i][1],max_b+1)[::-1]:
            dp[ai][bi] = min(dp[ai][bi],dp[ai-abc[i][0]][bi-abc[i][1]]+abc[i][2])
ans = inf
for i in range(1,min(max_a//Ma,max_b//Mb)):
    ans = min(ans,dp[i*Ma][i*Mb])
if ans == inf:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
import sympy
 
N = int(input())
if N == 1:
    print(1)
    exit()
d = {}
for i in range(2,N+1):
    a = sympy.factorint(i)
    for k,v in a.items():
        if k not in d:
            d[k] = 2
        else:
            d[k] +=v
ans = 1
for v in d.values():
    ans = (ans * v)%(10**9+7)
print(ans)

Fixed submission:
N = int(input())
prime = [0]*(N+1)
ans = 1
for i in range(2,N+1):
    d = 1
    while i > 1:
        d+=1
        while i % d == 0:
            i = i//d
            prime[d]+= 1
for j in range(N+1):
    ans = ans *(prime[j]+1)%(10**9+7)
print(ans)

Buggy python submission (verdict: Runtime Error):
import sympy
 
N = int(input())
if N == 1:
    print(1)
    exit()
d = {}
for i in range(2,N+1):
    a = sympy.factorint(i)
    for k,v in a.items():
        if k not in d:
            d[k] = 2
        else:
            d[k] +=v
ans = 1
for v in d.values():
    ans = (ans * v)%(10**9+7)
print(ans)

Fixed submission:
N = int(input())
prime = [0]*(N+1)
ans = 1
for i in range(2,N+1):
    d = 1
    while i > 1:
        d+=1
        while i % d == 0:
            i = i//d
            prime[d]+= 1
for j in range(N+1):
    ans = ans *(prime[j]+1)%(10**9+7)
print(ans)

Buggy python submission (verdict: Runtime Error):
import sympy

N = int(input())
if N == 1:
    print(1)
    exit()
d = {}
for i in range(2,N+1):
    a = sympy.factorint(i)
    for k,v in a.items():
        if k not in d:
            d[k] = 2
        else:
            d[k] +=v
ans = 1
for v in d.values():
    ans = (ans * v)%(10**9+7)
print(ans)


Fixed submission:
N = int(input())
prime = [0]*(N+1)
ans = 1
for i in range(2,N+1):
    d = 1
    while i > 1:
        d+=1
        while i % d == 0:
            i = i//d
            prime[d]+= 1
for j in range(N+1):
    ans = ans *(prime[j]+1)%(10**9+7)
print(ans)

Buggy python submission (verdict: Runtime Error):
import itertools
import math
import sympy
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
from collections import Counter
inf = 10**10

N = int(input())
if N == 1:
    print(1)
    exit()
d = {}
for i in range(2,N+1):
    a = sympy.factorint(i)
    for k,v in a.items():
        if k not in d:
            d[k] = 2
        else:
            d[k] +=v
ans = 1
for v in d.values():
    ans = (ans * v)%(10**9+7)
print(ans)

Fixed submission:
N = int(input())
prime = [0]*(N+1)
ans = 1
for i in range(2,N+1):
    d = 1
    while i > 1:
        d+=1
        while i % d == 0:
            i = i//d
            prime[d]+= 1
for j in range(N+1):
    ans = ans *(prime[j]+1)%(10**9+7)
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
s[5] = " "
s[13] = " "
print(s)



Fixed submission:
s = list(input())
s[5] = " "
s[13] = " "
ans = map(str,s)

print("".join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())
ans = 0
for i in range(0,k+1):
  for j in range(0,k+1):
    for l in range(0,k+1):
      if i + j + l == s:
        ans += 1
      else:
        continue
print(ans)

Fixed submission:

k,s = map(int,input().split())
ans = 0
for i in range(k+1):
    for j in range(k+1):
        if k>=s-i-j>=0:
            ans +=1
        else:
            continue
print(ans)
Buggy python submission (verdict: Runtime Error):
sx,sy,tx,ty = map(int,input().split())
print("U"*(ty-sy)+"R"*(tx-sx)+"D"*(ty-sy)+"L"*(ty-sy)+"L"+"U"*(ty-sy+1)+"R"*(tx-sx+1)+"D"+"R"+"D"*(ty-sy+1)+"L"*(tx-sx+1)+"U"

Fixed submission:
sx,sy,tx,ty = map(int,input().split())
print("U"*(ty-sy)+"R"*(tx-sx)+"D"*(ty-sy)+"L"*(tx-sx)+"L"+"U"*(ty-sy+1)+"R"*(tx-sx+1)+"D"+"R"+"D"*(ty-sy+1)+"L"*(tx-sx+1)+"U")
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
a = list(map(int,input().split()))
A = [0]*(N+1)
S = [0]*(N+1)

for i in range(N):
    A[i+1] = A[i]+max(0,a[i])
    S[i+1] = S[i]+a[i]

ans = -inf
for i in range(0,N-K+1):
    ans = max(ans,A[i]+max(0,S[i+K]-S[i])+(A[N]-A[i+K]))

print(ans)

Fixed submission:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

#色を塗るタイプの操作は逆順に見ていけば確定した色が上書きされることは無いと思える
N,K = map(int,input().split())
a = list(map(int,input().split()))
A = [0]*(N+1)
S = [0]*(N+1)

for i in range(N):
    A[i+1] = A[i]+max(0,a[i])
    S[i+1] = S[i]+a[i]

ans = -inf
for i in range(0,N-K+1):
    ans = max(ans,A[i]+max(0,S[i+K]-S[i])+(A[N]-A[i+K]))

print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
if s == "a" or s=="i" or s=="u" or s=="e" or s=="o":
  print(vowel)
else:
  print(consonant)

Fixed submission:
s = input()
if s == "a" or s=="i" or s=="u" or s=="e" or s=="o":
  print("vowel")
else:
  print("consonant")
Buggy python submission (verdict: Runtime Error):
n,t = map(int,input().split())
a = list(map(int,input().split()))
ma = inf
benefit = 0
ans = 1
for i in range(n):
    if a[i] < ma:
        ma = a[i]
    else:
        b = a[i]-ma
        if b == benefit:
            ans += 1

        if b > benefit:
            benefit = b
            ans = 1
print(ans)

Fixed submission:
inf = 10**18
mod = 10**9+7

n,t = map(int,input().split())
a = list(map(int,input().split()))
ma = inf
benefit = 0
ans = 1
for i in range(n):
    if a[i] < ma:
        ma = a[i]
    else:
        b = a[i]-ma
        if b == benefit:
            ans += 1

        if b > benefit:
            benefit = b
            ans = 1
print(ans)
Buggy python submission (verdict: Runtime Error):
s = list(input())
K = int(input())
for i in range(len(s)-1):
    if K == 0:
        break
    else:
        if s[i] == "a":
            continue
        else:
            if 123-ord(s[i]) <= K:
                K -= 123-ord(s[i])
                s[i] = "a"

K = K %26
if K > 0:
    if ord(s[-1])+K <= 122:
        s[-1] = chr(ord(s[-1])+K)
    else:
        s[-1] = chr(97+(ord(s[-1]+K-122)))

print(*s,sep="")

Fixed submission:
s = list(input())
K = int(input())
for i in range(len(s)-1):
    if K == 0:
        break
    else:
        if s[i] == "a":
            continue
        else:
            if 123-ord(s[i]) <= K:
                K -= 123-ord(s[i])
                s[i] = "a"
K = K %26
if K > 0:
    if ord(s[-1])+K <= 122:
        s[-1] = chr(ord(s[-1])+K)
    else:
        s[-1] = chr(96+((ord(s[-1])+K-122)))

print(*s,sep="")
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
d = input().split()
while len(set(str(n)) & set(d)) !=0:
    n +=1
print(n)


Fixed submission:
a = list(map(int,input().split()))
if a.count(5)==2 and a.count(7)==1:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
num =set([0,1,2,3,4,5,6,7,8,9])
n,k = input().split()
d = list(map(int,input().split()))
a = list(num - set(d))
a.sort()
ans =[]
for i in range(len(n)):
    for j in a:
        if int(n[i]) <= j:
            ans.append(a[i])
            break
    if a[-1] < int(n[i]):
        ans.append(a[0])
l = map(str,ans)
b = "".join(l)
if int(b) < int(n):
    if a[0] != 0:
        print(a[0]*(10**(len(n)))+int(b))
    else:
        print(a[1]*(10**(len(n))) + int(b))
else:
    print(int(b))

Fixed submission:
n,k = map(int,input().split())
d = input().split()
while len(set(str(n)) & set(d)) !=0:
    n +=1
print(n)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


n, k = MI()
if ((n - 1) * (n - 2)) // 2 < k:
    print(-1)
else:
    graph = []
    for i in range(1, n + 1):
        for j in range(i, n + 1):
            if i != j:
                graph.append([i, j])
    for i in range(n - 1):
        print(*graph[i])
    for k in range((((n - 1) * (n - 2)) // 2) - k):
        print(*graph[n + k])


Fixed submission:
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


n, k = MI()
if ((n - 1) * (n - 2)) // 2 < k:
    print(-1)
else:
    m = (n * (n - 1)) // 2 - k
    print(m)
    graph = []
    for i in range(1, n + 1):
        for j in range(i, n + 1):
            if i != j:
                graph.append([i, j])
    for i in range(m):
        print(*graph[i])
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


x, a =MI()
print(0 if x < a else 10)
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


x, a =MI()
print(0 if x < a else 10)


Fixed submission:
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


x, a = MI()
print(0 if x < a else 10)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


n, x = MI()
l = LI()
z = 0
cnt = 0
if n == 1:
    if l[0] <= x:
        print(2)
    else:
        print(1)
else:
    while z <= x and cnt < n+1:
        z = z + l[cnt]
        cnt += 1
    print(cnt)


Fixed submission:
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


n, x = MI()
l = LI()
cnt = 0
ans = []
ans.append(0)
z = 0
for i in range(n):
    z += l[i]
    ans.append(z)
for num in ans:
    if num <= x:
        cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


n = II()
a = sorted(LI(), key=abs)
for i in range(n - 1):
    if abs(a[i]) == abs(a[i+1]) and a[i] > a[i+1]:
        hoge = a[i+1]
        a[i+1] = a[i]
        a[i] = hoge
# print(a)
newa = []
zerocnt = 0
for i in a:
    if i != 0:
        newa.append(i)
    else:
        zerocnt += 1
s = 0
ans = []
tmp = newa[0]
for i in range(n - 1 - zerocnt):
    if i == n - 2 - zerocnt:
        if tmp < newa[i+1]:
            ans.append((newa[i+1], tmp))
            tmp = newa[i+1] - tmp
            print(tmp)
        else:
            ans.append((tmp, newa[i+1]))
            tmp = tmp - newa[i+1]
            print(tmp)
    elif i == 0:
        tmp = newa[i] - newa[i+1]
        ans.append((newa[i], newa[i+1]))
    else:
        tmp = tmp - newa[i+1]
        ans.append((tmp, newa[i+1]))
for i in ans:
    print(str(i[0])+' '+str(i[1]))
for i in range(zerocnt):
    print(str(tmp)+' '+str(0))



Fixed submission:
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


n = II()
a = sorted(LI(), reverse=True)
ans = []
s = 0
if all([i < 0 for i in a]):
    tmp = a[0]
    for i in range(1, n):
        ans.append((tmp, a[i]))
        tmp -= a[i]
    print(tmp)
    for i in ans:
        print(i[0], i[1])
else:
    tmp = a[-1]
    for i in range(1, n - 1):
        if a[i] < 0:
            break
        ans.append((tmp, a[i]))
        tmp -= a[i]

    ans.append((max(a), tmp))
    tmp = max(a) - tmp

    for i in range(1, n - 1):
        if a[i] >= 0:
            continue
        ans.append((tmp, a[i]))
        tmp -= a[i]
    print(tmp)
    for i in ans:
        print(i[0], i[1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
n, k = map(int, sys.stdin.readline().split())
s = [int(string) for string in input()]

tmp = []
flag = s[0]
cnt = 1

if s[0] == 0:
    tmp.append(0)
for i in range(1, n):
    if flag == s[i]:
        cnt += 1
    else:
        tmp.append(cnt)
        cnt = 1
        flag = 1 - flag
tmp.append(cnt)
if s[-1] == 0:
    tmp.append(0)

ans = 0
for i in range(0, n, 2):
    ans_tmp = 0
    for j in range(2*k+1):
        if len(tmp) <= i+j:
            break
        ans_tmp += tmp[i+j]
    ans = max(ans, ans_tmp)

print(ans)

Fixed submission:
import sys
import itertools
n, k = map(int, sys.stdin.readline().split())
s = [int(string) for string in input()]

tmp = []
flag = s[0]
cnt = 1

if s[0] == 0:
    tmp.append(0)
for i in range(1, n):
    if flag == s[i]:
        cnt += 1
    else:
        tmp.append(cnt)
        cnt = 1
        flag = 1 - flag
tmp.append(cnt)
if s[-1] == 0:
    tmp.append(0)

ruisekiwa = list(itertools.accumulate(tmp))
ans = 0
ruisekiwa.insert(0, 0)
for left in range(0, len(ruisekiwa), 2):
    right = left + 2*k+1
    if len(ruisekiwa) <= right:
        right = len(ruisekiwa)-1
    ans = max(ans, ruisekiwa[right] - ruisekiwa[left])

print(ans)