Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def solve(a,b,c,x):
    count = 0
    for i in range(a+1):
        for j in range(b+1):
            for k in range(c+1):
                if 500*i+100*j+50*k == x:
                    count += 1
    return count

A,B,C,X = map(int, input().split(" "))
print(solve(A,B,C,X))

Fixed submission:
def solve(a,b,c,x):
    count = 0
    for i in range(a+1):
        for j in range(b+1):
            for k in range(c+1):
                if 500*i+100*j+50*k == x:
                    count += 1
    return count

A = int(input())
B = int(input())
C = int(input())
X = int(input())

print(solve(A,B,C,X))

Buggy python submission (verdict: Runtime Error):
def solve(a,b,c,x):
    count = 0
    for i in range(a+1):
        for j in range(b+1):
            for k in range(c+1):
                if 500*i+100*j+50*k == x:
                    count += 1
    return count

A,B,C,X = map(int, input().split())
print(solve(A,B,C,X))

Fixed submission:
def solve(a,b,c,x):
    count = 0
    for i in range(a+1):
        for j in range(b+1):
            for k in range(c+1):
                if 500*i+100*j+50*k == x:
                    count += 1
    return count

A = int(input())
B = int(input())
C = int(input())
X = int(input())

print(solve(A,B,C,X))

Buggy python submission (verdict: Runtime Error):
def solve(a,b,c,x):
    count = 0
    for i in range(a+1):
        for j in range(b+1):
            for k in range(c+1):
                if 500*i+100*j+50*k == x:
                    count += 1
    return count

A,B,C,X = map(int, input().split())
print(solve(A,B,C,X))   

Fixed submission:
def solve(a,b,c,x):
    count = 0
    for i in range(a+1):
        for j in range(b+1):
            for k in range(c+1):
                if 500*i+100*j+50*k == x:
                    count += 1
    return count

A = int(input())
B = int(input())
C = int(input())
X = int(input())

print(solve(A,B,C,X))
Buggy python submission (verdict: Time Limit Exceeded):
N,Y = map(int, input().split())

ans = [-1,-1,-1]
for x in range(N+1):
    for y in range(N+1):
        for z in range(N+1):
            if x+y+z==N and 10000*x+5000*y+1000*z==Y:
                ans[0] = x
                ans[1] = y
                ans[2] = z

print(ans[0],ans[1],ans[2])

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

ans = [-1,-1,-1]
for x in range(N+1):
    for y in range(N+1):
        k = N-x-y
        if k>=0 and 10000*x+5000*y+1000*k==Y:
                ans[0] = x
                ans[1] = y
                ans[2] = k

print(ans[0],ans[1],ans[2])

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

ans = [-1,-1,-1]
for x in range(N):
    for y in range(N):
        for z in range(N):
            if x+y+z==N and 10000*x+5000*y+1000*z==Y:
                ans[0] = x
                ans[1] = y
                ans[2] = z

print("{0} {1} {2}".format(ans[0],ans[1],ans[2]))

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

ans = [-1,-1,-1]
for x in range(N+1):
    for y in range(N+1):
        k = N-x-y
        if k>=0 and 10000*x+5000*y+1000*k==Y:
                ans[0] = x
                ans[1] = y
                ans[2] = k

print(ans[0],ans[1],ans[2])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
V = list(map(int , input().split()))
C = list(map(int , input().split()))

Benefit = 0

for b in range(2**N):
	Binary = []
	binary = b
	for n in range(N):
		Binary.append(binary % 2)
		binary = binary //(2)
#	print("Binary = " + str(Binary))
	B = 0
	for n in range(N):
		if Binary[n] == 1:
			B += V[n] - C[n]
	Benefit = max(Benefit, B)
#print("Benefit = " + str(Benefit) )

print(Benefit)


Fixed submission:
N = int(input())
V = list(map(int , input().split()))
C = list(map(int , input().split()))
B = 0

for n in range(N):
	if V[n] - C[n] > 0:
		B += V[n] - C[n]

print(B)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
V = list(map(int , input().split()))
C = list(map(int , input().split()))

Benefit = []

for b in range(2**N):
	Binary = []
	binary = b
	for n in range(N):
		Binary.append(binary % 2)
		binary = binary //(2)
#	print("Binary = " + str(Binary))
	B = 0
	for n in range(N):
		if Binary[n] == 1:
			B += V[n] - C[n]
	Benefit.append(B)
