qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
i, c = 0, 0
while i < n:
    if s[i] == "A":
        ac[i] = c
        i += 1
        if s[i] == "C":
            c += 1
            ac[i] = c
        else: ac[i] = c
    else:
        ac[i] = c
        i += 1
print(ac)
for p in lr:
    l, r = p[0] - 1, p[1] - 1
    print(int(ac[r] - ac[l]))

Fixed code:
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
i, c = 0, 0
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        ac[i+1] = ac[i] + 1
    else:
        ac[i+1] = ac[i]
for p in lr:
    l, r = p[0] - 1, p[1] - 1
    print(int(ac[r] - ac[l]))
Buggy code:
import itertools
n,q = map(int, input().split())
s = input()
calc = [0]*n
prev = None
for i,c in enumerate(s):
    if prev == 'A' and c == 'C':
        calc[i] = 1
    prev = c
calc = list(itertools.accumulate(calc))
print(calc)
for _ in range(q):
    l,r = map(int,input().split())
    print(calc[r-1]-calc[l-1])

Fixed code:
import itertools
n,q = map(int, input().split())
s = input()
calc = [0]*n
prev = None
for i,c in enumerate(s):
    if prev == 'A' and c == 'C':
        calc[i] = 1
    prev = c
calc = list(itertools.accumulate(calc))
for _ in range(q):
    l,r = map(int,input().split())
    print(calc[r-1]-calc[l-1])
Buggy code:
n, q = map(int, input().split())
s = input()
keep = [0]*(n)

for i in range(1, n):
    keep[i] = keep[i-1]
    l, r = i-1, i+1
    if s[l:r] == "AC":
        keep[i] += 1
print(keep)

for j in range(q):
    l, r = map(int, input().split())
    print(keep[r-1]-keep[l-1])


Fixed code:
n,q=map(int,input().split())
s=input()
cnt=[0]*n
for i in range(n):
    cnt[i]=cnt[i-1]
    if s[i-1:i+1]=="AC":
        cnt[i]+=1
for i in range(q):
    l,r=map(int,input().split())
    print(cnt[r-1]-cnt[l-1])
Buggy code:
    n, q = map(int, input().split())
    s = input()
    dat_q = []
    for i in range(q):
        l, r = map(int, input().split())
        dat_q.append((l, r))

    c = [0] * n
    for i in range(1, n):
        if s[i-1:i+1] == "AC":
            c[i] = c[i-1] + 1
        else:
            c[i] = c[i-1]
    for i in range(q):
        l, r = dat_q[i][0], dat_q[i][1]
        print(c[r - 1] - c[l - 1])

Fixed code:
n, q = map(int, input().split())
s = input()
dat_q = []
for i in range(q):
    l, r = map(int, input().split())
    dat_q.append((l, r))

c = [0] * n
for i in range(1, n):
    if s[i-1:i+1] == "AC":
        c[i] = c[i-1] + 1
    else:
        c[i] = c[i-1]
for i in range(q):
    l, r = dat_q[i][0], dat_q[i][1]
    print(c[r - 1] - c[l - 1])
Buggy code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    n, q = map(int, readline().split())
    s = readline().rstrip().decode()
    ac = []    
    cnt = 0
    for i in range(1, n+1):
        if (s[i-1] == 'A') and (s[i] == 'C'):
            cnt += 1
            ac.append(cnt)
        else:
            ac.append(cnt)
    query = []
    for _ in range(q):
        l, r = map(int, readline().split())
        l -= 1
        r -= 1
        print(ac[r]-ac[l])
if __name__ == '__main__':
    main()


Fixed code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    n, q = map(int, readline().split())
    s = readline().rstrip().decode()
    ac = [0]    
    cnt = 0
    for i in range(1, n):
        if (s[i-1] == 'A') and (s[i] == 'C'):
            cnt += 1
            ac.append(cnt)
        else:
            ac.append(cnt)
    query = []
    for _ in range(q):
        l, r = map(int, readline().split())
        l -= 1
        r -= 1
        print(ac[r]-ac[l])
if __name__ == '__main__':
    main()
Buggy code:
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])

Fixed code:
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 code:
N, Q = map(int, input().split())
S = input()
L = [list(map(int, input().split())) for _ in range(Q)]
C = [0]*N
for i in range(1,N):
	if S[i-1] == 'A' and S[i] == 'C':
		C[i] = C[i-1] + 1
	else:
		C[i] = C[i-1]
