Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
'''input
3
1
2 1
1
1 1
1
2 0
'''
# A coding delight
from sys import stdin, stdout
import gc
from copy import deepcopy
# gc.disable()
input = stdin.readline



def consistent(choose):
	T = set()
	F = set()
	for i in choose:
		T.add(i + 1)

	for i in choose:
		aux = data[i]
		for j in range(len(aux)):
			p, v = aux[j]
			if v == 0:
				if p in T:
					return False 
				else:
					F.add(p)
			else:
				if p in F:
					return False
				else:
					T.add(p)
	pT = set()
	pF = set()
	while len(T) + len(F) != len(pT) + len(pF):
		# print(T, F)
		pT = deepcopy(T)
		pF = deepcopy(F)
		for i in range(n):
			aux = data[i]
			if i + 1 in T:
				for j in range(len(aux)):
					p, v = aux[j]
					if v == 0:
						if p in T:
							return False 
						else:
							F.add(p)
					else:
						if p in F:
							return False
						else:
							T.add(p)
	# print(T, F)		
	return True

	
# main starts
n = int(input().strip())
data = []
for _ in range(n):
	k = int(input().strip())
	temp =[]
	for i in range(k):
		x, y = list(map(int, input().split()))
		temp.append([x, y])
	data.append(temp)
ans = 0

# generating subset
for i in range(1, 2**n):
	choose = []
	for k in range(n):
		if (1 << k) & i:
			choose.append(k)

	if consistent(choose):
		ans = max(ans, len(choose))
		# print(choose)

print(ans)

Fixed submission:
'''input
3
1
2 1
1
1 1
1
2 0
'''
# A coding delight
from sys import stdin, stdout
import gc
from copy import deepcopy
# gc.disable()
input = stdin.readline



def consistent(choose):
	T = set()
	F = set()
	for i in choose:
		T.add(i + 1)

	for i in choose:
		aux = data[i]
		for j in range(len(aux)):
			p, v = aux[j]
			if v == 0:
				if p in T:
					return False 
				else:
					F.add(p)
			else:
				if p in F:
					return False
				else:
					T.add(p)
	pT = set()
	pF = set()
	while len(T) + len(F) != len(pT) + len(pF):
		# print(T, F)
		pT = deepcopy(T)
		pF = deepcopy(F)
		for i in range(n):
			aux = data[i]
			if i + 1 in T:
				for j in range(len(aux)):
					p, v = aux[j]
					if v == 0:
						if p in T:
							return False 
						else:
							F.add(p)
					else:
						if p in F:
							return False
						else:
							T.add(p)
	# print(T, F)		
	return True

	
# main starts
n = int(input().strip())
data = []
for _ in range(n):
	k = int(input().strip())
	temp =[]
	for i in range(k):
		x, y = list(map(int, input().split()))
		temp.append([x, y])
	data.append(temp)
ans = 0

# generating subset
for i in range(1, 2**n):
	choose = []
	for k in range(n):
		if (1 << k) & i:
			choose.append(k)

	if consistent(choose):
		ans = max(ans, len(choose))
		# print(choose)

print(ans)
Buggy python submission (verdict: Runtime Error):
import math 
def lcm(a, b):
    return (a*b)/math.gcd(a, b)
a = [int(i) for i in input().split()]
k = a[1]//a[2] - (a[0] - 1)//a[2]
r = a[1]//a[3] - (a[0] - 1)//a[3]
s = a[1]//(int(lcm(a[2],a[3]))) - (a[0] - 1)//int((lcm(a[2],a[3])))
print((a[1] - a[0] + 1 - (k + r - s)))

Fixed submission:
def gcd(a,b):
    while b > 0:
        a, b = b, a % b
    return a
    
def lcm(a, b):
    return a * b / gcd(a, b)
  
a = [int(i) for i in input().split()]
k = a[1]//a[2] - (a[0] - 1)//a[2]
r = a[1]//a[3] - (a[0] - 1)//a[3]
s = a[1]//(int(lcm(a[2],a[3]))) - (a[0] - 1)//int((lcm(a[2],a[3])))
print((a[1] - a[0] + 1 - (k + r - s)))
Buggy python submission (verdict: Runtime Error):
a = int(input())
s = '1' + '0' * (a-1)
print(int(s, 2) -1)


