Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):


def read_input():
    n = int(input())
    tlist = []
    for i in range(n):
        tlist.append(int(input()))

    return n, tlist

gcdmemo = {}

def mygcd(a, b):
    if b == 0:
        return a

    if not (a, b) in gcdmemo.keys():
        gcdmemo[(a, b)] = mygcd(b, a % b)

    return gcdmemo[(a, b)]


def mylcm(a, b):
    g = mygcd(a, b)
    if g != 0:
        return int(a * b / g)
    return a * b


def submit():
    n, tlist = read_input()

    acc = 1
    for t in tlist:
        acc = mylcm(acc, t)

    print(acc)

if __name__ == '__main__':
    submit()

Fixed submission:


def read_input():
    n = int(input())
    tlist = []
    for i in range(n):
        tlist.append(int(input()))

    return n, tlist


def mygcd(a, b):
    if b == 0:
        return a
    return mygcd(b, a % b)


def mylcm(a, b):
    g = mygcd(a, b)
    return a * b // g


def submit():
    n, tlist = read_input()

    acc = 1
    for t in tlist:
        acc = mylcm(acc, t)

    print(acc)


if __name__ == '__main__':
    submit()

Buggy python submission (verdict: Runtime Error):
def read_input():
    n = int(input())
    tlist = []
    for i in range(n):
        tlist.append(int(input()))

    return n, tlist


def mygcd(a, b):
    if b == 0:
        return a
    return mygcd(b, a % b)


def mylcm(a, b):
    g = mygcd(a, b)
    return int(a * b / g)


def submit():
    n, tlist = read_input()

    acc = 1
    for t in tlist:
        acc = mylcm(acc, t)

    print(acc)

if __name__ == '__main__':
    submit()

Fixed submission:


def read_input():
    n = int(input())
    tlist = []
    for i in range(n):
        tlist.append(int(input()))

    return n, tlist


def mygcd(a, b):
    if b == 0:
        return a
    return mygcd(b, a % b)


def mylcm(a, b):
    g = mygcd(a, b)
    return a * b // g


def submit():
    n, tlist = read_input()

    acc = 1
    for t in tlist:
        acc = mylcm(acc, t)

    print(acc)


if __name__ == '__main__':
    submit()

Buggy python submission (verdict: Runtime Error):
def read_input():
    n = int(input())
    tlist = []
    for i in range(n):
        tlist.append(int(input()))

    return n, tlist


def mygcd(a, b):
    if b == 0:
        return a
    return mygcd(b, a % b)


def mylcm(a, b):
    g = mygcd(a, b)
    return int(a * b / g)


def submit():
    n, tlist = read_input()

    acc = 1
    for t in tlist:
        acc = mylcm(acc, t)

    print(acc)

if __name__ == '__main__':
    submit()

Fixed submission:


def read_input():
    n = int(input())
    tlist = []
    for i in range(n):
        tlist.append(int(input()))

    return n, tlist


def mygcd(a, b):
    if b == 0:
        return a
    return mygcd(b, a % b)


def mylcm(a, b):
    g = mygcd(a, b)
    return a * b // g


def submit():
    n, tlist = read_input()

    acc = 1
    for t in tlist:
        acc = mylcm(acc, t)

    print(acc)


if __name__ == '__main__':
    submit()
Buggy python submission (verdict: Time Limit Exceeded):

def read_input():
    n = int(input())
    alist = [-1]

    for i in range(n):
        alist.append(int(input()))


    return n, alist

def submit():
    n, alist = read_input()

    through = {}
    curr_button = 1
    steps = 0
    while curr_button not in through.keys():
        through[curr_button] = 1
        curr_button = alist[curr_button]
        steps += 1

        if curr_button == 2:
            break

    if curr_button == 2:
        print(steps)
    else:
        print(-1)



if __name__ == '__main__':
    submit()

Fixed submission:
from collections import defaultdict

def read_input():
    n = int(input())
    alist = [-1]

    for i in range(n):
        alist.append(int(input()))


    return n, alist