print(C)
for i in range(Q):
	print(C[L[i][1] - 1]- C[L[i][0] - 1])


Fixed code:
N, Q = map(int, input().split())
S = input()
L = [list(map(int, input().split())) for _ in range(Q)]
C = [0]*N
for i in range(1,N):
	if S[i-1] == 'A' and S[i] == 'C':
		C[i] = C[i-1] + 1
	else:
		C[i] = C[i-1]
for i in range(Q):
	print(C[L[i][1] - 1]- C[L[i][0] - 1])
Buggy code:
import numpy as np

def count(s):
    prev = ""
    cnt = 0
    dp = np.zeros(len(s)+1, dtype=int)
    for i, c in enumerate(s):
        if (prev == "A") and (c == "C"):
            cnt += 1
        prev = c
        dp[i+1] = cnt
    return dp

def solve(n, q, s, l, r):
    dp = count(s)
    for i in range(q):
        print(dp[r[i]] - dp[l[i]])

n, q = map(int, input().split())
s = input()
l = np.zeros(n, dtype=int)
r = np.zeros(n, dtype=int)
for i in range(q):
    l[i], r[i] = map(int, input().split())
print(solve(n, q, s, l, r))

Fixed code:
import numpy as np

def count(s):
    prev = ""
    cnt = 0
    dp = np.zeros(len(s)+1, dtype=int)
    for i, c in enumerate(s):
        if (prev == "A") and (c == "C"):
            cnt += 1
        prev = c
        dp[i+1] = cnt
    return dp

def solve(n, q, s, l, r):
    dp = count(s)
    for i in range(q):
        print(dp[r[i]] - dp[l[i]])

n, q = map(int, input().split())
s = input()
l = np.zeros(q, dtype=int)
r = np.zeros(q, dtype=int)
for i in range(q):
    l[i], r[i] = map(int, input().split())
solve(n, q, s, l, r)
Buggy code:
N, Q = map(int, input().split())
S = input()
li = [list(map(int, input().split())) for _ in range(Q)]

ACList = list()
prevA = False
accum = 0
for i in range(N):
    if prevA:
        if S[i] == 'C':
            accum += 1
            prevA = False
        elif S[i] == 'A':
            prevA = True
    else:
        if S[i] == 'A':
            prevA = True
    ACList.append(accum)
print(ACList)

for i in range(Q):
    print( ACList[li[i][1]-1] - ACList[li[i][0]-1] )

Fixed code:
N, Q = map(int, input().split())
S = input()
li = [list(map(int, input().split())) for _ in range(Q)]

ACList = list()
prevA = False
accum = 0
for i in range(N):
    if prevA and S[i] =='C':
        accum += 1
    if S[i] == 'A':
        prevA = True
    else:
        prevA = False
    ACList.append(accum)

for i in range(Q):
    print( ACList[li[i][1]-1] - ACList[li[i][0]-1] )
Buggy code:
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])
    

Fixed code:
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 code:
from sys import stdin
n, q = stdin.readline().split()
s = stdin.readline().strip()
count = 0
for i in range(q):
  l, r = map(int, stdin.readline().split())
  for j in range(l-1, r-1):
    if s[j] + s[j+1] == 'AC':
      count += 1
      
  print(count)


Fixed code:
from sys import stdin

n, q = map(int, stdin.readline().split())
s = stdin.readline().strip()
counts = [0 for i in range(n)]
count = 0
for i in range(1, n):
    if s[i-1:i+1] == 'AC':
        count += 1
    counts[i] = count

for i in range(q):
    l, r = map(int, stdin.readline().split())
    print(counts[r-1] - counts[l-1])
Buggy code:
n,q=map(int,input().split())
s=input()
t=[]
for i in range(n):
  if t[i:i+2]=='AC':
    t.append(1)
  else:
    t.append(0)
for j in range(q):
  l,r=map(int,input().split())
  print(sum(t[l-1:r]))
  
    


Fixed code:
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 j in range(q):
  l,r=map(int,input().split())
  print(t[r-1]-t[l-1])
Buggy code:
n, q = map(int,input().split())
s = input()
l = [0]*q
r = [0]*q
for i in range(q):
  l[i],r[i] = map(int,input().split())
count = 0
c_sum = [0]*n
for i in range(n-1):
  if s[i] == 'A' and s[i+1] == 'C':
    count += 1
  c_sum[i] = count