Fixed submission:
a = int(input())

def f(n):
    sum = 0
    if (n == 1):
        return 1
    else:
        sum += f(int(n/2)) * 2 + 1
        return sum

print(f(a))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
if(K==1):
  print(0)
  else:
    print(N-K)

Fixed submission:
N, K = map(int, input().split())
if(K==1):
  print("0")
else:
  print(N-K)
Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

dp = [0] + [-1] * h
INF = 10**18
for hp in range(1, h+1):
    ret = INF
    for i in range(n):
        if hp - a[i] >= 0:
            ret = min(ret, dp[hp-a[i]] + b[i])
        else:
            ret = min(ret, b[i])
    dp[hp] = ret
print(dp[h])


Fixed submission:
h, n = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

dp = [0] + [-1] * h
INF = 10**18
for hp in range(1, h+1):
    ret = INF
    for i in range(n):
        if hp - a[i] >= 0:
            ret = min(ret, dp[hp-a[i]] + b[i])
        else:
            ret = min(ret, b[i])
    dp[hp] = ret
print(dp[h])

Buggy python submission (verdict: Runtime Error):
def f(hp):
    if hp <= 0: return 0
    if dp[hp] >= 0: return dp[hp]
    ret = f(hp - a[0]) + b[0]
    for i in range(1, n):
        ret = min(ret, f(hp-a[i]) + b[i])
    dp[hp] = ret
    return ret

h, n = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

dp = [0] + [-1] * h
print(f(h))


Fixed submission:
h, n = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

dp = [0] + [-1] * h
INF = 10**18
for hp in range(1, h+1):
    ret = INF
    for i in range(n):
        if hp - a[i] >= 0:
            ret = min(ret, dp[hp-a[i]] + b[i])
        else:
            ret = min(ret, b[i])
    dp[hp] = ret
print(dp[h])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
G = [[] for i in range(M+1)]
for i in range(M):
    u, v = map(int, input().split())
    G[u].append(v)
s, t = map(int, input().split())

d = [-1] * (N + 1)

S = set()
S.add(s)
d[s] = 0
x = 1
while len(S) > 0:
    Q1 = set()
    for u in S:
        for v in G[u]:
            Q1.add(v)
    Q2 = set()
    for u in Q1:
        for v in G[u]:
            Q2.add(v)
    Q3 = set()
    for u in Q2:
        for v in G[u]:
            if d[v] < 0:
                d[v] = x
                Q3.add(v)
    x += 1
    S = Q3

print(d[t])


Fixed submission:
N, M = map(int, input().split())
G = [[] for i in range(N+1)]
for i in range(M):
    u, v = map(int, input().split())
    G[u].append(v)
s, t = map(int, input().split())

d = [-1] * (N + 1)

S = set()
S.add(s)
d[s] = 0
x = 1
while len(S) > 0:
    Q1 = set()
    for u in S:
        for v in G[u]:
            Q1.add(v)
    Q2 = set()
    for u in Q1:
        for v in G[u]:
            Q2.add(v)
    Q3 = set()
    for u in Q2:
        for v in G[u]:
            if d[v] < 0:
                d[v] = x
                Q3.add(v)
    x += 1
    S = Q3

print(d[t])
Buggy python submission (verdict: Runtime Error):
from math import gcd

n = int(input())
a = list(map(int, input().split()))
fw = [0] * n
bw = [0] * n

g = 0
for i in range(n):
    g = gcd(a[i], g)
    fw[i] = g

g = 0
for i in range(n-1, -1, -1):
    g = gcd(a[i], g)
    bw[i] = g

gmax = max(bw[1], fw[n-2])
for i in range(1, n-1):
    g = gcd(fw[i-1], bw[i+1])
    if gmax < g:
        gmax = g

print(gmax)


Fixed submission:
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))
fw = [0] * n
bw = [0] * n

g = 0
for i in range(n):
    g = gcd(a[i], g)
    fw[i] = g

g = 0
for i in range(n-1, -1, -1):
    g = gcd(a[i], g)
    bw[i] = g