#print("Benefit = " + str(Benefit) )
print(max(Benefit))


Fixed submission:
N = int(input())
V = list(map(int , input().split()))
C = list(map(int , input().split()))
B = 0

for n in range(N):
	if V[n] - C[n] > 0:
		B += V[n] - C[n]

print(B)
Buggy python submission (verdict: Runtime Error):
A , B = map(int , input().split())

if A > B + 1:
	print(2*A - 1)
elif B > A + 1:
	print(2*b - 1)
else:
	print(A + B)




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

if A > B + 1:
	print(2*A - 1)
elif B > A + 1:
	print(2*B - 1)
else:
	print(A + B)
Buggy python submission (verdict: Time Limit Exceeded):
### C

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

X = list(map(int , sorted(list(map(int , input().split())))))

#print("X = " + str(X))

D = []

R = 0

if M-1 > 0 :
	for i in range(M-1):
		D.append(int(X[i+1]) - int(X[i]))


#print("D = " + str(D))

for i in range(N-1):
	if D !=[]:
		MAXD = max(D)
		D.remove(MAXD)
#		print(str(D) + "minus " + str(i+1) + "roots.")

if D != []:
	for d in D:
		R += d


print(R)



Fixed submission:
### C

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

X = list(map(int , sorted(list(map(int , input().split())))))

#print("X = " + str(X))

D = []

R = 0

if M-1 > 0 :
	for i in range(M-1):
		D.append(int(X[i+1]) - int(X[i]))


#print("D = " + str(D))

if D !=[]:
	D = sorted(D)
	D = D[::-1]
	D = D[N-1:]
#print("D = " + str(D))

if D != []:
	for d in D:
		R += d


print(R)

Buggy python submission (verdict: Time Limit Exceeded):
### C

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

X = list(map(int , input().split()))

X = list(map(int , sorted(X)))

#print("X = " + str(X))

D = []

R = 0

if M-1 > 0 :
	for i in range(M-1):
		D.append(int(X[i+1]) - int(X[i]))


#print("D = " + str(D))

for i in range(N-1):
	if D !=[]:
		MAXD = max(D)
		D.remove(MAXD)
#		print(str(D) + "minus " + str(i+1) + "roots.")

if D != []:
	for d in D:
		R += d


print(R)



Fixed submission:
### C

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

X = list(map(int , sorted(list(map(int , input().split())))))

#print("X = " + str(X))

D = []

R = 0

if M-1 > 0 :
	for i in range(M-1):
		D.append(int(X[i+1]) - int(X[i]))


#print("D = " + str(D))

if D !=[]:
	D = sorted(D)
	D = D[::-1]
	D = D[N-1:]
#print("D = " + str(D))

if D != []:
	for d in D:
		R += d


print(R)
Buggy python submission (verdict: Runtime Error):
N = int(input())

l_0 = list(map(int , input().split()))

L = [l_0]

m = None

count = 0

while L != []:
	for l in L:
		m = min(l)
		L.remove(l)
		for i in range(len(l)):
			l[i] = l[i] - m
		count += m
		l = " ".join( list(map(str , l)) )
		l = l.split("0")
		for a in l:
			L.append(list(map(int, (a.split()))))
		while [] in L:
			L.remove([])


print(count)

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

print(int(a*c/2))

Buggy python submission (verdict: Runtime Error):
c = int(input())

a = int(input())

print(int(a*c/2))

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

print(int(a*c/2))
Buggy python submission (verdict: Runtime Error):
L = [l_0]

m = None

count = 0

while L != []:
	for l in L:
		m = min(l)
		L.remove(l)
		for i in range(len(l)):
			l[i] = l[i] - m
		count += m
		l = list(map(str , l))
		l = " ".join(l)
		l = (l.split("0 "))
		for a in l:
			L.append(list(map( int, (a.split()))))
		while [] in L:
			L.remove([])

print(count)

Fixed submission:
N = int(input())

l_0 = list(map(int , input().split()))

L = [l_0]

m = None

count = 0

while L != []:
	for l in L:
		lis = l
		m   = min(l)
		for i in range(len(l)):
			lis[i] = lis[i] - m
		count += m
		lis = "_".join( list(map(str , lis)) )
		if lis[0:1] == "0":
			lis = lis[2:]
		lis = lis.split("_0")
		while "" in lis:
			lis.remove("")
		for a in lis:
			if a[0:1] == "_":
				a = a[1:]
			a = list(map(int, a.split("_")))
			L.append(a)
		L.remove(l)
		while [] in L:
			L.remove([])
