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

Fixed submission:
from collections import Counter
import sys
sys.setrecursionlimit(10000000)

class UnionFind:
    def __init__(self, N: int) -> None:
        #自身が親なら、その集合に属する頂点数に-1をかけたもの
        #自身が親でないなら、自身の親
        self.par = [-1 for i in range(N)]
    
    def root(self, x: int) -> bool:
        if self.par[x] < 0: #親が自分自身なら頂点
            return x
        else:
            #経路圧縮してから返す
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, x: int, y: int) -> None:
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return
        else:
            if rx > ry:
                rx, ry = ry, rx
            self.par[rx] += self.par[ry]
            self.par[ry] = rx
    
    def same(self, x: int, y: int) -> bool:
        return self.root(x) == self.root(y)
    
    def size(self, x: int) -> int:
        root = self.root(x)
        return -self.par[root]


def main():
    N, M = map(int, input().split())
    uf = UnionFind(N)
    for _ in range(M):
        a, b = map(int, input().split())
        uf.unite(a-1, b-1)
    
    ans = 0
    for i in range(N):
        ans = max(ans, uf.size(i))
    print(ans)

if __name__ == '__main__':
    main()

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

class UnionFind:
    def __init__(self, N: int) -> None:
        self.par = [i for i in range(N)]
    
    def root(self, x: int) -> bool:
        if self.par[x] == x: #親が自分自身なら頂点
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, x: int, y: int) -> None:
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return
        else:
            self.par[rx] = ry
    
    def same(self, x: int, y: int) -> bool:
        return self.root(x) == self.root(y)


def main():
    N, M = map(int, input().split())
    uf = UnionFind(N)
    for _ in range(M):
        a, b = map(int, input().split())
        uf.unite(a-1, b-1)
    
    g = Counter(uf.root(x) for x in range(N))
    ans = g.most_common(1)[0][1]
    print(ans)

if __name__ == '__main__':
    main()
Problem p02658 (python)

Fixed submission:
#import functools

def main():
    N = int(input())
    A = [int(c) for c in input().split(' ')]
    A.sort(reverse=True)

    if A[-1] == 0:
        print('0')
        exit()
    elif A[0] > 1e18:
        print('-1')
        exit()

    ret = 1
    for x in A:
        ret = ret * x
        if ret > 1e18:
            print('-1')
            exit()
        elif ret == 0:
            print('0')
            exit()

    if ret == 0:
        print('0')
        exit()
    elif ret > 1e18:
        print('-1')
        exit()
    print(f'{ret}')


if __name__ == "__main__":
    main()

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

N = int(input())
A = [int(c) for c in input().split(' ')]

ret = np.prod(A, dtype='float128')
if int(ret) > 1e18:
  print(-1)
else:
  print(ret)
Problem p02686 (python)

Fixed submission:
#from collections import defaultdict, deque
#import itertools
#import numpy as np
#import re
import bisect

def main():
    N = int(input())
    SS = []
    for _ in range(N):
        SS.append(input())
    S = []
    for s in SS:
        while '()' in s:
            s = s.replace('()', '')
        S.append(s)
    #print(S)
    S = [s for s in S if s != '']
    sum_op = 0
    sum_cl = 0
    S_both_op = []
    S_both_cl = []
    for s in S:
        if not ')' in s:
            sum_op += len(s)
        elif not '(' in s:
            sum_cl += len(s)
        else:
            pos = s.find('(')
            if pos <= len(s) - pos:
                S_both_op.append((pos, len(s)-pos))  #closeのほうが少ない、'))((('など -> (2,3)
            else:
                S_both_cl.append((pos, len(s)-pos))  #closeのほうが多い、')))(('など -> (3,2)

    # S_both_opは、耐えられる中でより伸ばす順にしたほうがいい？
    #S_both_op.sort(key=lambda x: (x[0], x[0]-x[1]))  #closeの数が小さい順にsortかつclose-openが小さい=伸ばす側にsort
    #S_both_cl.sort(key=lambda x: (x[0], x[0]-x[1]))  #これもcloseの数が小さい順にsortかつclose-openが小さい=あまり縮まない順にsort
    S_both_op.sort(key=lambda x: x[0])
    S_both_cl.sort(key=lambda x: -x[1])

    for p in S_both_op:
        sum_op -= p[0]
        if(sum_op < 0 ):
            print('No')
            exit()
        sum_op += p[1]

    for p in S_both_cl:
        sum_op -= p[0]
        if(sum_op < 0 ):
            print('No')
            exit()
        sum_op += p[1]
    
    if sum_op == sum_cl:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#from collections import defaultdict, deque