print(c_sum)
for i in range(q):
  print(c_sum[r[i]-2] - c_sum[l[i]-2])

Fixed code:
n, q = map(int,input().split())
s = input()
l = [0]*q
r = [0]*q
for i in range(q):
  l[i],r[i] = map(int,input().split())
count = 0
c_sum = [0]*n
for i in range(n-1):
  if s[i] == 'A' and s[i+1] == 'C':
    count += 1
  c_sum[i] = count
for i in range(q):
  print(c_sum[r[i]-2] - c_sum[l[i]-2])
Buggy code:
N, Q = map(int, input().split())
S = input()
flag = True
R = [0]*N
a = 0
for i in range(N):
    s = S[i]
    if s == "A":
        flag = True
    elif s == "C" and flag:
        a += 1
        flag = False
    else:
        flag = False
    R[i] = a
print(R)
for i in range(Q):
    l, r = map(int, input().split())
    print(R[r-1] - R[l-1])


Fixed code:
N, Q = map(int, input().split())
S = input()
flag = True
R = [0]*N
a = 0
for i in range(N):
    s = S[i]
    if s == "A":
        flag = True
    elif s == "C" and flag:
        a += 1
        flag = False
    else:
        flag = False
    R[i] = a
for i in range(Q):
    l, r = map(int, input().split())
    print(R[r-1] - R[l-1])
Buggy code:
# -*- coding: utf-8 -*-
#ABC122C
import sys
import copy
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
q=hoge[1]

s = input()

ans=[]
sum=0
print(s)

for j in range(0,n-1):
	if(s[j]=="A")and(s[j+1]=="C"):
		sum+=1
	ans.append(sum)
	#print(s[j])
ans.append(sum)
ans.append(0)
#ans[n-1]=sum
#print(ans)
print(ans)

l=[]
r=[]
sum=0
for i in range(0,q):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))

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

Fixed code:
# -*- coding: utf-8 -*-
#ABC122C
import sys
import copy
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
q=hoge[1]

s = input()

ans=[]
sum=0
#print(s)

for j in range(0,n-1):
	if(s[j]=="A")and(s[j+1]=="C"):
		sum+=1
	ans.append(sum)
	#print(s[j])
ans.append(sum)
ans.append(0)
#ans[n-1]=sum
#print(ans)
#print(ans)

l=[]
r=[]
sum=0
for i in range(0,q):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))

	print(ans[hoge[1]-2]-ans[hoge[0]-2])
Buggy code:
N,Q = map(int,input().split())
s = input()
al = [0] * N
al[0] = 0
for i in range(1,N):
    if s[i-1:i+1] == 'AC':al[i] = al[i-1]+1
    else:al[i]=al[i-1]
for _ in range(Q):
    l,r = map(int,input().split())
    print(l,r,':',al[r-1]-al[l-1])

Fixed code:
N,Q = map(int,input().split())
s = input()
al = [0] * N
al[0] = 0
for i in range(1,N):
    if s[i-1:i+1] == 'AC':al[i] = al[i-1]+1
    else:al[i]=al[i-1]
for _ in range(Q):
    l,r = map(int,input().split())
    print(al[r-1]-al[l-1])
Buggy code:
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)
    print(t)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])



Fixed code:
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 code:
n,q = list(map(int,input().split()))
s = list(input())
num = list()
check = [0]*n
for i in range(0,n-1):
        if s[i] == "A" and s[i+1] == "C":
                check[i] = check[i-1]+1
        else:
              check[i] =check[i-1] 
ans = 0
for i in range(0,q):
        num = list(map(int,input().split()))
        ans = check[num[1]-2]-check[num[0]-1]
        print(ans)

Fixed code:
n,q = list(map(int,input().split()))
s = list(input())
num = list()
check = [0]*n
for i in range(1,n):
        if s[i-1] == "A" and s[i] == "C":
                check[i] = check[i-1]+1
        else:
                check[i] = check[i-1]
ans = 0
for i in range(0,q):
        num = list(map(int,input().split()))
        ans = check[num[1]-1]-check[num[0]-1]
        print(ans)