def submit():
    n, alist = read_input()

    through = defaultdict(int)
    curr_button = 1
    steps = 0
    while through[curr_button] == 0:
        through[curr_button] = 1
        curr_button = alist[curr_button]
        steps += 1

        if curr_button == 2:
            break

    if curr_button == 2:
        print(steps)
    else:
        print(-1)



if __name__ == '__main__':
    submit()

Buggy python submission (verdict: Time Limit Exceeded):

def read_input():
    n = int(input())
    alist = [-1]

    for i in range(n):
        alist.append(int(input()))


    return n, alist

def submit():
    n, alist = read_input()

    through = []
    curr_button = 1
    steps = 0
    while curr_button not in through:
        through.append(curr_button)
        curr_button = alist[curr_button]
        steps += 1

        if curr_button == 2:
            break

    if curr_button == 2:
        print(steps)
    else:
        print(-1)



if __name__ == '__main__':
    submit()

Fixed submission:
from collections import defaultdict

def read_input():
    n = int(input())
    alist = [-1]

    for i in range(n):
        alist.append(int(input()))


    return n, alist

def submit():
    n, alist = read_input()

    through = defaultdict(int)
    curr_button = 1
    steps = 0
    while through[curr_button] == 0:
        through[curr_button] = 1
        curr_button = alist[curr_button]
        steps += 1

        if curr_button == 2:
            break

    if curr_button == 2:
        print(steps)
    else:
        print(-1)



if __name__ == '__main__':
    submit()
Buggy python submission (verdict: Time Limit Exceeded):

def read_input():
    n = int(input())
    alist = list(map(int, input().split()))
    return n, alist

def get_sign(x):
    if x > 0:
        return 1
    elif x < 0:
        return -1
    return 0

def submit():
    n, alist = read_input()

    s = alist[0]
    sign = get_sign(s)
    edit = 0
    for a in alist[1:]:
        temp = s + a
        temp_sign = get_sign(temp)

        while temp_sign == sign or temp == 0:
            edit += 1
            temp -= sign
            temp_sign = get_sign(temp)

        s = temp
        sign = temp_sign

    print(edit)





if __name__ == '__main__':
    submit()


Fixed submission:

def read_input():
    n = int(input())
    alist = list(map(int, input().split()))
    return n, alist

def get_sign(x):
    if x > 0:
        return 1
    elif x < 0:
        return -1
    return 0

def submit():
    n, alist = read_input()

    # pattern 1
    s = 0
    sign = 1
    edit = 0

    for a in alist:
        temp = s + a
        temp_sign = get_sign(temp)

        if sign == temp_sign:
            edit += temp_sign * temp
            temp -= temp

        if temp == 0:
            edit += 1
            temp -= sign

        s = temp
        sign = get_sign(s)

    edit1 = edit

    # pattern 2
    s = 0
    sign = -1
    edit = 0

    for a in alist:
        temp = s + a
        temp_sign = get_sign(temp)

        if sign == temp_sign:
            edit += temp_sign * temp
            temp -= temp

        if temp == 0:
            edit += 1
            temp -= sign

        s = temp
        sign = get_sign(s)

    edit2 = edit

    print(min(edit1, edit2))


if __name__ == '__main__':
    submit()
Buggy python submission (verdict: Time Limit Exceeded):

import math

def read_input():
    n = int(input())
    return n


def submit():
    n = read_input()

    factor_cand = int(math.ceil(math.sqrt(n)))

    while n % factor_cand:
        factor_cand += 1

    a = int(n / factor_cand)
    b = int(factor_cand)

    al = len([c for c in str(a)])
    bl = len([c for c in str(b)])

    print(max(al, bl))



if __name__ == '__main__':
    submit()


Fixed submission:

import math

def read_input():
    n = int(input())
    return n


def submit():
    n = read_input()

    factor_cand = int(math.ceil(math.sqrt(n)))

    while n % factor_cand:
        factor_cand -= 1

        if factor_cand == 1:
            nl = len([c for c in str(n)])
            print(nl)
            return

    a = int(n / factor_cand)
    b = int(factor_cand)

    al = len([c for c in str(a)])
    bl = len([c for c in str(b)])

    print(max(al, bl))