print(count)
Buggy python submission (verdict: Runtime Error):
S = input()
L = len(S)
Truth = 0

for j in range(0, 8):
	if S[0:j] + S[L- 7 +j:] = "keyence":
		Truth = 1

if Truth =1:
	print(YES)
else:
	print(NO)

Fixed submission:
S = input()
L = len(S)
Truth = 0

for j in range(0, 8):
	if S[0:j] + S[L- 7 +j:] == "keyence":
		Truth = 1

if Truth ==1:
	print("YES")
else:
	print("NO")
Buggy python submission (verdict: Runtime Error):
X = int(input())

if X = 7 or X = 5 or X = 3:
	print("YES")
else:
	print("NO")




Fixed submission:
X = int(input())

if X == 7 or X == 5 or X == 3:
	print("YES")
else:
	print("NO")
Buggy python submission (verdict: Runtime Error):
N = int(input())

T, A = list(map(int , input().split()))

H = list(map(int , input().split()))

Tlist =[]

for n in range(N):
	Tlist.append(T - H[n]*0.006)


t = Tlist[0]
m = None

for n in range(N):
	if abs(t-A) > abs(Tlist[n]-A):
		t = Tlist[n]
		m = n

M = m + 1
print(M)



Fixed submission:
N = int(input())

T, A = list(map(int , input().split()))

H = list(map(int , input().split()))

Tlist =[]

for n in range(N):
	Tlist.append(T - H[n]*0.006)

t = Tlist[0]
m = 0

for n in range(N):
	if abs(t-A) > abs(Tlist[n]-A):
		t = Tlist[n]
		m = n

M = m + 1
print(M)
Buggy python submission (verdict: Runtime Error):
a,b=input().split()
c=a*b
if c%2==0:
  print("Even")
else:
  print("Odd")

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

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

Fixed submission:
a,b=(int(x) for x in input().split())
c=a*b
if c%2==0:
  print("Even")
else:
  print("Odd")
Buggy python submission (verdict: Runtime Error):
D = int(input())

if D==22:
    (print) "Christmas Eve Eve Eve Eve"

if D==23:
    (print) "Christmas Eve Eve"

if D==24:
    (print) "Christmas Eve"

if D==25:
    (print) "Christmas "


Fixed submission:
D = int(input())

if D==22:
    print ("Christmas Eve Eve Eve")

if D==23:
    print ("Christmas Eve Eve")

if D==24:
    print ("Christmas Eve")

if D==25:
    print ("Christmas ")

Buggy python submission (verdict: Runtime Error):
D = int(input())

if D==22:
    print "Christmas Eve Eve Eve Eve"

if D==23:
    print "Christmas Eve Eve"

if D==24:
    print "Christmas Eve"

if D==25:
    print "Christmas "


Fixed submission:
D = int(input())

if D==22:
    print ("Christmas Eve Eve Eve")

if D==23:
    print ("Christmas Eve Eve")

if D==24:
    print ("Christmas Eve")

if D==25:
    print ("Christmas ")

Buggy python submission (verdict: Runtime Error):
D = int(input())

if D==23:
    print "Christmas Eve Eve"

if D==24:
    print "Christmas Eve"

if D==23:
    print "Christmas "


Fixed submission:
D = int(input())

if D==22:
    print ("Christmas Eve Eve Eve")

if D==23:
    print ("Christmas Eve Eve")

if D==24:
    print ("Christmas Eve")

if D==25:
    print ("Christmas ")

Buggy python submission (verdict: Runtime Error):

if D==23:
    print "Christmas Eve Eve"

if D==24:
    print "Christmas Eve"

if D==23:
    print "Christmas "


Fixed submission:
D = int(input())

if D==22:
    print ("Christmas Eve Eve Eve")

if D==23:
    print ("Christmas Eve Eve")

if D==24:
    print ("Christmas Eve")

if D==25:
    print ("Christmas ")

Buggy python submission (verdict: Runtime Error):

if D==23:
    print('Christmas Eve Eve')

if D==24:
    print('Christmas Eve')

if D==23:
    print('Christmas ')


Fixed submission:
D = int(input())