#import itertools
#import numpy as np
#import re

def main():
    N = int(input())
    SS = []
    for _ in range(N):
        SS.append(input())
    S = []
    for s in SS:
        while '()' in s:
            s = s.replace('()', '')
        S.append(s)
    #print(S)
    S = [s for s in S if s != '']
    sum_op = 0
    sum_cl = 0
    S_both_op = []
    S_both_cl = []
    for s in S:
        if not ')' in s:
            sum_op += len(s)
        elif not '(' in s:
            sum_cl += len(s)
        else:
            pos = s.find('(')
            if pos <= len(s) - pos:
                S_both_op.append((pos, len(s)-pos))  #closeのほうが少ない、'))((('など -> (2,3)
            else:
                S_both_cl.append((pos, len(s)-pos))  #closeのほうが多い、')))(('など -> (3,2)

    # S_both_opは、耐えられる中でより伸ばす順にしたほうがいい？
    sort(S_both_op, key=lambda x: x[0])  #closeの数が小さい順にsort
    sort(S_both_cl, key=lambda x: x[0])  #これもcloseの数が小さい順にsort

    for p in S_both_op:
        sum_op -= p[0]
        if(sum_op < 0 ):
            print('No')
            exit()
        sum_op += p[1]
    for p in S_both_cl:
        sum_op -= p[0]
        if(sum_op < 0 ):
            print('No')
            exit()
        sum_op += p[1]
    
    if sum_op == sum_cl:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()
Problem p02705 (python)

Fixed submission:
R = int(input())
print(R * 2 * 3.1416)

Buggy submission (verdict: Runtime Error):
R = float(input)
print(R * 2 * 3.1416)
Problem p02706 (python)

Fixed submission:
N, M = tuple(int(c) for c in input().split(' '))
A = tuple(int(c) for c in input().split(' '))
if sum(A) > N:
  print(-1)
else:
  print(N - sum(A))

Buggy submission (verdict: Runtime Error):
N, M = tuple(int(c) for c in input().split(' '))
A = tuple(int(c) for c in input().split(' '))
if len(sum(A)) > N:
  print(-1)
else:
  print(len(sum(A)) > N)
Problem p02554 (python)

Fixed submission:
n=input()
z=[[[0 for _1 in xrange(2)] for _2 in xrange(2)] for _3 in xrange(n+1)]
z[-1][1][1]=1
for i in xrange(n-1,-1,-1):
  for j in xrange(2):
    for k in xrange(2):
      for t in xrange(10):
        z[i][j][k]+=z[i+1][j or t==0][k or t==9]
      z[i][j][k]%=(pow(10,9)+7)
print z[0][0][0]

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(1<<30)
def f(i,b1,b2):
  if i==n:
    return b1 and b2
  if z[i][b1][b2]==-1:
    z[i][b1][b2]=sum(f(i+1,b1 or j==0,b2 or j==9) for j in xrange(10))%(pow(10,9)+7)
  return z[i][b1][b2]
n=input()
z=[[[-1 for _1 in xrange(2)] for _2 in xrange(2)] for _3 in xrange(n+1)]
print f(0,False,False)
Problem p03160 (python)

Fixed submission:
n=input()
a=map(int,raw_input().split())
z=[0]*n
z[1]=abs(a[1]-a[0])
for i in xrange(2,n):
  z[i]=min(z[i-1]+abs(a[i]-a[i-1]),z[i-2]+abs(a[i]-a[i-2]))
print z[-1]