if __name__ == '__main__':
    submit()
Buggy python submission (verdict: Time Limit Exceeded):


def read_input():
    n = int(input())
    alist = list(map(int, input().split()))
    return n, alist


def submit():
    n, alist = read_input()


    count = {}
    for a in alist:
        if a not in count.keys():
            count[a] = 1
        else:
            count[a] += 1

    count = list(count.items())
    pruned = []
    for c in count:
        if c[1] > 1:
            if c[1] % 2 == 0:
                pruned.append((c[0], 2))
            else:
                pruned.append((c[0], 1))
        else:
            pruned.append(c)

    f = False
    for c in pruned:
        if c[1] == 2:
            f = not f

    if f:
        print(len(pruned) - 1)
    else:
        print(len(pruned))

    return


if __name__ == '__main__':
    submit()


Fixed submission:


def read_input():
    n = int(input())
    alist = list(map(int, input().split()))
    return n, alist


def submit():
    n, alist = read_input()

    count = {}
    count_t = 0
    for a in alist:
        if a not in count.keys():
            count[a] = False
        else:
            count[a] = not count[a]
            if count[a]:
                count_t += 1
            else:
                count_t -= 1

    if count_t % 2 == 0:
        print(len(count))
    else:
        print(len(count) - 1)




if __name__ == '__main__':
    submit()
Buggy python submission (verdict: Runtime Error):


def warshall_floyd(d, n):
    # d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


def read_input():
    n, m = map(int, input().split())

    edges = []
    for i in range(m):
        a, b, c = map(int, input().split())
        edges.append((a - 1, b - 1, c))

    return n, m, edges

def submit():
    n, m, edges = read_input()

    # 全ノード間の最短経路を求める
    d = [[float('inf') for _ in range(n)] for _ in range(n)]

    for edge in edges:
        d[edge[0]][edge[1]] = edge[2]
        d[edge[1]][edge[0]] = edge[2]

    for i in range(n):
        d[i][i] = 0

    d = warshall_floyd(d, n)

    # 各edgeについていずれかの2点間の最短経路に含まれうるか確認する
    edge_inuse = [0 for _ in range(n)]
    for e, edge in enumerate(edges):
        for i in range(n):
            for j in range(n):
                dist1 = d[i][j]
                dist2 = d[i][edge[0]] + edge[2] + d[edge[1]][j]

                if dist1 == dist2:
                    edge_inuse[e] = 1
                    break

            if edge_inuse[e] == 1:
                break

    print(m - sum(edge_inuse))
    return


if __name__ == '__main__':
    submit()


Fixed submission:


def warshall_floyd(d, n):
    # d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


def read_input():
    n, m = map(int, input().split())

    edges = []
    for i in range(m):
        a, b, c = map(int, input().split())
        edges.append((a - 1, b - 1, c))

    return n, m, edges

def submit():
    n, m, edges = read_input()

    # 全ノード間の最短経路を求める
    d = [[float('inf') for _ in range(n)] for _ in range(n)]

    for edge in edges:
        d[edge[0]][edge[1]] = edge[2]
        d[edge[1]][edge[0]] = edge[2]

    for i in range(n):
        d[i][i] = 0

    d = warshall_floyd(d, n)

    # 各edgeについていずれかの2点間の最短経路に含まれうるか確認する
    edge_inuse = [0 for _ in range(m)]
    for e, edge in enumerate(edges):
        for i in range(n):
            for j in range(n):
                dist1 = d[i][j]
                dist2 = d[i][edge[0]] + edge[2] + d[edge[1]][j]

                if dist1 == dist2:
                    edge_inuse[e] = 1
                    break

            if edge_inuse[e] == 1:
                break

    print(m - sum(edge_inuse))
    return


if __name__ == '__main__':
    submit()
Buggy python submission (verdict: Runtime Error):
import numpy as np


def read_input():
    n = int(input())
    return n


def mymod(x):
    return x % (10**9 + 7)