if D==22:
    print ("Christmas Eve Eve Eve")

if D==23:
    print ("Christmas Eve Eve")

if D==24:
    print ("Christmas Eve")

if D==25:
    print ("Christmas ")

Buggy python submission (verdict: Runtime Error):
if D=23:
    print('Christmas Eve Eve')

if D=24:
    print('Christmas Eve')

if D=23:
    print('Christmas ')


Fixed submission:
D = int(input())

if D==22:
    print ("Christmas Eve Eve Eve")

if D==23:
    print ("Christmas Eve Eve")

if D==24:
    print ("Christmas Eve")

if D==25:
    print ("Christmas ")
Buggy python submission (verdict: Runtime Error):

def grand_garden(count, hlist):
    nonzero = False
    for i, h_i in enumerate(hlist):
        if h_i != 0:
            nonzero = True
            hlist[i] = hlist[i] -1
        elif nonzero:
            break


    if nonzero:
        return grand_garden(count + 1, hlist)
    else:
        return count






n = int( input())
hlist = input().split()
for i, h_i in enumerate(hlist):
    hlist[i] = int(hlist[i])

count = grand_garden(0, hlist)

print(count)



Fixed submission:

def grand_garden(hlist):
    all_zero = False
    count = 0
    while(not all_zero):
        nonzero = False
        for i, h_i in enumerate(hlist):
            if h_i != 0:
                nonzero = True
                hlist[i] = hlist[i] -1
            elif nonzero:
                break


        if nonzero:
            count = count + 1
        else:
            all_zero = True


    return count




n = int( input())
hlist = input().split()
for i, h_i in enumerate(hlist):
    hlist[i] = int(hlist[i])

count = grand_garden(hlist)

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N, M = map(int, input().split())
X = [ list(map(int, input().split())) for _ in range(M)]

Y = [ [] for _ in range(N)]
for x in X:
    Y[x[0]-1].append((x[0], x[1], x[2]))
    Y[x[1]-1].append((x[1], x[0], x[2]))
# print(Y)

visited = [False] * N
count = 0
que = deque()

for i in range(len(Y)):
    if len(Y[i]) == 0:
        visited[i] = True
        count +=1

while True:
    if not False in visited:
        break
    count += 1
    que.append(visited.index(False))
    
    while len(que)>0:
        v = que.popleft()
        visited[v] = True
        for y in Y[v]:
            if not visited[y[1]-1]:
                que.append(y[1]-1)
    

print(count)

Fixed submission:
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        
    def find_root(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.find_root(self.par[x])
        return self.par[x]
    
    def union(self, x, y):
        x_root = self.find_root(x)
        y_root = self.find_root(y)
        if x_root != y_root:
            if self.rank[x_root] < self.rank[y_root]:
                x_root, y_root = y_root, x_root
            if self.rank[x_root] == self.rank[y_root]:
                self.rank[x_root] += 1
            self.par[y_root] = x_root
            
    def is_same(self, x, y):
        x_root = self.find_root(x)
        y_root = self.find_root(y)
        return x_root == y_root
        
N, M = map(int, input().split())
X = [ list(map(int, input().split())) for _ in range(M)]

uf = UnionFind(N)
for x in X:
    uf.union(x[0]-1, x[1]-1)
    
roots = [ uf.find_root(i) for i in range(N)]
print(len(set(roots)))
Buggy python submission (verdict: Time Limit Exceeded):

H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]
# print(maze)

blacks = []
for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            blacks.append((i, j))
# print(blacks)

count = 0
while len(blacks) != 0:
    count += 1
#     print(blacks)
    nexts = []
    for x, y in blacks:
        for nx, ny in [(x-1, y), (x+1,y), (x,y-1),(x,y+1)]:
            if 0<=nx<H and 0<=ny<W and maze[nx][ny] == '.':
                maze[nx][ny] = '#'
                nexts.append((nx, ny))
#     print(maze)
    blacks = nexts
    
print(count-1)

Fixed submission:

H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]
# print(maze)

blacks = []
for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            blacks.append((i, j))
# print(blacks)

count = 0
while len(blacks) != 0:
    count += 1
#     print(blacks)
    nexts = []
    for x, y in blacks:
        for nx, ny in [(x-1, y), (x+1,y), (x,y-1),(x,y+1)]:
            if 0<=nx<H and 0<=ny<W and maze[nx][ny] == '.':
                maze[nx][ny] = '#'
                nexts.append((nx, ny))