Buggy code:
    # coding: UTF-8
    import sys
    #sys.setrecursionlimit(n)
    import heapq
    import re
    import bisect
    import random
    import math
    import itertools
    from collections import defaultdict, deque
    from copy import deepcopy
    from decimal import *
     
    n, q = map(int, input().split())
    s = list(input())
     
    ss = ""
    a = [0] * n
    b = [0] * n
    for i in range(n):
        if s[i] == "A":
            ss = s[i]
        elif s[i] == "C":
            ss += s[i]
        if ss == "AC":
            a[i] = a[i - 1] - 1
            b[i] += b[i - 1] + 1
            ss = ""
        else:
            if i > 0:
                a[i] = a[i - 1]
                b[i] = b[i - 1]
     
    for i in range(q):
        x, y = map(int, input().split())
        print(max(0, b[y - 1] + a[x - 1]))

Fixed code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

n, q = map(int, input().split())
s = list(input())

ss = ""
b = [0] * n
for i in range(n):
    if s[i] == "A":
        ss = s[i]
    elif s[i] == "C":
        ss += s[i]
    else:
        ss = ""
    if ss == "AC":
        b[i] += b[i - 1] + 1
        ss = ""
    else:
        if i > 0:
            b[i] = b[i - 1]
for i in range(q):
    x, y = map(int, input().split())
    print(b[y - 1] - b[x - 1])
Buggy code:
n,q = map(int,input().split())
s=input()
c=0
AC=[0]*(n)
for i in range(n):
    if 'AC' ==s[i-1]+s[i]:
        c+=1
    AC[i]=c

print(AC)
for i in range(q):
    l,r=map(int,input().split())
    print(AC[r-1]-AC[l-1])


Fixed code:
n,q = map(int,input().split())
s=input()
c=0
AC=[0]*(n)
for i in range(n):
    if s[i-1]=='A' and s[i]=='C':
        c+=1
    AC[i]=c


for i in range(q):
    l,r=map(int,input().split())
    print(AC[r-1]-AC[l-1])
Buggy code:
N,Q = map(int,input().split())
S = input()
t = [0] * (N + 1)

for i in range(N):
    if S[i : i + 2] == 'AC':
        t[i + 1] = t[i] + 1
    else:
        t[i + 1] = t[i]

for i in range(Q):
    l, r = map(int, input().split())

print(t[r-1] - t[l-1])

Fixed code:
N,Q = map(int,input().split())
S = input()
t = [0] * (N + 1)

for i in range(N):
    if S[i : i + 2] == 'AC':
        t[i + 1] = t[i] + 1
    else:
        t[i + 1] = t[i]

for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
Buggy code:
N,Q = map(int,input().rstrip().split())
S = input().rstrip()
a = [0]*N
for i in range(N):
    if i > 1:
        a[i] = a[i-1]
    if i != 0 and S[i-1]=='A' and S[i] == 'C':
        a[i] += 1
for _ in range(Q):
    l, r = map(int,input().rstrip().split())

Fixed code:
N,Q = map(int,input().rstrip().split())
S = input().rstrip()
a = [0]*N
for i in range(N):
    if i > 1:
        a[i] = a[i-1]
    if i != 0 and S[i-1]=='A' and S[i] == 'C':
        a[i] += 1
for _ in range(Q):
    l, r = map(int,input().rstrip().split())
    print(a[r-1]-a[l-1])
Buggy code:
N, Q = map(int, input().split())
S = input()
qn = [list(map(int, input().split())) for _ in range(Q)]
S = "0" + S
cnt = []
cnt.append(0)
for i in range(1, N+1):
    if (S[i-1:i+1] == "AC"):
        cnt.append(cnt[i-1] + 1)
    else:
        cnt.append(cnt[i-1])
for q in qn:
    ans = cnt[q[1]] - cnt[q[0]-1]
#    if S[q[0]-1:q[0]+1] == "AC":
#        ans -= 1
    print(ans)



Fixed code:
N, Q = map(int, input().split())
S = input()
qn = [list(map(int, input().split())) for _ in range(Q)]
S = "0" + S
cnt = []
cnt.append(0)
for i in range(1, N+1):
    if (S[i-1:i+1] == "AC"):
        cnt.append(cnt[i-1] + 1)
    else:
        cnt.append(cnt[i-1])
for q in qn:
    ans = cnt[q[1]] - cnt[q[0]-1]
    if S[q[0]-1:q[0]+1] == "AC":
        ans -= 1
    print(ans)
Buggy code:
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])

Fixed code:
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
lr = [tuple(map(int, input().split())) for _ in range(Q)]
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for l, r in lr:
    print(t[r-1] - t[l-1])