def submit():
    N = read_input()
    N = list(map(int, list(bin(N)[2:])))

    dp = np.zeros((len(N) + 1, 3))
    dp[len(N)][0] = 1

    for i in range(len(N) - 1, -1, -1):
        for s in range(3):
            for k in range(3):
                new_s = 2 * s + N[len(N) - i - 1] - k
                if new_s < 0:
                    continue
                if new_s > 2:
                    new_s = 2
                dp[i][new_s] += mymod(dp[i + 1][s])
            dp[i][0] = mymod(dp[i][0])
            dp[i][1] = mymod(dp[i][1])
            dp[i][2] = mymod(dp[i][2])

    print(int(sum(dp[0])) % (10**9 + 7))

if __name__ == '__main__':
    submit()

Fixed submission:

def read_input():
    n = int(input())
    return n


def mymod(x):
    return x % (10**9 + 7)


def submit():
    N = read_input()
    N = list(map(int, list(bin(N)[2:])))

    dp = [[0]*(3) for _ in range(len(N) + 1)]
    dp[len(N)][0] = 1

    for i in range(len(N) - 1, -1, -1):
        for s in range(3):
            for k in range(3):
                new_s = 2 * s + N[len(N) - i - 1] - k
                if new_s < 0:
                    continue
                if new_s > 2:
                    new_s = 2
                dp[i][new_s] += dp[i + 1][s]
            dp[i][0] = mymod(dp[i][0])
            dp[i][1] = mymod(dp[i][1])
            dp[i][2] = mymod(dp[i][2])

    print(mymod((dp[0][0] + dp[0][1] + dp[0][2])))


if __name__ == '__main__':
    submit()
Buggy python submission (verdict: Runtime Error):

from itertools import combinations


def read_input():
    s = input().strip()
    return s

def split_and_sum(s, indice):
    indice_e = [0, *indice, 10]

    result = []
    for start,end in zip(indice_e, indice_e[1:]):
        result.append(int(s[start:end]))

    return sum(result)

def submit():
    s = read_input()
    max_index = len(s)

    acc = 0
    for i in range(max_index):
        for c in combinations(range(1, max_index), i):
            acc += split_and_sum(s, c)

    print(acc)

if __name__ == '__main__':
    submit()

Fixed submission:

from itertools import combinations


def read_input():
    s = input().strip()
    return s

def split_and_sum(s, indice):
    indice_e = [0] + indice + [10]

    result = []
    for start,end in zip(indice_e, indice_e[1:]):
        result.append(int(s[start:end]))

    return sum(result)

def submit():
    s = read_input()
    max_index = len(s)

    acc = 0
    for i in range(max_index):
        for c in combinations(range(1, max_index), i):
            acc += split_and_sum(s, list(c))

    print(acc)

if __name__ == '__main__':
    submit()
Buggy python submission (verdict: Runtime Error):
ubkookoookyfyut

Fixed submission:
a = int(input())
print(a+a*a+a*a*a)

Buggy python submission (verdict: Runtime Error):
unko

Fixed submission:
a = int(input())
print(a+a*a+a*a*a)

Buggy python submission (verdict: Runtime Error):
afgdgrh

Fixed submission:
a = int(input())
print(a+a*a+a*a*a)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 1
for x in a:
	ans *= x
	
if ans > 10**18:
	print(-1)
else:
	print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 1
a.sort()
for x in a:
	ans *= x
	if x == 0:
		print(0)
		break
	elif ans > 10**18:
		print(-1)
		break
else:
	print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def check(x, dist, H):

	for i, j in dist:
		if x == i:
			if H[x - 1] <= H[j - 1]:
				return 0
		elif x == j:
			if H[x - 1] <= H[i - 1]:
				return 0
	return 1



n, m = map(int, input().split())
H = list(map(int, input().split()))
dist = []
count = 0
for _ in range(m):
	a, b, = map(int, input().split())
	dist.append((a,b))

for x in range(1, n + 1):
	if check(x, dist, H) == 1:
		count += 1

print(count)