#     print(maze)
    blacks = nexts
    
print(count-1)
Buggy python submission (verdict: Runtime Error):


N = int(input())
S = input()
K =  int(input())

moji = S[K]

result = ''
for s in S:
    if s == moji:
        result+=s
    else:
        result+='*'
print(result)

Fixed submission:


N = int(input())
S = input()
K =  int(input())

moji = S[K-1]

result = ''
for s in S:
    if s == moji:
        result+=s
    else:
        result+='*'
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

kouho = []
kouho.append(['.' for i in range(N)])
for i in range(1, N+1):
    a = kouho[-1][:]
    a[-i] = '#'
    kouho.append(a)

counts = []
for k in kouho:
    count = 0
    for i in range(N):
        if k[i] != S[i]:
            count += 1
    counts.append(count)

print(min(counts))


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

answer = ['.' for i in range(N)]
diff = 0
for i in range(N):
    if S[i] != answer[i]:
        diff += 1

counts = [diff]

for i in range(1, N+1):
    v = answer[-i] 
    if v == S[-i]:
        diff += 1
    else:
        diff -= 1
    answer[-i] = '.' if v == '#' else '#'
    counts.append(diff)

print(min(counts))
Buggy python submission (verdict: Runtime Error):

N = int(input())
nums = list(map(int, gen.__next__().split()))

maxx = 0
count = 0
for n in nums:
    if n>=maxx:
        maxx = n
        count += 1

print(count)

Fixed submission:
N = int(input())
nums = list(map(int, input().split()))
 
maxx = 0
count = 0
for n in nums:
    if n>=maxx:
        maxx = n
        count += 1
 
print(count)
Buggy python submission (verdict: Runtime Error):
gen = get_input()

S = list(input())

count = 0
s1 = S[:]
for i in range(1, len(S)):
    if s1[i - 1] == s1[i]:
        s1[i] = '0' if s1[i-1] == '1' else '1'
        count += 1

count2 = 0
s2 = S[:]
for i in reversed(range(len(S)-1)):
    if s2[i] == s2[i +1]:
        s2[i] = '0' if s2[i+1] == '1' else '1'
        count2 += 1

print(min(count, count2))

Fixed submission:
S = list(input())
 
count = 0
s1 = S[:]
for i in range(1, len(S)):
    if s1[i - 1] == s1[i]:
        s1[i] = '0' if s1[i-1] == '1' else '1'
        count += 1
 
count2 = 0
s2 = S[:]
for i in reversed(range(len(S)-1)):
    if s2[i] == s2[i +1]:
        s2[i] = '0' if s2[i+1] == '1' else '1'
        count2 += 1
 
print(min(count, count2))
Buggy python submission (verdict: Runtime Error):

S = input()
ARR = ['A', 'C', 'G', 'T']

results = []
count = 0
for i in range(len(S)):
    if S[i] in ARR:
        count+=1
    else:
        results.append(count)
        count = 0
print(max(results))

Fixed submission:

S = input()
ARR = ['A', 'C', 'G', 'T']

results = []
count = 0
for i in range(len(S)):
    if S[i] in ARR:
        count+=1
        results.append(count)
    else:
        results.append(count)
        count = 0

print(max(results))
Buggy python submission (verdict: Time Limit Exceeded):

N, Q = map(int, input().split())
S = input()
LRs = [list(map(int, input().split())) for i in range(Q)]

counts = []
for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        counts.append(1)
    else:
        counts.append(0)
counts.append(0)

for LR in LRs:
    start = LR[0] - 1
    end = LR[1] 
    out = 0
    for i in range(start, end-1):
        out += counts[i]
    print(out)


Fixed submission:

N, Q = map(int, input().split())
S = input()
LRs = [list(map(int, input().split())) for i in range(Q)]

counts = []
for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        counts.append(1)
    else:
        counts.append(0)
counts.append(0)

rev_counts = [0]
for i in reversed(range(len(S)-1)):
    rev_counts.append(rev_counts[-1] + counts[i])
rev_counts = list(reversed(rev_counts))
# print(counts)
# print(rev_counts)


for LR in LRs:
    start = LR[0] - 1
    end = LR[1]  -1
    print(rev_counts[start] - rev_counts[end])

Buggy python submission (verdict: Time Limit Exceeded):