Buggy code:
# -*- coding: utf-8 -*-

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	n,q=map(int, io().split())
	s=list(io())
	
	ss=[0 for _ in s]
	for i, (c, cn) in enumerate(zip(s, s[1:])):
		if c=='A' and cn=='C':
			ss[i]=1
	print(ss)
	#ret=[]
	for i in range(q):
		r,l=map(int, io().split())
		rr=sum(ss[r-1:l])-ss[l-1]
		#ret.append(str(rr))
		print(rr)
	
#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	#print (main(io))
	main(io)

Fixed code:
 # -*- coding: utf-8 -*-

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	n,q=map(int, io().split())
	s=list(io())
	
	ss=[0 for _ in s]
	sss=ss.copy()
	for i, c in enumerate(s[1:],1):
		if s[i-1]=='A' and s[i]=='C':
			ss[i]=1
		sss[i] = ss[i] + sss[i-1]
	
	for i in range(q):
		r, l=map(int, io().split())
		#rr=sum(ss[r-1:l])-ss[l-1]
		rr=sss[l-1]-sss[r-1]
		#ret.append(str(rr))
		print(rr)
	
#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	#print (main(io))
	main(io)
Buggy code:
import sys
def input():
    return sys.stdin.readline()[:-1]
N,Q=map(int, input().split())
S=input()
L=[None]*(N)
t=0
for i in range(N-1):
    L[i]=t
    if S[i]=="A" and S[i+1]=="C":
        t+=1
L[-1]=t
for i in range(Q):
    l,r=map(lambda x:int(x)-1,input().split())
    print(L[r-1]-L[l-1])

Fixed code:
import sys
def input():
    return sys.stdin.readline()[:-1]
N,Q=map(int, input().split())
S=input()
L=[None]*(N)
t=0
for i in range(N-1):
    L[i]=t
    if S[i]=="A" and S[i+1]=="C":
        t+=1
L[-1]=t
for i in range(Q):
    l,r=map(int,input().split())
    print(L[r-1]-L[l-1])
Buggy code:
import bisect
N, Q = map(int, input().split())
S = list(input())
lr = [list(map(int, input().split())) for i in range(Q)]

lst=[]
for i in range(N-1):
    if S[i]=="A" and S[i+1]=="C":
        lst.append(i)

ans=[]
for j in range(Q):
    l,r = lr[j][0]-1, lr[j][1]-1
    ans.append(bisect.bisect_right(lst,r) - bisect.bisect_left(lst,l))

for a in ans:
    print(a)


Fixed code:
import bisect
N, Q = map(int, input().split())
S = list(input())
lr = [list(map(int, input().split())) for i in range(Q)]

alst,clst=[],[]
for i in range(N-1):
    if S[i]=="A" and S[i+1]=="C":
        alst.append(i)
        clst.append(i+1)

ans=[]
for j in range(Q):
    l,r = lr[j][0]-1, lr[j][1]-1
    ans.append(bisect.bisect_right(clst,r) - bisect.bisect_left(alst,l))

for a in ans:
    print(a)
Buggy code:
N, Q = map(int, input().split())
S=input()
li = [list(map(int, input().split())) for _ in range(Q)]

A=[0]*(N)

for i in range(N-1):
    if S[i:i+2]=='AC':
        A[i+1]=A[i]+1
    else:
        A[i+1]=A[i]

print(A)

for k in li:
    l=k[0]-1
    r=k[1]-1
    print(A[r]-A[l])

Fixed code:
N, Q = map(int, input().split())
S=input()
li = [list(map(int, input().split())) for _ in range(Q)]

A=[0]*(N)

for i in range(N-1):
    if S[i:i+2]=='AC':
        A[i+1]=A[i]+1
    else:
        A[i+1]=A[i]

for k in li:
    l=k[0]-1
    r=k[1]-1
    print(A[r]-A[l])
Buggy code:
n,q=map(int,input().split())
s=input()
c=[0 for _ in range(n)]
p=''
d=0
for i in range(n):
  x=s[i]
  if p=='A' and x=='C':
    d+=1
  p=x
  c[i]=d
print(c)
for i in range(q):
  ans=0
  l,r=map(int,input().split())
  ans=c[r-1]-c[l-1]

  print(ans)


Fixed code:
n,q=map(int,input().split())
s=input()
c=[0 for _ in range(n)]
p=''
d=0
for i in range(n):
  x=s[i]
  if p=='A' and x=='C':
    d+=1
  p=x
  c[i]=d
