qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n,q=map(int,input().split())
s=input()
Sum=[0]
sum=0
stack="Q"
for i in range(n):
  if stack=="A" and s[i]=="C":
    sum+=1
  stack=s[i]
  Sum.append(sum)
for i in range(q):
  l,r=map(int,input().split())
  print(Sum[r]-Sum[l-1])


Fixed code:
n,q=map(int,input().split())
s=input()
Sum=[0]
sum=0
stack="Q"
for i in range(n):
  if stack=="A" and s[i]=="C":
    sum+=1
  stack=s[i]
  Sum.append(sum)
for i in range(q):
  l,r=map(int,input().split())
  print(Sum[r]-Sum[l])
Buggy code:
n,q=map(int,input().split())
s=input()
dp=[0]*n
count=0
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    dp[i]=1+count
    count+=1
  else:
    dp[i]=count

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

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

#print(dp)
for i in range(q):
  l,r=map(int,input().split())
  print(dp[r-2]-dp[l-2])
Buggy code:
n,m=map(int,input().split())
l=list(input())
count=0
clist=[0]
for i in range(1,n):
  if l[i-1]=="A" and l[i]=="C":
    count+=1
  clist.append(count)
for i in range(m):
  i1,i2=map(int,input().split())
  if l[i1-1]=="C" and l[i1-2]=="A":
    ans=clist[i2-1]-clist[i1-1]-1
  else:
    ans=clist[i2-1]-clist[i1-1]
  print(ans)

Fixed code:
n,m=map(int,input().split())
l=list(input())
count=0
clist=[0]
for i in range(1,n):
  if l[i-1]=="A" and l[i]=="C":
    count+=1
  clist.append(count)
for i in range(m):
  i1,i2=map(int,input().split())
  if i1==1:
    ans=clist[i2-1]
  elif l[i1-1]=="C" and l[i1-2]=="A":
    ans=clist[i2-1]-clist[i1-2]-1
  else:
    ans=clist[i2-1]-clist[i1-2]
  print(ans)
Buggy code:
n,m=map(int,input().split())
l=list(input())
l1=[0]
i=0
for i in range(n-1):
  if l[i]=="A" and l[i+1]=="C":
    i+=1
    l1.append(i)
  else:
    l1.append(i)
for t in range(m):
  i,j=map(int,input().split())
  print(l1[j-1]-l1[i-1])


Fixed code:
n,m=map(int,input().split())
l=list(input())
l1=[0]
p=0
for i in range(n-1):
  if l[i]=="A" and l[i+1]=="C":
    p+=1
    l1.append(p)
  else:
    l1.append(p)
for t in range(m):
  i,j=map(int,input().split())
  print(l1[j-1]-l1[i-1])
Buggy code:
N, Q = map(int, input().split())
s = input()
nlis = [0]
cnt = 0
for i in range(len(s)-1):
    if(s[i:i+2] == "AC"): 
        cnt += 1
    nlis.append(cnt)
print(nlis)
for i in range(Q):
    in0, in1 = map(int, input().split())
    print(nlis[in1-1]-nlis[in0-1])

Fixed code:
N, Q = map(int, input().split())
s = input()
nlis = [0]
cnt = 0
for i in range(len(s)-1):
    if(s[i:i+2] == "AC"): 
        cnt += 1
    nlis.append(cnt)
#print(nlis)
for i in range(Q):
    in0, in1 = map(int, input().split())
    print(nlis[in1-1]-nlis[in0-1])
Buggy code:
N, Q = map(int, input().split())
S = input()
cumulative = [0] * (N+1)
for i in range(N):
  if S[i:i+2] == "AC":
    cumulative[i+2] = cumulative[i+1] + 1

for _ in range(Q):
  start, end = map(int, input().split())
  ans = cumulative[end] - cumulative[start-1]
  if start > 1 and S[start-2:start] == "AC":
    ans -= 1
  print(ans)

Fixed code:
N, Q = map(int, input().split())
S = input()
cumulative = [0] * (N+1)
for i in range(N-1):
  if S[i:i+2] == "AC":
    cumulative[i+2] = cumulative[i+1] + 1
  else:
    cumulative[i+2] = cumulative[i+1]
    
for _ in range(Q):
  start, end = map(int, input().split())
  ans = cumulative[end] - cumulative[start-1]
  if start > 1 and S[start-2:start] == "AC":
    ans -= 1
  print(ans)