gmax = max(bw[1], fw[n-2])
for i in range(1, n-1):
    g = gcd(fw[i-1], bw[i+1])
    if gmax < g:
        gmax = g

print(gmax)
Buggy python submission (verdict: Runtime Error):
m = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = map(int, input().split())
A = list(map(int, input().split()))
dp = [0] + [-N] * N
for x in range(1, N + 1):
    mx = -N
    for j in range(M):
        num = x - m[A[j]]
        if num >= 0:
            if mx < dp[num] + 1:
                mx = dp[num] + 1
    if mx < 0:
        dp[x] = -N
    else:
        dp[x] = mx

A.sort(reverse=True)
nd = dp[N]
n = N
for i in range(N):
    for a in A:
        if dp[n - m[a]] == nd - 1:
            nd -= 1
            n -= m[a]
            print(a, end="")
            break
print()




Fixed submission:
m = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = map(int, input().split())
A = list(map(int, input().split()))
dp = [0] + [-N] * N
for x in range(1, N + 1):
    mx = -N
    for j in range(M):
        num = x - m[A[j]]
        if num >= 0:
            if mx < dp[num] + 1:
                mx = dp[num] + 1
    if mx < 0:
        dp[x] = -N
    else:
        dp[x] = mx

A.sort(reverse=True)
nd = dp[N]
n = N
for i in range(N):
    for a in A:
        if n >= m[a] and dp[n - m[a]] == nd - 1:
            nd -= 1
            n -= m[a]
            print(a, end="")
            break
print()
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = [1] * (n + 1)
for i in range(2, n+1):
    for j in range(i, n+1, i)
        d[j] += 1
ans = 0
for i in range(1, n, 2):
  if d[i] == 8:
    ans += 1

print(ans)


Fixed submission:
n = int(input())
d = [1] * (n + 1)
for i in range(2, n+1):
    for j in range(i, n+1, i):
        d[j] += 1
ans = 0
for i in range(1, n+1, 2):
  if d[i] == 8:
    ans += 1
 
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
c = [0] * M
A = map(int, input().split())

S = [0]
w = 0
for a in A:
    w += a
    S.append(w % M)

S.sort()
ans = 0
prev = S[0]
c = 1
for i in range(1, N+1):
    if S[i] != prev:
        prev = S[i]
        ans += c * (c - 1) // 2
        c = 1
    else:
        c += 1
ans += c * (c - 1) // 2
print(ans)


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

S = [0]
w = 0
for a in A:
    w += a
    S.append(w % M)

S.sort()
ans = 0
prev = S[0]
c = 1
for i in range(1, N+1):
    if S[i] != prev:
        prev = S[i]
        ans += c * (c - 1) // 2
        c = 1
    else:
        c += 1
ans += c * (c - 1) // 2
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import log
x = int(input())
lx = log(x)
ans = 1
for b in range(2, int(b**(1/2))+1):
    h = int(lx/log(b))
    if b**h > ans: ans = b**h
 
print(ans)


Fixed submission:
from math import log
x = int(input())
lx = log(x)
ans = 1
for b in range(2, int(x**(1/2))+1):
    h = b
    while h*b <= x:
        h *= b
    if h > ans: ans = h

print(ans)

Buggy python submission (verdict: Runtime Error):
from math import log
x = int(input())
lx = log(x)
ans = 1
for b in range(2, int(b**(1/2))+1):
    h = int(lx/log(b))
    if b**h > ans: ans = b**h

print(ans)


Fixed submission:
from math import log
x = int(input())
lx = log(x)
ans = 1
for b in range(2, int(x**(1/2))+1):
    h = b
    while h*b <= x:
        h *= b
    if h > ans: ans = h

print(ans)
Buggy python submission (verdict: Runtime Error):
s = str(input(""))
t = str(input(""))

print(t + s)

Fixed submission:
s, t = input().split()
print(t + s)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())

for i in range(k):
    if (a >= 1): 
        a -= 1
    elif (b >= 1): 
        b -= 1
    else:
        break

print(str(a) + " " + str(b))

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

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

print(int(a * b / math.gcd(a, b)))

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

