Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline
from collections import defaultdict
r,c,k = map(int,input().split())
K = defaultdict(int)
for _ in range(k):
    x,y,z= [int(i) for i in input().split()]
    K[(x,y)] = z


dp = [[0]*(c+1) for _ in range(4)]
 
for i in range(1, r+1):
    for j in range(1, c+1):
        v = K[(i, j)]
        dp[0][j] = max(dp[0][j-1], dp[0][j], dp[1][j], dp[2][j], dp[3][j])
        dp[1][j] = max(dp[1][j-1], dp[0][j]+v) if v>0 else dp[1][j-1]
        dp[2][j] = max(dp[2][j-1], dp[1][j-1]+v) if v>0 else dp[2][j-1]
        dp[3][j] = max(dp[3][j-1], dp[2][j-1]+v) if v>0 else dp[3][j-1]
        
print(max(dp[i][-1] for i in range(4)))

Fixed submission:
import sys
input = sys.stdin.buffer.readline
H, W, K = map(int, input().split())
B = {}
for _ in range(K):
    r, c, v = map(int, input().split())
    B[(r, c)] = v

dp = [[0]*(W+1) for _ in range(4)]

for i in range(1, H+1):
    for j in range(1, W+1):
        if (i, j) in B:
            v = B[(i, j)]
            dp[0][j] = max(dp[0][j-1], dp[0][j], dp[1][j], dp[2][j], dp[3][j])
            dp[1][j] = max(dp[1][j-1], dp[0][j]+v)
            dp[2][j] = max(dp[2][j-1], dp[1][j-1]+v)
            dp[3][j] = max(dp[3][j-1], dp[2][j-1]+v)
        else:
            dp[0][j] = max(dp[0][j-1], dp[0][j], dp[1][j], dp[2][j], dp[3][j])
            dp[1][j] = dp[1][j-1]
            dp[2][j] = dp[2][j-1]
            dp[3][j] = dp[3][j-1]

print(max(dp[i][-1] for i in range(4)))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
r,c,k = map(int,input().split())
K = defaultdict(int)
for _ in range(k):
    x,y,z= [int(i) for i in input().split()]
    K[(x,y)] = z


dp = [[0]*(c+1) for _ in range(4)]
 
for i in range(1, r+1):
    for j in range(1, c+1):
        v = K[(i, j)]
        dp[0][j] = max(dp[0][j-1], dp[0][j], dp[1][j], dp[2][j], dp[3][j])
        dp[1][j] = max(dp[1][j-1], dp[0][j]+v) if v>0 else dp[1][j-1]
        dp[2][j] = max(dp[2][j-1], dp[1][j-1]+v) if v>0 else dp[2][j-1]
        dp[3][j] = max(dp[3][j-1], dp[2][j-1]+v) if v>0 else dp[3][j-1]
        
print(max(dp[i][-1] for i in range(4)))

Fixed submission:
import sys
input = sys.stdin.buffer.readline
H, W, K = map(int, input().split())
B = {}
for _ in range(K):
    r, c, v = map(int, input().split())
    B[(r, c)] = v

dp = [[0]*(W+1) for _ in range(4)]

for i in range(1, H+1):
    for j in range(1, W+1):
        if (i, j) in B:
            v = B[(i, j)]
            dp[0][j] = max(dp[0][j-1], dp[0][j], dp[1][j], dp[2][j], dp[3][j])
            dp[1][j] = max(dp[1][j-1], dp[0][j]+v)
            dp[2][j] = max(dp[2][j-1], dp[1][j-1]+v)
            dp[3][j] = max(dp[3][j-1], dp[2][j-1]+v)
        else:
            dp[0][j] = max(dp[0][j-1], dp[0][j], dp[1][j], dp[2][j], dp[3][j])
            dp[1][j] = dp[1][j-1]
            dp[2][j] = dp[2][j-1]
            dp[3][j] = dp[3][j-1]

print(max(dp[i][-1] for i in range(4)))
Buggy python submission (verdict: Runtime Error):
import math
def dist(x,y):
  return math.sqrt(x**2+y**2)

n,d=map(int,input().split())
i=0
for _ in range(d):
  x,y=map(int,input().split())
  if dist(x,y)<=d:
    i+=1