Buggy code:
n,q=map(int,input().split())
S=input()
L=[0]
c=0
for i in range(n-1):
    if S[i:i+2]=='AC':
        c+=1    
    L.append(c)
print(L)
for j in range(q):
    s,e=map(int,input().split())
    print(L[e-1]-L[s-1])

Fixed code:
n,q=map(int,input().split())
S=input()
L=[0]
c=0
for i in range(n-1):
    if S[i:i+2]=='AC':
        c+=1    
    L.append(c)
for j in range(q):
    s,e=map(int,input().split())
    print(L[e-1]-L[s-1])
Buggy code:
nq = input().split()
n, q = int(nq[0]), int(nq[1])
s = list(input())
r_li = []
l_li = []
t_li = []
for i in range(q):
    rl = input().split()
    l_li.append(int(rl[0]))
    r_li.append(int(rl[1]))
count = 0
i = 0
while True:
    if i == n:
        break
    else:
        if s[i] == "A":
            if i i == n - 1:
                i += 1
                t_li.append(count)
            else:
                if s[i + 1] == "C":
                    t_li.append(count)
                    count += 1
                    t_li.append(count)
                    i += 2
                else:
                    t_li.append(count)
                    i += 1
        else:
            i += 1
            t_li.append(count)
for i in range(q):
    print(t_li[r_li[i] - 1] - t_li[l_li[i] - 1])


Fixed code:
nq = input().split()
n, q = int(nq[0]), int(nq[1])
s = list(input())
r_li = []
l_li = []
t_li = []
for i in range(q):
    rl = input().split()
    l_li.append(int(rl[0]))
    r_li.append(int(rl[1]))
count = 0
i = 0
while True:
    if i == n:
        break
    else:
        if s[i] == "A":
            if i == n - 1:
                i += 1
                t_li.append(count)
            else:
                if s[i + 1] == "C":
                    t_li.append(count)
                    count += 1
                    t_li.append(count)
                    i += 2
                else:
                    t_li.append(count)
                    i += 1
        else:
            i += 1
            t_li.append(count)
for i in range(q):
    print(t_li[r_li[i] - 1] - t_li[l_li[i] - 1])
Buggy code:
n,m=map(int,input().split())
s=input()
l=[0]
x,y=0,0
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":x+=1
    l.append(x)
l.append(x)
for i in range(m):
    a,b=map(int,input().split())
    print(l[b]-l[a-1])

Fixed code:
n,m=map(int,input().split())
s=input()
l=[0]
x,y=0,0
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":x+=1
    l.append(x)
l.append(x)
for i in range(m):
    a,b=map(int,input().split())
    print(l[b-1]-l[a-1])
Buggy code:
n, q = map(int, input().split())
s = input()
ac_list = [0]*len(s)

'''while True:
    ac_index = s[i:].find("AC")
    if ac_index == -1:
        break
    else:
        ac_list[ac_index+i] = 1
        i = ac_index + i + 2'''

for i in range(len(s)-1):
    if s[i:i+2] == 'AC':
        ac_list[i+1] = ac_list[i] + 1

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

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

'''while True:
    ac_index = s[i:].find("AC")
    if ac_index == -1:
        break
    else:
        ac_list[ac_index+i] = 1
        i = ac_index + i + 2'''

for i in range(len(s)-1):
    if s[i:i+2] == 'AC':
        ac_list[i+1] = ac_list[i] + 1
    else:
        ac_list[i+1] = ac_list[i]
# print(ac_list)
for _ in range(q):
    l, r = map(int, input().split())
    print(ac_list[r-1] - ac_list[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())
counter=[0]*N
for i in range(len(S)-1):
  if S[i]=="A":
    counter[i]+=counter[i-1]+(S[i+1]=="C")
  else:counter[i]=counter[i-1]
for j in range(Q):
  print(counter[r[j-1]]-counter[l[j-1]])

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())
counter=[0]*N
for i in range(N-1):
  if S[i]=="A":
    counter[i]=counter[i-1]+(S[i+1]=="C")
  else:counter[i]=counter[i-1]
for j in range(Q):
  print(counter[r[j]-2]-counter[l[j]-2])
Buggy code:
N, Q = list(map(int, input().strip().split()))
S = input()
rangeList = [list(map(int, input().strip().split())) for i in range(Q)]

Accumulation = [0]*N
flag = False