print(int(a * b / fractions.gcd(a, b)))
Buggy python submission (verdict: Runtime Error):
import fractions

a, b, x = map(int, input().split())
s1 = fractions.degrees(fractions.atan(2*b/a - 2*x/(a*a*a)))
s2 = 90 - fractions.degrees(fractions.atan(2 * x / (a * b * b)))

if(a*a*b/2 <= x):
    print(s1)
else:
    print(s2)

Fixed submission:
from math import degrees
from math import atan

a, b, x = map(int, input().split())
s1 = degrees(atan(2*b/a - 2*x/(a*a*a)))
s2 = 90 - degrees(atan(2 * x / (a * b * b)))

if(a*a*b/2 <= x):
    print(s1)
else:
    print(s2)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
a, b = map(int, input().split())
x = fractions.gcd(a, b)

def check(n):
  d = 2
  count = 1
  last = 0
  while n >= d:
    if (n % d == 0):
      if d != last:
        count += 1; last = d
      n /= d
    else:
      d += 1
  return count

print(check(x))


Fixed submission:
import fractions
a, b = map(int, input().split())
x = fractions.gcd(a, b)
t = x

i = 2
ans = 1;
while i * i <= t:
  if x % i == 0:
    while x % i == 0:
      x /= i
    ans += 1
  i += 1
if x != 1:
  ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())
alist = []

def check_a(n):
  d = 2
  while n >= d:
    if (n % d == 0):
      if d not in alist:
        alist.append(d)
      n /= d
    else:
      d += 1
      
def check_b(n):
  count = 1
  last = 0
  d = 2
  while n >= d:
    if (n % d == 0):
      if d in alist:
        if d != last:
        	count += 1; last = d
      n /= d
    else:
      d += 1
  return count

check_a(a)
print(check_b(b))


Fixed submission:
import fractions
a, b = map(int, input().split())
x = fractions.gcd(a, b)
t = x

i = 2
ans = 1;
while i * i <= t:
  if x % i == 0:
    while x % i == 0:
      x /= i
    ans += 1
  i += 1
if x != 1:
  ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))

# a.sort(reverse=True)
for i in range(m):
    a[a.index(max(a))] /= 2

ans = 0
for i in range(n):
    ans += a[i] // 1

print(int(ans))


Fixed submission:
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x*(-1), a))

heapq.heapify(a)
for i in range(m):
  heapq.heappush(a, heapq.heappop(a) / 2)

ans = 0
for i in range(n):
  ans += -a[i] // 1

print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))

a.sort(reverse=True)
for i in range(m):
    a[0] = a[0] / 2
    a.sort(reverse=True)

ans = 0
for i in range(n):
    ans += a[i] // 1

print(int(ans))

Fixed submission:
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x*(-1), a))

heapq.heapify(a)
for i in range(m):
  heapq.heappush(a, heapq.heappop(a) / 2)

ans = 0
for i in range(n):
  ans += -a[i] // 1

print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
for i in range(1, n):
    ans += i
print(ans)