N, Q = map(int, input().split())
S = input()
LRs = [list(map(int, input().split())) for i in range(Q)]

counts = []
for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        counts.append(1)
    else:
        counts.append(0)
counts.append(0)

for LR in LRs:
    start = LR[0] - 1
    end = LR[1] 
#     print(S[start:end])
#     print(counts[start:(end-1)])
    print(sum(counts[start:(end-1)]))
    

Fixed submission:

N, Q = map(int, input().split())
S = input()
LRs = [list(map(int, input().split())) for i in range(Q)]

counts = []
for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        counts.append(1)
    else:
        counts.append(0)
counts.append(0)

rev_counts = [0]
for i in reversed(range(len(S)-1)):
    rev_counts.append(rev_counts[-1] + counts[i])
rev_counts = list(reversed(rev_counts))
# print(counts)
# print(rev_counts)


for LR in LRs:
    start = LR[0] - 1
    end = LR[1]  -1
    print(rev_counts[start] - rev_counts[end])

Buggy python submission (verdict: Time Limit Exceeded):

N, Q = map(int, input().split())
S = input()
LRs = [list(map(int, input().split())) for i in range(Q)]

for LR in LRs:
    s = S[LR[0]-1 : LR[1]]
    count = 0
    for i in range(len(s)-1):
        if s[i] == 'A' and s[i+1] == 'C':
            count += 1
    print(count)

Fixed submission:

N, Q = map(int, input().split())
S = input()
LRs = [list(map(int, input().split())) for i in range(Q)]

counts = []
for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        counts.append(1)
    else:
        counts.append(0)
counts.append(0)

rev_counts = [0]
for i in reversed(range(len(S)-1)):
    rev_counts.append(rev_counts[-1] + counts[i])
rev_counts = list(reversed(rev_counts))
# print(counts)
# print(rev_counts)


for LR in LRs:
    start = LR[0] - 1
    end = LR[1]  -1
    print(rev_counts[start] - rev_counts[end])
Buggy python submission (verdict: Time Limit Exceeded):

N, M = map(int, input().split())
Vs = [ list(map(int, input().split())) for _ in range(M)]

d = dict()

for v in Vs:
    if v[0] in d:
        d[v[0]].append(v[1])
    else:
        d[v[0]] = [v[1]]

for k, v in d.items():
    s = sorted(v)
    d[k] = s

for v in Vs:
    ind = d[v[0]].index(v[1])
    print(str(v[0]).zfill(6) + str(ind+1).zfill(6))

Fixed submission:

N, M = map(int, input().split())
Vs = [ list(map(int, input().split())) for _ in range(M)]

d = dict()

for v in Vs:
    if v[0] in d:
        d[v[0]].append(v[1])
    else:
        d[v[0]] = [v[1]]

for k, v in d.items():
    s = sorted(v)
    d[k] = s


ans = dict()
for k, v in d.items():
    for i in range(len(v)):
        a = v[i]
        ans[(str(k)+'-'+str(a))]  = i+1

for v in Vs:
    a = ans[(str(v[0])+'-'+str(v[1]))]
    print(str(v[0]).zfill(6) + str(a).zfill(6))
Buggy python submission (verdict: Time Limit Exceeded):

N, M = map(int, input().split())
bridge = [ list(map(int, input().split())) for _ in range(M)]

cut_count = 0
while True:
    summ = [ 0 for _ in range(N)]
    for b in bridge:
        for i in range(N):
            if (b[0] - 1) <= i < (b[1] - 1):
                summ[i] += 1
#     print(summ, bridge)
    maxx = max(summ)
    if maxx < 2:
        print(str(len(bridge) + cut_count))
        break
    else:
        cut_count += 1
        ind = summ.index(maxx)
        new_bridge = []
        for b in bridge:
            for i in range(N):
                if (b[0] - 1) <= ind < (b[1] - 1):
                    pass
                else:
                    new_bridge.append(b)
                    break
        bridge = new_bridge
        

Fixed submission:

N, M = map(int, input().split())
bridge = [ list(map(int, input().split())) for _ in range(M)]

bridge.sort(key=lambda x:x[1])

cuts = [bridge[0][1]]
for b in bridge[1:]:
    cut = cuts[-1]
    if b[0]< cut <= b[1]:
        continue
    cuts.append(b[1])

# print(cuts)
print(len(cuts))