if (S[0] == "A"):
    flag = True

for i in range(1,N):
    if (flag):
        if (S[i] == "C"):
            Accumulation[i] = Accumulation[i-1] + 1
            continue
        else:
            flag = False
            Accumulation[i] = Accumulation[i-1]
            continue
    elif (S[i] == "A"):
        flag = True
    Accumulation[i] = Accumulation[i-1]

for eachRange in rangeList:
    print(Accumulation[eachRange[1]-1] - Accumulation[eachRange[0]-1])


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

Accumulation = [0]*N
flag = False

if (S[0] == "A"):
    flag = True

for i in range(1,N):
    if (flag):
        if (S[i] == "C"):
            Accumulation[i] = Accumulation[i-1] + 1
            flag = False
            continue
        elif (S[i] == "A"):
            Accumulation[i] = Accumulation[i-1]
            continue
        else:
            flag = False
            Accumulation[i] = Accumulation[i-1]
            continue
    elif (S[i] == "A"):
        flag = True
    Accumulation[i] = Accumulation[i-1]

for eachRange in rangeList:
    print(Accumulation[eachRange[1]-1] - Accumulation[eachRange[0]-1])
Buggy code:
n, q = map(int, input().split())
s = input()
lr = [0] * q

def inp(l: list) -> list:
    return [int(l[0]) - 1, int(l[1]) - 1]

for i in range(q):
    lr[i] = tuple(inp(input().split()))

count = [0]*n
for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        count[i] = count[i-1] + 1
    else:
        count[i] = count[i-1]

print(count)

for l, r in lr:
    print(count[r] - count[l])

    

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

def inp(l: list) -> list:
    return [int(l[0]) - 1, int(l[1]) - 1]

for i in range(q):
    lr[i] = tuple(inp(input().split()))

count = [0]*n
for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        count[i] = count[i-1] + 1
    else:
        count[i] = count[i-1]

# print(count)

for l, r in lr:
    print(count[r] - count[l])
Buggy code:
N, Q =map(int,input().split())
S =input()
LR = [list(map(int,input().split())) for i in range(Q)]
ACnum =[0]*(N+1)
Sofar = 0
for i in range(N-1):
    if S[i]=="A" and S[i+1]=="C":
        Sofar+=1
    ACnum[i+1] = Sofar
ACnum[N]=Sofar
print(ACnum)
for i in range(Q):
    print(ACnum[LR[i][1]-1]-ACnum[LR[i][0]-1])

Fixed code:
N, Q =map(int,input().split())
S =input()
LR = [list(map(int,input().split())) for i in range(Q)]
ACnum =[0]*(N+1)
Sofar = 0
for i in range(N-1):
    if S[i]=="A" and S[i+1]=="C":
        Sofar+=1
    ACnum[i+1] = Sofar
ACnum[N]=Sofar
#print(ACnum)
for i in range(Q):
    print(ACnum[LR[i][1]-1]-ACnum[LR[i][0]-1])
Buggy code:
N, Q = map(int, input().split())
S = input()
t = [0]*(N+1)
for i in range(N):
    print(S[i-1:i])
    t[i+1] = t[i] + 1 if S[i-1:i+1] == "AC" else t[i]

lr = []
for i in range(Q):
    tmp_lr = list(map(int, input().split()))
    lr.append(tmp_lr)

for l,r in lr:
    print(t[r]-t[l])


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-1:i+1] == "AC" else 0)

lr = []
for i in range(Q):
    tmp_lr = list(map(int, input().split()))
    lr.append(tmp_lr)

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