Fixed submission:
def check(a, b, H, L):


	if H[a - 1] <= H[b - 1]:
			L[a - 1] = 0
	if H[b - 1] <= H[a - 1]:
			L[b - 1] = 0
	
n, m = map(int, input().split())
H = list(map(int, input().split()))
L = [i for i in range(1, n + 1)]
count = 0
for _ in range(m):
	a, b = map(int, input().split())
	check(a, b, H, L)

for i in L:
	if i != 0:
		count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

count = 0
for i in range(1, n + 1):
	for a in A:
		if i == a:
			count += 1
	print(count)
	count = 0


Fixed submission:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
C = Counter(A)

for i in range(1, n + 1):
	print(C[i])
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
sum = 0
for x in range(1, k + 1):
	for y in range(1, k + 1):
		for z in range(1, k + 1):
			sum += gcd(x, y, z)
print(sum)

Fixed submission:
import math

k = int(input())
two = []
total = 0
for x in range(1, k + 1):
	for y in range(1, k + 1):
		two.append(math.gcd(x, y))

for z in range(1, k + 1):
	for i in two:
		total += math.gcd(z, i)
print(total)
Buggy python submission (verdict: Time Limit Exceeded):


n = int(input())
s = list(input())

count = 0
for i in range(n):
	for j in range(i + 1, n):
		for k in range(j + 1, n):
			if s[i] != s[j] and s[j] != s[k] and s[i] != s[k] and j != (k + i) / 2:
				count += 1
print(count)


Fixed submission:
from collections import Counter

n = int(input())
s = list(input())
c = Counter(s)
total = c['R'] * c['G'] * c['B']
count = 0
for i in range(n):
	for j in range(i + 1, n):
			k = 2 * j - i
			if k < n and s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
				count += 1
print(total - count)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
if n % k == 0:
	print(0)
else:
	while True:
		prev = n
		n = abs(n - k)
		if n >= prev:
			break
	print(prev)


Fixed submission:
n, k = map(int, input().split())
p = n // k
print(min(abs(n - p * k), abs(n - (p + 1) * k)))

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
if k == 1:
	print(0)
else:
	while True:
		prev = n
		n = abs(n - k)
		if n >= prev:
			break
	print(prev)


Fixed submission:
n, k = map(int, input().split())
p = n // k
print(min(abs(n - p * k), abs(n - (p + 1) * k)))
Buggy python submission (verdict: Runtime Error):
A,B,T = map(int, input()split())
X = (T+0.5)/A
print(B*X)

Fixed submission:
A,B,T = map(int, input().split())
X = T//A
print(B*X)
Buggy python submission (verdict: Runtime Error):
N = int(input().split())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
P = []
for i in range(N):
    p = V[i]-C[i]
    if p >0:
    	P.append(p)

print(sum(P))

Fixed submission:
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
P = []
for i in range(N):
    p = V[i]-C[i]
    if p >0:
    	P.append(p)

print(sum(P))
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
max_mount = h[0]
cnt = 0 
for i in range(n):
    if max_mount<=h[i]:
    	ans +=1
    	max_mount = h[i]
print(ans)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
max_mount = h[0]
ans = 0 
for i in range(n):
    if max_mount<=h[i]:
    	ans +=1
    	max_mount = h[i]
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
cnt = n 
h.reverse()
for i in h:
    for j in h:
    	if h[j]>h[i]:
    		h.remove(h[i])
    		cnt = cnt-1
    	else:
    		h.remove(h[i])
else:
    print(cnt)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