Buggy submission (verdict: Runtime Error):
n=input()
a=map(int,raw_input().split())
z=[0]*n
z[1]=abs(a[1]-a[0])
for i in xrange(2,n):
  z[i]=min(z[i-1]+abs(a[i]-a[i-1],z[i-2]+abs(a[i]-a[i-2]))
print z[-1]
Problem p03166 (python)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(1<<30)
def f(x):
  if z[x]==-1:
  	z[x]=max([f(i) for i in v[x]]+[-1])+1
  return z[x]
n,m=map(int,raw_input().split())
v=[[] for _ in xrange(n)]
for x,y in [map(int,raw_input().split()) for _ in xrange(m)]:
  v[x-1].append(y-1)
z=[-1]*n
for i in xrange(n):
  if z[i]==-1:
    f(i)
print max(z)

Buggy submission (verdict: Runtime Error):
def f(x):
  if z[x]==-1:
  	z[x]=max([f(i) for i in v[x]]+[-1])+1
  return z[x]
n,m=map(int,raw_input().split())
v=[[] for _ in xrange(n)]
for x,y in [map(int,raw_input().split()) for _ in xrange(m)]:
  v[x-1].append(y-1)
z=[-1]*n
for i in xrange(n):
  if z[i]==-1:
    f(i)
print max(z)
Problem p03173 (python)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(1<<30)
def f(i,j,d):
  if i>=j:
    return 0
  if z[i][j]==-1:
    q=1<<64
    for k in xrange(i,j):
      q=min(q,s[j+1]-s[i]+f(i,k,d)+f(k+1,j,d))
    z[i][j]=q
  return z[i][j]
n=input()
a=map(int,raw_input().split())
s=[0]
for i in a:
  s.append(s[-1]+i)
z=[[-1]*n for i in xrange(n)]
print f(0,n-1,{})

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(1<<30)
def f(i,j,d):
  if i>=j:
    return 0
  if z[i][j]==-1:
    q=1<<64
    for k in xrange(i,j+1):
      q=min(q,s[j+1]-s[i]+f(i,k,d)+f(k+1,j,d))
    z[i][j]=q
  return z[i][j]
n=input()
a=map(int,raw_input().split())
s=[0]
for i in a:
  s.append(s[-1]+i)
z=[[-1]*n for i in xrange(n)]
print f(0,n-1,{})
Problem p02706 (python)

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

c = list(map(int,input().split()))
c_sum = sum(c)

day_count = n-c_sum

if day_count>=0:
  print(day_count)
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(map(int,iuput().split()))
a_sum = sum(a)
x = n - a_sum
if x >= 0:
    print(x)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(map(int,iuput().split()))
x = n - sum(a)
if x >= 0:
    print(x)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(map(int,iuput().split()))
x = n - sum(a)
if x >= 0:
    print(x)
else:
    print("-1")
Problem p02730 (python)

Fixed submission:
s = input()
l = len(s)
if list(s) != list(reversed(s)):
    print('No')
    exit()
if list(s[:(l - 1) // 2]) != list(reversed(s[:(l - 1) // 2])):
    print('No')
    exit()
if list(s[(l + 3) // 2 -1:l]) != list(reversed(s[(l + 3) // 2 -1:l])):
    print('No')
    exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
s = list(input())
n = len(s)
s_half = (n - 1)/2
s_3 = (n + 3)/ 2
if s == s[::-1]:
	if s[s_half - 1] == s[s_half - 1::-1]:
		if s[s_3 -1] == s[s_3 -1::-1]:
			print('Yes')
print('No')

Buggy submission (verdict: Runtime Error):
s = list(input())
n = len(s)
s_half = (n - 1)/2
s_3 = (n + 3)/ 2
if s == s[::-1]:
	if s_half == s_half[::-1]:
		if s_3 == s_3[::-1]:
			print('Yes')
print('No')
Problem p02886 (python)

Fixed submission:
n = int(input())
d = list(map(int, input().split()))
ans = 0
for i in range(n -1):
	for j in range(i + 1, n):
		ans += d[i] * d[j]
		
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
d = list(map(int, input().split()))
ans = 0
for i in n -1:
	for j in (i + 1: n):
		ans += d[i] * d[j]
		
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
d = list(map(int, input().split()))
ans = 0
for i in d:
	for j in (d -i):
		ans += i * j
		
print(ans // 2)
Problem p02921 (python)

Fixed submission:
s = input()
t = input()
ans = 0
for i in range(3):
	if s[i] == t[i]:
		ans += 1
		
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
for i in range(3):
	if s[i] == t[i]:
		ans += 1
		
print(ans)
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
c = a * b
if(c % 2):
    print("Odd")
else:
    print("Even")

Buggy submission (verdict: Runtime Error):
a, b = amp(int, input().split())
c = a * b
if(c % 2):
    print("Odd")
else:
    print("Even")
Problem p02664 (python)

Fixed submission:
s = input()
newS = ""
for i in range(len(s)):
    if s[i]=="?":
        newS+="D"
    else:
        newS+=s[i]
print(newS)

Buggy submission (verdict: Runtime Error):
s = input()
newS = ""

for i in range(len(s)):
    if s[i]=="?" and len(s)!= 1 and i==0 and s[i+1]=="D":
        newS+="P"
    elif len(s)&1 and i==len(s)-1 and s[i]=="?":
        newS+="D"
    elif s[i]=="?":
        if i!=0 and i!=len(s)-1:
            if newS[i-1]=="P":
                newS+="D"
            elif newS[i-1]=="D" and  (s[i+1]=="D" or s[i+1]=="?"):
                newS+="P"
        else:
            if i==0:
                if s[i+1]=="D":
                    newS+="P"
                elif s[i+1]=="P" or s[i+1]=="?":
                    newS+="D"
            else:
                newS+="D"
    else:
        newS+=s[i]
print(newS)

Buggy submission (verdict: Runtime Error):
s = input()
newS = ""

for i in range(len(s)):
    if s[i]=="?" and len(s)!= 1 and i==0 and s[i+1]=="D":
        newS+="P"
    elif len(s)&1 and i==len(s)-1 and s[i]=="?":
        newS+="D"
    elif s[i]=="?":
        if newS[i-1]=="P":
            newS+="D"
        elif newS[i-1]=="D" and (s[i+1]=="D" or s[i+1]=="?"):
            newS+="P"
    else:
        newS+=s[i]
print(newS)
Problem p02801 (python)

Fixed submission:
a = "abcdefghijklmnopqrstuvwyz"

s = input()
print(a[a.index(s)+1])

Buggy submission (verdict: Runtime Error):
a = "abcdefghijklmnopqrstuvwyz"

s = input()
print(a.index[a.index(s)+1])
Problem p02742 (python)

Fixed submission:
def main():
    h, w = map(int, input().split())

    if h == 1 or w == 1:
        print(1)
    else:
        print(int(w * (h/2)) if h % 2 == 0 else int(w*(h//2) + (w+1)//2))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    h, w = map(int, input().split())

    if h == 1 or w == 1:
        print(1)
    else:
        print((w * h + 1) // 2))


if __name__ == '__main__':
    main()
Problem p03067 (python)

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

print('Yes' if (min(a, b) < c) and (c < max(a, b)) else 'No')

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input() + 'a'

count = min(s.count('#'), s.count('.'))

for i in range(n):
  if s[i] != s[i+1]:
  	count = min(count, s[:i+1].count('#') + s[i+1:].count('.'))
    
print(count)
Problem p03085 (python)

Fixed submission:
base = input()

if base == 'A':
  print('T')
elif base == 'T':
  print('A')
elif base == 'C':
  print('G')
else:
  print('C')

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

if base == 'A':
  print('T')
elif base == 'T':
  print('A')
elif base =- 'C':
  print('G')
else:
  print('C')
Problem p03103 (python)

Fixed submission:
n, m = map(int, input().split())
shops = sorted([list(map(int, input().split())) for i in range(n)])

def main():
  cost = 0
  got = 0
  for shop in shops:
    if got + shop[1] <= m:
      got += shop[1]
      cost += shop[0] * shop[1]
    else:
      cost += (m - got) * shop[0]
      return cost
  return cost
  
print(main())

Buggy submission (verdict: Runtime Error):
def main():
  n, m = map(int, input().split())
  shops = sorted([list(map(int, input().split())) for i in range(n)])
  
  cost = 0
  got = 0
  for shop in shops:
    if got + shop[1] <= m:
      got += shop[1]
      cost += shop[0] * shop[1]
    else:
      cost += (m - got) * shop[0]
      break
  print(cost)
  

if __init__ == '__main__':
  main()
Problem p02697 (python)

Fixed submission:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,M = LI()

if N%2:
    count = 0
    for i in range(1,(N+1)//2):
        if count < M:
            print(i,N+1-i)
            count += 1
else:
    count = 0
    if M == 1:
        print(1,N)
        exit()
    for i in range(1,N//2+1):
        if count < M:
            print(i,N//2+1-i)
            count += 1
        if count < M:
            print(i+N//2,N-i)
            count += 1

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,M = LI()

if N%2:
    count = 0
    for i in range(1,(N+1)//2):
        if count < M:
            print(i,N+1-i)
            count += 1
else:
    count = 0
    for i in range(1,N//2+1):
        if count < M and N+1-2*i != N//2:
            print(i,N+1-i)
            count += 1
            raise(ValueError())
Problem p02817 (python)

Fixed submission:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

S,T = map(str, input().split())
print(T+S)

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

# FFT
# use python3
# a = np.array([a1,a2,a3]), b= np.array([b1,b2,b3])
# c = np.array([a1b1,a1b2+a2b1,a1a3+a2b2+a3b1,a2b3+a3b2,a3b3])
import numpy as np
def Convolution(a,b):
    bit = (len(a)+len(b)-2).bit_length()
    L = 2**bit
    fa,fb = np.fft.rfft(a,L), np.fft.rfft(b,L)
    c = np.rint(np.fft.irfft(fa*fb,L)).astype(np.int64)
    return c[:len(a)+len(b)-1]

N,M = II()
A = III()

print('time test')

h = [0]*(max(A))
for a in A:
    h[a-1] += 1

conv = np.append([0,0],Convolution(h,h))
ans = 0
count = 0
'''
for k in range(2,2*max(A)+1)[::-1]:
    if conv[k]:
        num = min(M-count,conv[k])
        count += num
        ans += k*num
    if count==M:
        break
'''
print(ans)
Problem p02840 (python)

Fixed submission:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

inf = 10**30
N,X,D = II()

if D==0:
    if X==0:
        print(1)
    else:
        print(N+1)
    exit()
if D<0:
    X,D = -X,-D

kukan = []
for i in range(N+1):
    kukan.append([i*X+(i*(i-1)//2)*D, i*X+(N*(N-1)//2-(N-i)*(N-i-1)//2)*D, (i*X)%D])
kukan.sort(key=lambda x:(x[2],x[0]))

div,d_min,d_max = inf,inf,inf
ans = 0
for k in kukan:
    if k[2]!=div:
        if d_min!=inf:
            ans += (d_max-d_min)//D + 1
        d_min,d_max,div = k[0],k[1],k[2]
    else:
        if k[0]>d_max:
            ans += (d_max-d_min)//D + 1
            d_min,d_max = k[0],k[1]
        else:
            d_max = max(d_max,k[1])
ans += (d_max-d_min)//D + 1

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

inf = 10**30
N,X,D = II()

if D<0:
    X,D = -X,-D

kukan = []
for i in range(N+1):
    kukan.append([i*X+(i*(i-1)//2)*D, i*X+(N*(N-1)//2-(N-i)*(N-i-1)//2)*D, (i*X)%D])
kukan.sort(key=lambda x:(x[2],x[0]))

div,d_min,d_max = inf,inf,inf
ans = 0
for k in kukan:
    if k[2]!=div:
        if d_min!=inf:
            ans += (d_max-d_min)//D + 1
        d_min,d_max,div = k[0],k[1],k[2]
    else:
        if k[0]>d_max:
            ans += (d_max-d_min)//D + 1
            d_min,d_max = k[0],k[1]
        else:
            d_max = k[1]
ans += (d_max-d_min)//D + 1

print(ans)
Problem p02852 (python)

Fixed submission:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

from bisect import bisect_right

N,M = II()
A = str(input())

B = A[::-1]

ans = []
place = 0
while place!=N:
    for i in range(1,M+1)[::-1]:
        if place+i<=N:
            if B[place+i]!='1':
                ans.append(i)
                place += i
                break
        if i==1 and B[place+i]=='1':
            print(-1)
            exit()

print(*list(reversed(ans)))

Buggy submission (verdict: Runtime Error):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

from bisect import bisect_right

N,M = II()
A = list(map(str, input().split()))

B = list(reversed(A))
ones = []
n = [0]*N
for i in range(N):
    if B[i]=='1':
        ones.append(i)

ans = []
place = 0
while place<N-1:
    for i in range(1,M+1)[::-1]:
        if B[place+i]!=1:
            ans.append(i)
            place += i
        if i==1 and B[place+i]=='1':
            print(-1)
            exit()

print(*list(reversed(ans)))