for i in range(1, N+1):
  t[i] = t[i-1] + (1 if S[i-1:i+1] == '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(1, N+1):
  t[i] = t[i-1] + (1 if S[i-1:i+1] == '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 = list(str(input()))

ans_list = []
fa = 0
ans = 0
for index, s in enumerate(S):
    if s == 'A' and fa == 0:
        fa = 1
        ans_list.append(ans)
    elif s == 'A' and fa == 1:
        ans_list.append(ans)
    elif s == 'C' and fa == 1:
        fa = 0
        ans += 1
        ans_list.append(ans)
    else:
        fa = 0
        ans_list.append(ans)
print(ans_list)
for _ in range(Q):
    l, r = map(int, input().split())
    print(ans_list[r-1] - ans_list[l-1])

Fixed code:
N, Q = map(int, input().split())
S = list(str(input()))

ans_list = []
fa = 0
ans = 0
for index, s in enumerate(S):
    if s == 'A' and fa == 0:
        fa = 1
        ans_list.append(ans)
    elif s == 'A' and fa == 1:
        ans_list.append(ans)
    elif s == 'C' and fa == 1:
        fa = 0
        ans += 1
        ans_list.append(ans)
    else:
        fa = 0
        ans_list.append(ans)
for _ in range(Q):
    l, r = map(int, input().split())
    print(ans_list[r-1] - ans_list[l-1])
Buggy code:
N, Q = map(int, input().split())
S = input()
wa = [0] * (N + 1)
flag = "X"
for i in range(N):
    if S[i] == "A":
        flag = "A"
        wa[i+1] = wa[i]
    elif flag == "A" and S[i] == "C":
        wa[i+1] = wa[i] + 1
        flag = "X"
    else:
        flag = "X"
        wa[i+1] = wa[i]

print(wa)
for q in range(Q):
    left,  right = map(int, input().split())
    print(wa[right] - wa[left])

Fixed code:
N, Q = map(int, input().split())
S = input()
wa = [0] * (N + 1)
flag = "X"
for i in range(N):
    if S[i] == "A":
        flag = "A"
        wa[i+1] = wa[i]
    elif flag == "A" and S[i] == "C":
        wa[i+1] = wa[i] + 1
        flag = "X"
    else:
        flag = "X"
        wa[i+1] = wa[i]
        
for q in range(Q):
    left,  right = map(int, input().split())
    print(wa[right] - wa[left])
Buggy code:
n, q = map(int, input().split())
s = input()
ac = [0] * (n + 1)
for i in [0] * n:
    ac[i + 1] = ac[i] + (1 if s[i:i + 2] == "AC" else 0)
for i in [0] * q:
    l, r = map(int, input().split())
    print(ac[r-1] - ac[l-1])

Fixed code:
n, q = map(int, input().split())
s = input()
ac = [0] * (n + 1)
for i in range(n):
    ac[i + 1] = ac[i] + (1 if s[i:i + 2] == "AC" else 0)
for i in [0] * q:
    l, r = map(int, input().split())
    print(ac[r-1] - ac[l-1])
Buggy code:
N,Q = map(int,input().split())
S = input()
questions = [[i for i in map(int,input().split())] for j in range(Q)]
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 q in questions:
  print(t[q[1]-1] - t[q[0]-1])

Fixed code:
N,Q = map(int,input().split())
S = input()
questions = [[i for i in map(int,input().split())] for j in range(Q)]
t = [0]*(N+1)
for i in range(N):
  t[i+1] = t[i] + (1 if S[i:i+2]=='AC' else 0)  

for q in questions:
  print(t[q[1]-1] - t[q[0]-1])
Buggy code:
N,Q = map(int,input().split())
S = input()
L = [list(map(int,input().split())) for i in range(Q)]

loc = [0 for i in range(N+1)]
for i in range(N) :
    if S[i:i+2] == "AC" :
        loc[i+1] = loc[i]+1
    else :
        loc[i+1] = loc[i]
for l,r in L :
    l -= 1
    r -= 1
    ans = loc[r] - loc[l]
    print(ans)
print(loc)

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

loc = [0 for i in range(N+1)]
for i in range(N) :
    if S[i:i+2] == "AC" :
        loc[i+1] = loc[i]+1
    else :
        loc[i+1] = loc[i]
for l,r in L :
    l -= 1
    r -= 1
    ans = loc[r] - loc[l]
    print(ans)
Buggy code:
import bisect
N,Q = map(int,input().split())
S = input()
lista = []
for j in range(N-1):
    if S[j:j+2] == 'AC':
        lista.append(j)
print(lista)
for i in range(Q):
    l,r = map(int,input().split())
    l,r = l-1,r-1
    lind = bisect.bisect_left(lista,l)
    rind = bisect.bisect_right(lista,r-1)
    print(rind-lind)

Fixed code:
import bisect
N,Q = map(int,input().split())
S = input()
lista = []
for j in range(N-1):
    if S[j:j+2] == 'AC':
        lista.append(j)
for i in range(Q):
    l,r = map(int,input().split())
    l,r = l-1,r-1
    lind = bisect.bisect_left(lista,l)
    rind = bisect.bisect_right(lista,r-1)
    print(rind-lind)
Buggy code:
n,q = map(int,input().split())
s = input()

li = [0]*(n)
ans = 0

for i in range(n-1):
    if s[i:i+2] == "AC":
        ans += 1
    li[i] = ans

for i in range(q):
    x,y = map(int,input().split())
    print(li[y-2] - li[x-2])
    
print(li)

Fixed code:
n,q = map(int,input().split())
s = input()

li = [0]*(n)
ans = 0

for i in range(n-1):
    if s[i:i+2] == "AC":
        ans += 1
    li[i+1] = ans

for i in range(q):
    x,y = map(int,input().split())
    print(li[y-1] - li[x-1])
Buggy code:
N, Q = map(int, input().split())
S = input()
x = [0 for i in range(N)]
T = ""
for i in range(len(S)):
    c = S[i]
    if c == 'A':
        A = True
    elif A and c == 'C':
        x[i] += 1
        A = False
    else:
        A = False
        T += c
s = [0 for i in range(N+1)]
for i in range(N):
    s[i+1] = s[i]+x[i]
print(s)
for i in range(Q):
    l, r = map(int, input().split())
    l -= 1
    if s[l] != s[l+1]:
        print(s[r]-s[l]-1)
    else:
        print(s[r]-s[l])


Fixed code:
N, Q = map(int, input().split())
S = input()
x = [0 for i in range(N)]
A = False
for i in range(len(S)):
    c = S[i]
    if c == 'A':
        A = True
    elif A and c == 'C':
        x[i] += 1
        A = False
    else:
        A = False
s = [0 for i in range(N+1)]
for i in range(N):
    s[i+1] = s[i]+x[i]
for i in range(Q):
    l, r = map(int, input().split())
    l -= 1
    if s[l] != s[l+1]:
        print(s[r]-s[l]-1)
    else:
        print(s[r]-s[l])
Buggy code:
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(n,q,s,l):
    lst_ac = [0]*(len(s))
    for i in range(len(s)-1):
        if s[i]+s[i+1] == "AC":
            lst_ac[i+1] = lst_ac[i]+1
        else:
            lst_ac[i+1] = lst_ac[i]
    print(lst_ac)
    for item in l:
        print(lst_ac[item[1]-1] - lst_ac[item[0]-1])

def resolve():
    n,q = mi()
    s = input()
    l = mix(q)
    main(n,q,s,l)

if __name__ == "__main__":
    resolve()

Fixed code:
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(n,q,s,l):
    lst_ac = [0]*(len(s))
    for i in range(len(s)-1):
        if s[i]+s[i+1] == "AC":
            lst_ac[i+1] = lst_ac[i]+1
        else:
            lst_ac[i+1] = lst_ac[i]
    for item in l:
        print(lst_ac[item[1]-1] - lst_ac[item[0]-1])

def resolve():
    n,q = mi()
    s = input()
    l = mix(q)
    main(n,q,s,l)

if __name__ == "__main__":
    resolve()
Buggy code:
n, q = map(int, input().split())
s = input()
ac = [0]
for i in range(len(s)):
  if s[i] == 'A' and s[i] == 'C':
    ac.append(ac[i]+1)
  else:
    ac.append(ac[i])
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()
ac = [0]
for i in range(len(s)-1):
  if s[i] == 'A' and s[i+1] == 'C':
    ac.append(ac[i]+1)
  else:
    ac.append(ac[i])
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())
a=input()

list=[0]*N

for i in range(N):
    list[i+1]=list[i]+1 if a[i:i+2]=="AC" else list[i]
    
for i in range(N):
    l,r = map(int, input().split())
    print(list[r-1]-list[l-1])
    

Fixed code:
N, Q = map(int, input().split())
a=input()

list=[0]*(N+1)

for i in range(N):
    list[i+1]=list[i]+1 if a[i:i+2]=="AC" else list[i]
    
for i in range(Q):
    l,r = map(int, input().split())
    print(list[r-1]-list[l-1])
Buggy code:
N,Q=map(int,input().split())
S=input()
l=0
r=0

s=[]
s.append(0)

for i in range(1,N):
    if(S[i-1]=='A' and S[i]=='C'):
        print(i)
        s.append(s[i-1]+1)
        print(s)
    else:
        s.append(s[i-1])
print(s)
for i in range(Q):

    l,r=map(int,input().split())

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




'''
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())

s=[0 for i in range(N+1)]
s[0]=0

for i in range(1,N+1):
    s[i]=S[0:i].count('AC')

for i in range(Q):
    print(s[r[i]]-s[l[i]])
'''


Fixed code:
N,Q=map(int,input().split())
S=input()
l=0
r=0

s=[]
s.append(0)

for i in range(1,N):
    if(S[i-1]=='A' and S[i]=='C'):

        s.append(s[i-1]+1)

    else:
        s.append(s[i-1])

for i in range(Q):

    l,r=map(int,input().split())

    print(s[r-1]-s[l-1])
Buggy code:
n, q = map(int, input().split())
s = str(input())
l = [-1] * q
r = [-1] * q
for i in range(q):
    l[i], r[i] = map(int, input().split())
sum = [0] * (n+1)
flag_a = False
for i in range(1, n+1):
    if s[i-1] == 'A':
        flag_a = True
        sum[i] = sum[i-1]
    elif s[i-1] == 'C' and flag_a:
        flag_a = False
        sum[i] = sum[i-1] + 1
    else:
        flag_a = False
        sum[i] = sum[i-1]
print(sum)
for i in range(q):
    print(sum[r[i]] - sum[l[i]])


Fixed code:
n, q = map(int, input().split())
s = str(input())
l = [-1] * q
r = [-1] * q
for i in range(q):
    l[i], r[i] = map(int, input().split())
sum = [0] * (n+1)
flag_a = False
for i in range(1, n+1):
    if s[i-1] == 'A':
        flag_a = True
        sum[i] = sum[i-1]
    elif s[i-1] == 'C' and flag_a:
        flag_a = False
        sum[i] = sum[i-1] + 1
    else:
        flag_a = False
        sum[i] = sum[i-1]
for i in range(q):
    print(sum[r[i]] - sum[l[i]])
Buggy code:
N, Q = map(int, input().split())
S = list(input())

mark = [0]*(N+1)

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

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

Fixed code:
N, Q = map(int, input().split())
S = list(input())

mark = [0]*(N+1)

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

for i in range(Q):
    l,r = map(int,input().split())
    l = l - 1
    r = r - 1
    print(mark[r+1]-mark[l+1])
Buggy code:
n, q = map(int, input().split())
S = input()

counts = [0 for i in range(N)]
cnt = 0

for i in range(n):
  if S[i-1:i+1] == "AC":
    cnt += 1
    counts[i] = cnt
    
for i in range(q):
  l, r = map(int, input().split())
  print (counts[r-1] - counts[l-1])

Fixed code:
n, q = map(int, input().split())
S = input()
 
counts = [0 for i in range(n)]
cnt = 0
 
for i in range(n):
  if S[i-1:i+1] == "AC":
    cnt += 1
  counts[i] = cnt
    
for i in range(q):
    l, r = map(int, input().split())
    print(counts[r-1] - counts[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 = map(int, input().split())
s = input()
b = [0] * n
cnt = 0
for i in range(n-1):
	if s[i:i+2] == "AC":
		cnt += 1
	b[i+1] = cnt
print (b)
for i in range(q):
	l, r = map(int, input().split())
	a = b[r-1] - b[l-1]
	print (a)

Fixed code:
n, q = map(int, input().split())
s = input()
b = [0] * n
cnt = 0
for i in range(n-1):
	if s[i:i+2] == "AC":
		cnt += 1
	b[i+1] = cnt
for i in range(q):
	l, r = map(int, input().split())
	a = b[r-1] - b[l-1]
	print (a)
Buggy code:
N,Q=map(int,input().split())
S=input()
a=[0]
for i in range(1,N):
    if S[i-1]+S[i]=='AC':
        a.append(1)
    else:
        a.append(0)
print(a)
b=[]
sum=0
b.append(sum)
for x in a:
    sum+=x
    b.append(sum)
print(b)
for i in range(Q):
    l,r=map(int,input().split())
    print(b[r]-b[l])

Fixed code:
N,Q=map(int,input().split())
S=input()
a=[0]
for i in range(1,N):
    if S[i-1]+S[i]=='AC':
        a.append(1)
    else:
        a.append(0)
#print(a)
b=[]
sum=0
b.append(sum)
for x in a:
    sum+=x
    b.append(sum)
#print(b)
for i in range(Q):
    l,r=map(int,input().split())
    print(b[r]-b[l])