max_mount = h[0]
ans = 0 
for i in range(n):
    if max_mount<=h[i]:
    	ans +=1
    	max_mount = h[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if e-a>k or d=a>k or c-a>k or b-a>k:
    print(":(")
else:
    print("Yay!")

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if e-a>k:
    print(":(")

elif d-a>k:
    print(":(")

elif e-a>k:
    print(":(")

elif c-a>k:
    print(":(")

elif b-a>k:
    print(":(")

else:
    print("Yay!")
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

P = [A, B, C, D, E]
p = min(P)
if p>=N:
    print(5)
else:
    ans = 4+ceil(N/p)
    print(ans)

Fixed submission:
import math
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

P = [A, B, C, D, E]
p = min(P)
if p>=N:
    print(5)
else:
    ans = 4+math.ceil(N/p)
    print(ans)
Buggy python submission (verdict: Runtime Error):
b = input()
if b == "A":
    print("T")

elif b =="T":
    print("A")

elif b =="C":
    print("G")

elif b == "G":
    pritn("C")

Fixed submission:
b = input()
if b == "A":
    print("T")

elif b =="T":
    print("A")

elif b =="C":
    print("G")

elif b == "G":
    print("C")
Buggy python submission (verdict: Runtime Error):
s = input()
n = len(s)
a = "BDEFHIJKLMNOPQRSUVWXYZ"
cnt = []
for i in range(n):
    for j in range(i,n+1):
    	fr = s[i;j]
    	value = 1
    	for k in a:
    		if k in fr:
    			value = 0
    	if value:
    		cnt.append(len(fr))
    		
print(max(cnt))

Fixed submission:
s = input()
n = len(s)
a = "BDEFHIJKLMNOPQRSUVWXYZ"
cnt = []
for i in range(0, n):
    for j in range(i,n+1):
    	fr = s[i:j]
    	value = 1
    	for k in a:
    		if k in fr:
    			value = 0
    	if value:
    		cnt.append(len(fr))
    		
print(max(cnt))

Buggy python submission (verdict: Runtime Error):
s = input()
n = len(s)
a = [B,D,E,F,H,I,J,K,L,M,N,O,P,Q,R,S,U,V,W,X,Y,Z]
cnt = []
for i in range(n):
    for j in range(i,n+1):
    	fr = s[i;j]
    	value = 1
    	for k in a:
    		if k in fr:
    			value = 0
    	if value:
    		cnt.append(len(fr))
    		
print(max(cnt))

Fixed submission:
s = input()
n = len(s)
a = "BDEFHIJKLMNOPQRSUVWXYZ"
cnt = []
for i in range(0, n):
    for j in range(i,n+1):
    	fr = s[i:j]
    	value = 1
    	for k in a:
    		if k in fr:
    			value = 0
    	if value:
    		cnt.append(len(fr))
    		
print(max(cnt))

Buggy python submission (verdict: Runtime Error):
s = input()
n = len(s)
a = [B,D,E,F,H,I,J,K,L,M,N,O,P,Q,R,S,U,V,W,X,Y,Z]
cnt = []
for i in range(n):
    for j in range(i,n+1):
    	fr = s[i;j]
    	value = 1
    	for k in a:
    		if k in fr:
    			value = 0
    	if value:
    		cnt.append(len(fr))
print(max(cnt))

Fixed submission:
s = input()
n = len(s)
a = "BDEFHIJKLMNOPQRSUVWXYZ"
cnt = []
for i in range(0, n):
    for j in range(i,n+1):
    	fr = s[i:j]
    	value = 1
    	for k in a:
    		if k in fr:
    			value = 0
    	if value:
    		cnt.append(len(fr))
    		
print(max(cnt))
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
R = [list(map(int, input().split())) for i in range(Q)]
ans = []
for i in range(Q):
    x = R[i][0]-1
    y = R[i][1]
    a=S[x:y].count("AC")
    ans.append(a)

for i in range(Q):
    print(ans[i])

Fixed submission:
N, Q = map(int, input().split())
S = input()
t = [0]*(N+1)
for i in range(N):
    t[i+1]=t[i] + (1 if S[i:i+2]=="AC" else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
R = [list(map(int, input().split)) for i in range(Q)]
ans = []
for i in range(Q):
    x = R[i][0]-1
    y = R[i][1]
    a=S[x:y].count("AC")
    ans.append(a)

for i in range(Q):
    print(ans[i])

Fixed submission:
N, Q = map(int, input().split())
S = input()
t = [0]*(N+1)
for i in range(N):
    t[i+1]=t[i] + (1 if S[i:i+2]=="AC" else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1]-t[l-1])