for i in range(q):
  ans=0
  l,r=map(int,input().split())
  ans=c[r-1]-c[l-1]

  print(ans)
Buggy code:
n, q = map(int, input().split())
s = input()
cnt_AC = [0] * n
cnt = 0

for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        cnt += 1
    cnt_AC[i + 1] = cnt
print(cnt_AC)
for i in range(q):
    l, r = map(int, input().split())
    print(cnt_AC[r - 1] - cnt_AC[l - 1])

Fixed code:
n, q = map(int, input().split())
s = input()
cnt_AC = [0] * n
cnt = 0

for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        cnt += 1
    cnt_AC[i + 1] = cnt

for i in range(q):
    l, r = map(int, input().split())
    print(cnt_AC[r - 1] - cnt_AC[l - 1])
Buggy code:
n,q=map(int,input().split())
s=input()
l=[list(map(int,input().split())) for _ in range(q)]
a=[0]*(n-1)
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    a[i]=1
b=[0]*n
for i in range(n-1):
  b[i+1]=b[i]+a[i]
print(b)
for i in range(q):
  print(b[l[i][1]-1]-b[l[i][0]-1])

Fixed code:
n,q=map(int,input().split())
s=input()
l=[list(map(int,input().split())) for _ in range(q)]
a=[0]*(n-1)
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    a[i]=1
b=[0]*n
for i in range(n-1):
  b[i+1]=b[i]+a[i]
for i in range(q):
  print(b[l[i][1]-1]-b[l[i][0]-1])
Buggy code:
N, Q = [int(_) for _ in input().split()]
S = input()
LR = [[int(_) for _ in input().split()] for _ in range(Q)]

cumsum = [0] * (N + 10)
for i in range(N - 1):
    cumsum[i] = cumsum[i - 1]
    if S[i:i + 2] == 'AC':
        cumsum[i] += 1

print(cumsum)
for l, r in LR:
    print(cumsum[r - 2] - cumsum[l - 2])


Fixed code:
N, Q = [int(_) for _ in input().split()]
S = input()
LR = [[int(_) for _ in input().split()] for _ in range(Q)]

cumsum = [0] * (N + 10)
for i in range(N - 1):
    cumsum[i] = cumsum[i - 1]
    if S[i:i + 2] == 'AC':
        cumsum[i] += 1

for l, r in LR:
    print(cumsum[r - 2] - cumsum[l - 2])
Buggy code:
N,Q=map(int,input().split()) 
S=sinput()
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])

Fixed code:
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 code:
N,Q = map(int,input().split(" "))
S = input()
a = [0] *  N
acc = [0] * N
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        a[i] = 1
        acc[i] += a[i]
    acc[i+1] = acc[i]

acc[N-1] = acc[N-2]
print(acc)
for i in range(Q):
    l,r = map(int,input().split(" "))
    if l > 1:
        ans = acc[r-1] - acc[l-2]
    else:
        ans = acc[r-1]
    if a[r-1] == 1:
        ans -= 1
    
    print(ans)

Fixed code:
N,Q = map(int,input().split(" "))
S = input()
a = [0] *  N
acc = [0] * N
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        a[i] = 1
        acc[i] += a[i]
    acc[i+1] = acc[i]

acc[N-1] = acc[N-2]
for i in range(Q):
    l,r = map(int,input().split(" "))
    if l > 1:
        ans = acc[r-1] - acc[l-2]
    else:
        ans = acc[r-1]
    if a[r-1] == 1:
        ans -= 1
    
    print(ans)
Buggy code:
n,q=list(map(int,input().split()))
s=list(input())
l=[0]*q
r=[0]*q
for i in range(q):
  l[i],r[i]=list(map(int(input().split())))
A=[]
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    A.append(1)
  else:
    A.append(0)
check=[0]+A
check=list(accumulate(check))
for i in range(q):
  print(check[r[i]]-check[l[i]+1])

    
  

Fixed code:
from itertools import accumulate
n,q=list(map(int,input().split()))
s=list(input())
l=[0]*q
r=[0]*q
for i in range(q):
  l[i],r[i]=list(map(int,input().split()))
A=[]
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    A.append(1)
  else:
    A.append(0)
check=[0]+A+[0]
check=list(accumulate(check))
for i in range(q):
  print(check[r[i]-1]-check[l[i]-1])