print(i)

Fixed submission:
import math

def dist(x,y):
  return math.sqrt(x**2+y**2)

n,d=map(int,input().split())
i=0
for _ in range(n):
  x,y=map(int,input().split())
  if dist(x,y)<=d:
    i+=1
    
print(i)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
A=[int(i) for i in input().split()]


def f(i):
    if i<0: return True
    if i>= 10**9: return False
    x = sum([(a-1)//i for a in A])
    if x<=k:
        return True
    else:
        return False
l=-1
r=10**9
while r-l>1:
    m = (l+r)//2
    if f(m):
        r=m
    else:
        l=m
    #print(l,m,r)
print(r)

Fixed submission:
n,k=map(int,input().split())
A=[int(i) for i in input().split()]


def f(i):
    if i<=0: return False
    if i>= 10**9: return True
    x = sum([(a-1)//i for a in A])
    if x<=k:
        return True
    else:
        return False
l=-1
r=10**9
while r-l>1:
    m = (l+r)//2
    if f(m):
        r=m
    else:
        l=m
    #print(l,m,r)
print(r)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
A=[int(i) for i in input().split()]


def f(A,i):
    return sum([(a-1)//i for a in A])
l=-1
r=10**9+1
while r-l>1:
    m = (l+r)//2
    #print(m)
    x = f(A,m)
    if x<=k:
        r=m
    else:
        l=m
    #print(x,k,l,r,m)
print(m)

Fixed submission:
n,k=map(int,input().split())
A=[int(i) for i in input().split()]


def f(i):
    if i<=0: return False
    if i>= 10**9: return True
    x = sum([(a-1)//i for a in A])
    if x<=k:
        return True
    else:
        return False
l=-1
r=10**9
while r-l>1:
    m = (l+r)//2
    if f(m):
        r=m
    else:
        l=m
    #print(l,m,r)
print(r)
Buggy python submission (verdict: Runtime Error):
T=int(input()
for _ in range(T):      
    N = int(input())
    A = list(map(int, input().split()))
    S = list(map(int, input()))

    for i in range(N-1, -1, -1):
        ai = A[i]
        if ai==0:
            continue
        top = ai.bit_length() - 1

        #assert ai & 1<<top
        for j in range(i-1, -1, -1):
            if A[j] >> top & 1:
                A[j] ^= ai
    print(A,S)
    for a, c in zip(A[::-1], S[::-1]):
        if c==1 and a:
            break
    else:
        print("0")
        continue
    print("1")

Fixed submission:
T=int(input())
for _ in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    S = list(map(int, input()))

    for i in range(N-1, -1, -1):
        ai = A[i]
        if ai==0:
            continue
        top = ai.bit_length() - 1

        #assert ai & 1<<top
        for j in range(i-1, -1, -1):
            if A[j] >> top & 1:
                A[j] ^= ai
    #print(A,S)
    for a, c in zip(A[::-1], S[::-1]):
        if c==1 and a:
            break
    else:
        print("0")
        continue
    print("1")
Buggy python submission (verdict: Runtime Error):
from collections import deque
n,m = map(int,input().split())
G = [set() for _ in range(n)]
for _ in range(m):
    a,b = map(int,input().split())
    G[a-1].add(b-1)
    G[b-1].add(a-1)
ans = [-1 for _ in range(n)]

ans[0]=0
q = deque([0])
q2 = deque()

seen = set()
seen.add(0)

for _ in range(n):
    while q:
        q2 = deque()
        #print(ans,q,q2,seen)
        i = q.pop()
        for j in G[i]:
            if j in seen:
                continue
            q2.append(j)
            ans[j] = i+1
            seen.add(j)
            '''if cost[i] ==-1:
                cost[i] = c
                ans[i] = j
            elif cost[i] > cost[j] + 1:
                cost[i] = cost[j] + 1
                ans[i] = j
            else:
                pass'''
    q = q2
    if len(seen) == n:
        print("Yes")
        print(*ans[1:], sep="\n")
        sys.exit()
        
print("No")

Fixed submission:
from collections import deque

N, M = map(int, input().split())
d = [set() for _ in range(N+1)]
for _ in range(M):
    a, b = map(int, input().split())
    d[a].add(b)
    d[b].add(a)

queue=deque([1])
vs = set([1])
parents = [0] * (N+1)
while queue:
    v = queue.popleft()
    for u in d[v]:
        if u in vs:
            continue
        parents[u] = v
        vs.add(u)
        queue.append(u)
print("Yes")
for x in parents[2:]:
    print(x)
Buggy python submission (verdict: Runtime Error):
import sys
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
d=dict()
for i,a in enumerate(A):
    d[i+1] = a
p=1
li = set()
li.add(1)
for i in range(k):
    #print(p,li)
    p = d[p]
    #print(p,li)
    if p in li:
        cyc =  i+ 1- pidx
        q = 1
        st=0
        while q != p:
            q = d[q]
            st+=1
        k = (k-st) % cyc + st
        r = 1
        #print(k)
        for _ in range(k):
            #print(r)
            r = d[r]
        print(r)
        sys.exit()
    li.add(p)
else:
    print(p)

Fixed submission:
import sys
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
d=dict()
for i,a in enumerate(A):
    d[i+1] = a
p=1
li = set()
li.add(1)
for i in range(k):
    #print(p,li)
    p = d[p]
    #print(p,li)
    if p in li:
        cyc =  i + 1
        q = 1
        st=0
        while q != p:
            q = d[q]
            st+=1
        cyc -=st
        k = (k-st) % cyc + st
        r = 1
        #print(k)
        for _ in range(k):
            #print(r)
            r = d[r]
        print(r)
        sys.exit()
    li.add(p)
else:
    print(p)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
d=dict()
for i,a in enumerate(A):
    d[i+1] = a
p=1
li = [1]
for i in range(k):
    #print(p,li)
    p = d[p]
    if p in li:
        pidx = li.index(p)
        cyc = i+1-pidx
        print(li[(k-pidx)%cyc+li.index(p)])
        sys.exit()
    li.append(p)
else:
    print(p)

Fixed submission:
import sys
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
d=dict()
for i,a in enumerate(A):
    d[i+1] = a
p=1
li = set()
li.add(1)
for i in range(k):
    #print(p,li)
    p = d[p]
    #print(p,li)
    if p in li:
        cyc =  i + 1
        q = 1
        st=0
        while q != p:
            q = d[q]
            st+=1
        cyc -=st
        k = (k-st) % cyc + st
        r = 1
        #print(k)
        for _ in range(k):
            #print(r)
            r = d[r]
        print(r)
        sys.exit()
    li.add(p)
else:
    print(p)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=[int(i) for i in input().split()]
b=[A[i] - (i+1) for i in range(n)]
c=[A[i] + (i+1) for i in range(n)]
ans=0
for i in range(n):
    ans += (c[i+1:].count(-c[i]))
    ans += (b[i+1:].count(-c[i]))
print(ans)

Fixed submission:
from collections import defaultdict
n=int(input())
A=[int(i) for i in input().split()]
d=defaultdict(int)

b=[A[i] - (i+1) for i in range(n)]
c=[A[i] + (i+1) for i in range(n)]

l=[]
ans=0
d=defaultdict(int)
for i in range(1,n)[::-1]:
    d[c[i]]+=1
    d[b[i]]+=1
    ans+= d[-c[i-1]]
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, n = map(int, input().split())
 
x = min(b - 1, n)
print(int(a * x / b) - a * int(x / b))

import random
a,b,n=map(int,input().split())
def f(x):
    return int(a*x/b)-a*int(x/b)
if n<b:
    ans =f(n)
else:
    t = n
    u = b - 1
    v=min(t,u)
    ans=f(v)
print(ans)

Fixed submission:
a,b,n=map(int,input().split())
if n>=b-1:
  print(a*(b-1)//b)
else:
  print(a*n//b)
Buggy python submission (verdict: Runtime Error):
ppy

Fixed submission:
s=input()
if s =="AAA" or s=="BBB":
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S=input()
q=int(input())
Q=[]
state=True
ans=deque(S)
for _ in range(q):
    t = input().split()
    if t[0] == "1":
        Q.append(int(t[0]))
    elif t[0] == "2":
        Q.append((int(t[0]),int(t[1]),t[2]))
for que in Q:
    if que == 1:
        state = not state
    else:
        if state:
            if que[1] == 1:
                ans.appendleft(que[2])
            else:
                ans.append(que[2])
        else:
            if que[1] == 2:
                ans.appendleft(que[2])
            else:
                ans.append(que[2])
anss=""
if not state:
    while len(ans) >0:
        anss += ans.pop()
else:
    while len(ans) >0:
        anss += ans.popleft()
print(anss)


Fixed submission:
from collections import deque
S=input()
q=int(input())
Q=[]
state=True
ans=deque(S)
for _ in range(q):
    t = input().split()
    if t[0] == "1":
        Q.append(int(t[0]))
    elif t[0] == "2":
        Q.append((int(t[0]),int(t[1]),t[2]))
for que in Q:
    if que == 1:
        state = not state
    else:
        if state:
            if que[1] == 1:
                ans.appendleft(que[2])
            else:
                ans.append(que[2])
        else:
            if que[1] == 2:
                ans.appendleft(que[2])
            else:
                ans.append(que[2])
anss=""
if not state:
    while len(ans) >0:
        anss += ans.pop()
else:
    while len(ans) >0:
        anss += ans.popleft()
print(anss)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S=input()
q=int(input())
Q=[]
state=True
ans=deque(S)
for _ in range(q):
    t = input().split()
    if t[0] == "1":
        Q.append(int(t[0]))
    elif t[0] == "2":
        Q.append((int(t[0]),int(t[1]),t[2]))
for que in Q:
    if que == 1:
        state = not state
    else:
        if state:
            if que[1] == 1:
                ans.appendleft(que[2])
            else:
                ans.append(que[2])
        else:
            if que[1] == 2:
                ans.appendleft(que[2])
            else:
                ans.append(que[2])
anss=""
if not state:
    while len(ans) >0:
        anss += ans.pop()
else:
    while len(ans) >0:
        anss += ans.popleft()
print(anss)

Fixed submission:
from collections import deque
S=input()
q=int(input())
Q=[]
state=True
ans=deque(S)
for _ in range(q):
    t = input().split()
    if t[0] == "1":
        Q.append(int(t[0]))
    elif t[0] == "2":
        Q.append((int(t[0]),int(t[1]),t[2]))
for que in Q:
    if que == 1:
        state = not state
    else:
        if state:
            if que[1] == 1:
                ans.appendleft(que[2])
            else:
                ans.append(que[2])
        else:
            if que[1] == 2:
                ans.appendleft(que[2])
            else:
                ans.append(que[2])
anss=""
if not state:
    while len(ans) >0:
        anss += ans.pop()
else:
    while len(ans) >0:
        anss += ans.popleft()
print(anss)
Buggy python submission (verdict: Time Limit Exceeded):
n,d,a=map(int,input().split())
x=[]
h=[]
xh=[]
for _ in range(n):
    i,j = map(int,input().split())
    xh.append((i,j))
xh = sorted(xh, key=lambda x: x[0])
c=[]
ans=0
max_=[]
for i in range(n):
    value = xh[i][1]
    for ii,m in enumerate(max_):
        if m>=xh[i][0]:
            value -= a * c[ii]
    #print(xh[i][0],value)
    temp = max(0,-(-value//a))
    ans += temp
    c.append(temp)
    max_.append(xh[i][0]+2*d)
print(ans)

Fixed submission:
import sys
from bisect import bisect
 
class BIT():#1-indexed
	def __init__(self, size):
		self.table = [0 for _ in range(size+2)]
		self.size = size
 
	def Get(self, i):#iを返す
		s = 0
		while i > 0:
			s += self.table[i]
			i -= (i & -i)
		return s
 
	def PointAdd(self, i, x):#
		while i <= self.size:
			self.table[i] += x
			i += (i & -i)
		return
 
	def SegAdd(self, l, r, x):#lからrにxを足す
		self.PointAdd(l, x)
		self.PointAdd(r+1, -x)
		return
 
 
n, d, a = map(int, input().split())
d *= 2
mo = sorted([list(map(int, input().split())) for _ in range(n)])
for i in range(n):
	mo[i][1] = (mo[i][1]-1)//a + 1
reach = []
moo = [x[0] for x in mo]
mooo = [x[1] for x in mo]
for x in moo:
	reach.append(bisect(moo, x+d)-1)
#print(reach)
 
bit = BIT(n)
 
ans = 0
for i, h in enumerate(mooo):
	gap = max(0, h - bit.Get(i+1))
	bit.SegAdd(i+1, reach[i]+1, gap)
	ans += gap
 
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import random
from fractions import gcd
lim=10**9+7
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return int(x)
n=int(input())
#A=random.sample(list(range(1, 10**6)), k=10**4)
A=[int(i) for i in input().split()]
Z=lcm(A)
ans=0
for a in A:
    ans += Z//a
print(ans % lim)


Fixed submission:
from fractions import gcd
lim=10**9+7
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return int(x)


n=int(input())
A=[int(i) for i in input().split()]
A_inv = [pow(a,lim-2,lim) for a in A]

Z = A[0]
k=1
for i in range(1, n):
    Z = Z // gcd(Z, A[i]) * A[i]
ans=0

Z=Z % lim
for i in range(n):
    ans = ( ans + Z*A_inv[i] ) % lim
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
lim=10**9+7
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return int(x)
n=int(input())
#A=random.sample(list(range(1, 10**6)), k=10**4)
A=[int(i) for i in input().split()]
Z=lcm(A)
ans=0
for a in A:
    ans =(ans+Z//a) % lim
print(ans)

Fixed submission:
from fractions import gcd
lim=10**9+7
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return int(x)


n=int(input())
A=[int(i) for i in input().split()]
A_inv = [pow(a,lim-2,lim) for a in A]

Z = A[0]
k=1
for i in range(1, n):
    Z = Z // gcd(Z, A[i]) * A[i]
ans=0

Z=Z % lim
for i in range(n):
    ans = ( ans + Z*A_inv[i] ) % lim
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import random
from fractions import gcd
lim=10**9+7
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return int(x)
n=int(input())
#A=random.sample(list(range(1, 10**6)), k=10**4)
A=[int(i) for i in input().split()]
Z=lcm(A)
ans=0
for a in A:
    ans =(ans+Z//a) % lim
print(ans)

Fixed submission:
from fractions import gcd
lim=10**9+7
def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return int(x)


n=int(input())
A=[int(i) for i in input().split()]
A_inv = [pow(a,lim-2,lim) for a in A]

Z = A[0]
k=1
for i in range(1, n):
    Z = Z // gcd(Z, A[i]) * A[i]
ans=0

Z=Z % lim
for i in range(n):
    ans = ( ans + Z*A_inv[i] ) % lim
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
lim = 10**9+7
n=int(input())
A=[int(i) for i in input().split()]
binary = [bin(i)[2:].zfill(60)[::-1] for i in A]

ans=0
for i in range(60):
    l = [s[i] for s in binary]
    #print(i,l.count("0") * l.count("1"))
    ans = (ans+ ((l.count("0") * l.count("1"))% lim * 2**i )% lim)% lim
print(ans % lim)

Fixed submission:
lim = 10**9+7
n=int(input())
A=[int(i) for i in input().split()]
binary = [bin(i)[2:].zfill(60)[::-1] for i in A]

ans=0
for i in range(60):
    l = [s[i] for s in binary]
    #print(i,l.count("0") * l.count("1"))
    ans = (ans+ ((l.count("0") * l.count("1"))% lim * 2**i )% lim)% lim
print(ans % lim)

Buggy python submission (verdict: Time Limit Exceeded):
lim = 10**9+7
n=int(input())
A=[int(i) for i in input().split()]
binary = [bin(i)[2:].zfill(60)[::-1] for i in A]

ans=0
for i in range(60):
    l = [s[i] for s in binary]
    #print(i,l.count("0") * l.count("1"))
    ans +=  l.count("0") * l.count("1") * 2**i 
print(ans % lim)

Fixed submission:
lim = 10**9+7
n=int(input())
A=[int(i) for i in input().split()]
binary = [bin(i)[2:].zfill(60)[::-1] for i in A]

ans=0
for i in range(60):
    l = [s[i] for s in binary]
    #print(i,l.count("0") * l.count("1"))
    ans = (ans+ ((l.count("0") * l.count("1"))% lim * 2**i )% lim)% lim
print(ans % lim)

Buggy python submission (verdict: Time Limit Exceeded):
lim=10**9+7
H=int(input())
A=[int(i) for i in input().split()]

#M=[[0]*H for _ in range(H)]
#K=[[0]*H for _ in range(H)]
for N in range(0,H+1):
    sum_=0
    sum2=0
    for i in range(N):
        for j in range(i+1,N):
            #M[i][j]=A[i]^A[j]
            #K[i][j]=A[i]+A[j]
            sum_ = (sum_+(A[i]^A[j])) % lim
            #sum2 = (sum2+(A[i]+A[j])) 
print(sum_)
#print(sum2)
#print(sum2-sum_)
#print("###")

Fixed submission:
lim = 10**9+7
n=int(input())
A=[int(i) for i in input().split()]
binary = [bin(i)[2:].zfill(60)[::-1] for i in A]

ans=0
for i in range(60):
    l = [s[i] for s in binary]
    #print(i,l.count("0") * l.count("1"))
    ans = (ans+ ((l.count("0") * l.count("1"))% lim * 2**i )% lim)% lim
print(ans % lim)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate 
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
S=list(accumulate(A))
S.insert(0,0)

L=[ (s-i)%k  for i,s in enumerate(S)]
def f(l):
    return sum([x*(x-1)//2 for x in l])

from collections import Counter

ans=0
for i in range(n):
    #print(L[i+1:i+k],L[i])
    ans += (L[i+1:i+k].count(L[i]))
print(ans)

Fixed submission:
from itertools import accumulate 
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
S=list(accumulate(A))
S.insert(0,0)

L=[ (s-i)%k  for i,s in enumerate(S)]
def f(l):
    return sum([x*(x-1)//2 for x in l])

from collections import Counter

ans=0
d = Counter(L[1:k])
for i in range(n):
    ans += d[L[i]]
    #print(L[i+1:i+k],d)
    d[L[i+1]] -= 1
    if i+k <= n:
        d[L[i+k]] += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
n,m=map(int,input().split())
S=list(map(int,list(input())))

idx = n
ans=[]
while idx > 0:
    for i in range(1,m+1)[::-1]:
        #print(i,idx,idx-i,S[idx-i])
        if S[idx-i] == 0 and idx-i>=0:
            idx -= i
            ans.append(i)
            break
    else:
        print(-1)
        sys.exit()
print(*ans[::-1])

Fixed submission:
import sys
n,m=map(int,input().split())
S=list(map(int,list(input())))
if m > n:
    m = n
idx = n
ans=[]
while idx > 0:
    for i in range(1,m+1)[::-1]:
        #print(i,idx,idx-i,S[idx-i])
        if S[idx-i] == 0 and idx-i>=0:
            idx -= i
            ans.append(i)
            break
    else:
        print(-1)
        sys.exit()
print(*ans[::-1])
Buggy python submission (verdict: Runtime Error):
import math
def length(X,Y,c):
    sum_=0
    for i in range(len(c)-1):
        sum_+=math.sqrt((X[c[i]]-X[c[i+1]])**2 + (Y[c[i]]-Y[c[i+1]])**2)
    #print(sum_)
    return sum_
N=int(input())
X=[0]*N
Y=[0]*N
for i in range(N):
    X[i], Y[i] = map(int,input().split())
C = list(itertools.permutations(range(0,N)))
sum_=0
for c in C:
    sum_+=length(X,Y,c)
print(sum_/len(C))

Fixed submission:
import math
import itertools
def length(X,Y,c):
    sum_=0
    for i in range(len(c)-1):
        sum_+=math.sqrt((X[c[i]]-X[c[i+1]])**2 + (Y[c[i]]-Y[c[i+1]])**2)
    #print(sum_)
    return sum_
N=int(input())
X=[0]*N
Y=[0]*N
for i in range(N):
    X[i], Y[i] = map(int,input().split())
C = list(itertools.permutations(range(0,N)))
sum_=0
for c in C:
    sum_+=length(X,Y,c)
print(sum_/len(C))