Fixed submission:
n = int(input())
n = n - 1
if n % 2 == 1:
    ans = ((n+1)//2) * n
else:
    ans = n + (n//2) * (n-1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from numpy.linalg import solve
n = int(input())
a = list(map(int, input().split()))
ori = [0.5, 0.5] + [0] * (n-2) + [0.5, 0.5] + [0] * (n-2)
cul = []

for i in range(n):
    cul.append(ori[n-i:2*n-i])

x = solve(cul, a)
for i in range(n):
    print(int(x[i]), end=' ')


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
x = [0] * n
x[0] = sum(a) - 2 * sum(a[1::2])

for i in range(1, n):
    x[i] = 2 * a[i-1] - x[i-1]

for a in x:
    print(a, end=' ')
Buggy python submission (verdict: Runtime Error):
from scipy.misc import comb
X = 10 ** 9 + 7

n, k = map(int, input().split())
c = n - k + 1

for i in range(1, k+1):
    print(int(comb(c, i) * comb(k-1, i-1) % X))


Fixed submission:
from scipy.misc import comb
X = 10 ** 9 + 7

n, k = map(int, input().split())
c = n - k + 1

for i in range(1, k+1):
    print(int(comb(c, i, exact=True) * comb(k-1, i-1, exact=True)) % X)
Buggy python submission (verdict: Runtime Error):
x, a = map(int, input())
if (x < a):
    print(0)
else:
    print(10)

Fixed submission:
x, a = map(int, input().split())
if (x < a):
    print(0)
else:
    print(10)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [0] * m
dp = [1, 1]
x = 0
for i in range(m):
    a[i] = int(input())
if a[0] == 1:
    dp[1] = 0
    x = 1

for i in range(len(a)-1):
    if a[i+1] - a[i] == 1:
        print(0)
        exit(0)


for i in range(2, n+1):
    if i != a[x]:
        dp.append((dp[-1] + dp[-2]) % 1000000007)
    else:
        dp.append(0)
        if x < len(a)-1:
            x += 1
# print(dp)
print(dp[-1])


Fixed submission:
n, m = map(int, input().split())
a = [0] * 100100
dp = [1, 1]
x = 0
for i in range(m):
    a[i] = int(input())
if a[0] == 1:
    dp[1] = 0
    x = 1

for i in range(len(a)-1):
    if a[i+1] - a[i] == 1:
        print(0)
        exit(0)


for i in range(2, n+1):
    if i != a[x]:
        dp.append((dp[-1] + dp[-2]) % 1000000007)
    else:
        dp.append(0)
        if x < len(a)-1:
            x += 1
# print(dp)
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [0] * m
dp = [1, 1]

for i in range(m):
    a[i] = int(input())

for i in range(len(a)-1):
    if a[i+1] - a[i] == 1:
        print(0)
        exit(0)

x = 0
for i in range(1, n+1):
    if i != a[x]:
        dp.append((dp[-1] + dp[-2]) % 1000000007)
    else:
        dp.append(0)
        if x < len(a)-1:
            x += 1
# print(dp)
print(dp[-1])


Fixed submission:
n, m = map(int, input().split())
a = [0] * 100100
dp = [1, 1]
x = 0
for i in range(m):
    a[i] = int(input())
if a[0] == 1:
    dp[1] = 0
    x = 1

for i in range(len(a)-1):
    if a[i+1] - a[i] == 1:
        print(0)
        exit(0)


for i in range(2, n+1):
    if i != a[x]:
        dp.append((dp[-1] + dp[-2]) % 1000000007)
    else:
        dp.append(0)
        if x < len(a)-1:
            x += 1
# print(dp)
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [0] * m
dp = [1, 1]

for i in range(m):
    a[i] = int(input())

for i in range(len(a)-1):
    if a[i+1] - a[i] == 1:
        print(0)
        exit()

x = 0
for i in range(1, n+1):
    if i != a[x]:
        dp.append((dp[-1] + dp[-2]) % 1000000007)
    else:
        dp.append(0)
        if x < len(a)-1:
            x += 1
# print(dp)
print(dp[-1])


Fixed submission:
n, m = map(int, input().split())
a = [0] * 100100
dp = [1, 1]
x = 0
for i in range(m):
    a[i] = int(input())
if a[0] == 1:
    dp[1] = 0
    x = 1

for i in range(len(a)-1):
    if a[i+1] - a[i] == 1:
        print(0)
        exit(0)


for i in range(2, n+1):
    if i != a[x]:
        dp.append((dp[-1] + dp[-2]) % 1000000007)
    else:
        dp.append(0)
        if x < len(a)-1:
            x += 1
# print(dp)
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
times = [int(input()) for i in range(5)]
rest = [times[i] % 10 for i in range(len(times))]
m = rest.index(min(rest))
total = 0
for n in len(times):
    if n == m:
        total += times[n]
    else:
        total += ((times[n]+9) // 10) * 10

print(total)

Fixed submission:
lst = []
total = 0
for i in range(5):
    n = int(input())
    lst.append([(n-1) % 10, n])
lst.sort()

for i in range(len(lst)):
    if i == 0:
        total += lst[i][1]
    else:
        total += ((lst[i][1] + 9) // 10) * 10
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]
ac_list = []
for i in range(1, len(s)):
    if s[i] == 'C' and s[i-1] == 'A':
        ac_list.append([i-1, i])

for i in range(q):
    # print(s[lr[i][0] - 1:lr[i][1]])
    # print(s[lr[i][0] - 1:lr[i][1]].count('AC'))
    count = 0
    for n in range(len(ac_list)):
        if ac_list[n][0] >= lr[i][0] - 1 and ac_list[n][1] <= lr[i][1] - 1:
            count += 1
    print(count)

Fixed submission:
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]
ac_list = [0] * (n+1)
for i in range(n):
    ac_list[i+1] = ac_list[i] + (1 if s[i:i+2] == 'AC' else 0)
# print(ac_list)
for i in range(q):
    print(ac_list[lr[i][1]-1] - ac_list[lr[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

for i in range(q):
    # print(s[lr[i][0] - 1:lr[i][1]])
    print(s[lr[i][0] - 1:lr[i][1]].count('AC'))

Fixed submission:
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]
ac_list = [0] * (n+1)
for i in range(n):
    ac_list[i+1] = ac_list[i] + (1 if s[i:i+2] == 'AC' else 0)
# print(ac_list)
for i in range(q):
    print(ac_list[lr[i][1]-1] - ac_list[lr[i][0]-1])

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

for i in range(q):
    print(s[lr[i][0] - 1:lr[i][1]])
    print(s[lr[i][0] - 1:lr[i][1]].count('AC'))

Fixed submission:
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]
ac_list = [0] * (n+1)
for i in range(n):
    ac_list[i+1] = ac_list[i] + (1 if s[i:i+2] == 'AC' else 0)
# print(ac_list)
for i in range(q):
    print(ac_list[lr[i][1]-1] - ac_list[lr[i][0]-1])
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]

ab.sort(key=lambda x: x[0])

count = 0
money = 0
while True:
    count += ab[0][1]
    if count <= m:
        money += ab[0][0] * ab[0][1]
        del ab[0]
    else:
        money += ab[0][0] * (m - count + ab[0][1])
        break

print(money)

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

ab.sort(key=lambda x: x[0])

count = 0
money = 0
while True:
    count += ab[0][1]
    if count < m:
        money += ab[0][0] * ab[0][1]
        del ab[0]
    else:
        money += ab[0][0] * (m - count + ab[0][1])
        break

print(money)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = []
b = []
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

count = 0
money = 0
while count < m:
    count += b[a.index(min(a))]
    if count <= m:
        money += a[a.index(min(a))] * b[a.index(min(a))]
    else:
        money += a[a.index(min(a))] * (m - count + b[a.index(min(a))])

    del b[a.index(min(a))]
    del a[a.index(min(a))]
    
print(money)

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

ab.sort(key=lambda x: x[0])

count = 0
money = 0
while True:
    count += ab[0][1]
    if count < m:
        money += ab[0][0] * ab[0][1]
        del ab[0]
    else:
        money += ab[0][0] * (m - count + ab[0][1])
        break

print(money)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
count = 0
for i in range(len(s)):
    if '10' in s:
        s = s.replace('10', '', 1)
        count += 1
    elif '01' in s:
        s = s.replace('01', '', 1)
        count += 1
    else:
        pass

print(count * 2)

Fixed submission:
s = input()
print(min(s.count('0'), s.count('1')) * 2)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
count = 0
while '10' in s or '01' in s:
    if '10' in s:
        s = s.replace('10', '', 1)
    elif '01' in s:
        s = s.replace('01', '', 1)
    count += 1

print(count * 2)

Fixed submission:
s = input()
print(min(s.count('0'), s.count('1')) * 2)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
count = 0
while '10' in s:
    s = s.replace('10', '', 1)
    count += 1

while '01' in s:
    s = s.replace('01', '', 1)
    count += 1
print(count * 2)

Fixed submission:
s = input()
print(min(s.count('0'), s.count('1')) * 2)

Buggy python submission (verdict: Runtime Error):
s = input()
count = 0
while '10' in s:
    s = s.replace('10', '', 1)
    count += 1
    print(s)

while '01' in s:
    s = s.replace('01', '', 1)
    count += 1
print(count * 2)

Fixed submission:
s = input()
print(min(s.count('0'), s.count('1')) * 2)