Problem:
 Score : 300 points    Problem Statement You are given a string S of length N consisting of A , C , G and T . Answer the following Q queries:   Query i ( 1 \leq i \leq Q ): You will be given integers l_i and r_i ( 1 \leq l_i < r_i \leq N ). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does AC occurs as a substring?       Notes A substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T .  For example, the substrings of ATCODER include TCO , AT , CODER , ATCODER and (the empty string), but not AC .      Constraints  2 \leq N \leq 10^5  1 \leq Q \leq 10^5  S is a string of length N .  Each character in S is A , C , G or T .  1 \leq l_i < r_i \leq N         Input Input is given from Standard Input in the following format:  N  Q  S  l_1  r_1  :  l_Q  r_Q       Output Print Q lines. The i -th line should contain the answer to the i -th query.        Sample Input 1 8 3
ACACTACG
3 7
2 3
1 8      Sample Output 1 2
0
3   Query 1 : the substring of S starting at index 3 and ending at index 7 is ACTAC . In this string, AC occurs twice as a substring.  Query 2 : the substring of S starting at index 2 and ending at index 3 is CA . In this string, AC occurs zero times as a substring.  Query 3 : the substring of S starting at index 1 and ending at index 8 is ACACTACG . In this string, AC occurs three times as a substring.

Solution (Python):
import sys
from itertools import accumulate

readline = sys.stdin.readline
n, q = map(int, readline().split())
s = readline().rstrip()
ac = [False] * (n - 1)
for i, x in enumerate(zip(s, s[1:])):
    if x == ('A', 'C'):
        ac[i] = True
ac = [0] + list(accumulate(ac))
for _ in range(q):
    l, r = map(int, readline().split())
    print(ac[r-1] - ac[l-1])

Solution (Python):
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())

cs = [0]*(N+1)
for i in range(N-1):
    if(S[i] == 'A' and S[i+1] == 'C'):
        cs[i+2] = cs[i+1] + 1
    else:
        cs[i+2] = cs[i+1]
for q in range(Q):
    print(cs[r[q]] - cs[l[q]])

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    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())

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

    for q in range(Q):
        print(cs[r[q]]-cs[l[q]])

if __name__ == '__main__':
    resolve()

Solution (Python):
N,Q=map(int,input().split())
S=input()
query=[list(map(int,input().split())) for _ in range(Q)]
table=[0 for _ in range(N)]
num=0
for i in range(N-1):
    if (S[i]=="A")and(S[i+1]=="C"):
        num=num+1
    table[i+1]=num
for i in range(Q):
    print(table[query[i][1]-1]-table[query[i][0]-1])

Solution (Python):
def main():
    n, q = [int(e) for e in input().split()]
    s = input()
    LR = [[int(e) for e in input().split()] for i in range(q)]

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

        CNT.append(cnt)

    CNT.append(0)
    for lr in LR:
        print(CNT[lr[1] - 2] - CNT[lr[0] - 2])

if __name__ == "__main__":
    main()

Solution (Python):

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

AC=[0]
tmp=0
for i in range(N-1):
  if S[i:i+2]=="AC":
    tmp=tmp+1
  AC.append(tmp)

for i in range(Q):
  print(AC[lr[i][1]-1]-AC[lr[i][0]-1])

Solution (Python):
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n,q = map(int, input().split())
    s = input()
    cumsum = list()

    for i in  range(n+1):
        if i == 0:
            cumsum.append(0)
        else:
            if i > 1 and  s[i-2:i] == 'AC':
                
                cumsum.append(cumsum[i-1] + 1)
            else:
                cumsum.append(cumsum[i-1])
    
    for i in range(q):
        l,r = map(int, input().split())
        print(cumsum[r] - cumsum[l])
    
    return

if __name__ == '__main__':
    main()

Solution (Python):
n,q = map(int,input().split())
s = input() + '0'
lr = [list(map(int,input().split())) for _ in range(q)]
cnt = [0] * (n+1)

for i in range(n):
  if s[i] == 'A' and s[i+1] == 'C':
    cnt[i+1] = cnt[i] + 1
  else:
    cnt[i+1] = cnt[i]
for i in lr:
  print(cnt[i[1]-1] - cnt[i[0]-1])

Solution (Python):
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])

Solution (Python):
N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[l-1])

Solution (Python):
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])

Solution (Python):
N, Q = map(int, input().split())
S=input()
lr=[]
for _ in range(Q):
    lr.append(tuple(map(int, input().split())))


accum=[0]*(N+1)
should_plus=0
for i in range(2, N+1):
    if S[i-2]=='A' and S[i-1]=='C':
        should_plus+=1
    accum[i]=should_plus


for val in lr:
    left=val[0]
    right=val[1]
    OK=accum[right]-accum[left-1]
    if S[(left-2):left]=='AC':
        OK-=1
    print(OK)

Solution (Python):
import re
N, Q = map(int, input().split())
S=input()
lr=[]
for _ in range(Q):
    lr.append(tuple(map(int, input().split())))




accum=[0]*(N+1)
should_plus=0
for i in range(2, N+1):
    if S[i-2]=='A' and S[i-1]=='C':
        should_plus+=1
    accum[i]=should_plus


for val in lr:
    OK=accum[val[1]]-accum[val[0]-1]
    if S[(val[0]-2):val[0]]=='AC':
        OK-=1
    print(OK)

Solution (Python):
import math
import collections
from operator import mul
from functools import reduce



n,q=map(int,input().split())
s=input()
y=[0]*(n+1)
flag=0
for i in range(n):
    if flag==0:
        if s[i]=="A":flag=1
    else:
        if s[i]=="C":
            y[i+1]+=1
            flag=0
        elif s[i]!="A":
            flag=0

    y[i+1]+=y[i]

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

Solution (Python):
N,Q = map(int,input().split())
S = input()

csum = [0,0]
for i in range(1, N):
    if S[i-1] + S[i] == 'AC':
        csum.append(csum[i-1] + 1)
    else:
        csum.append(csum[i])
        

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

Solution (Python):
n, q = map(int, input().split())
s = input()

csum = [0, 0]
for i in range(1, n):
    if s[i-1]+s[i] == 'AC':
        csum.append(csum[i-1]+1)
    else:
        csum.append(csum[i])

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

Solution (Python):

from itertools import accumulate
def main():
    n,q = map(int, input().split())
    s = input()
    l = [list(map(int,input().split())) for _ in range(q)]

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

if __name__ == '__main__' :
    main()

Solution (Python):
n,q = map(int,input().split())
s = input()
cnt = [0]*(n+1)
p = s[0]
for i in range(1,n+1):
    if p == "A" and s[i-1] == "C":
            cnt[i] = cnt[i-1] +1
    else:
        cnt[i] = cnt[i-1]
    p = s[i-1]

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

Solution (Python):
import bisect

N, Q = [int(x) for x in input().split()]
S = input()
lr = []
for i in range(Q):
    lr.append([int(x)-1 for x in input().split()])

aclist = []
target = "AC"
index = -1
while True:
    index = S.find(target, index + 1)
    if index == -1:
        break
    aclist.append(index)

for [l, r] in lr:
    min_ac = bisect.bisect_left(aclist, l)
    max_ac = bisect.bisect_right(aclist, r-1)
    print(max_ac - min_ac)

Solution (Python):
from itertools import accumulate
n, q = map(int, input().split())
s = input()
*a, = accumulate([0,0]+[s[i-1:i+1]=="AC"for i in range(1,n)])
for i in range(q):
    l, r = map(int, input().split())
    print(a[r] - a[l])

Solution (Python):
n, q = map(int, input().split())
s = input()
lis = [0]
cnt = 0
for i in range(1, n):
    if s[i-1:i+1] == "AC":
        cnt += 1
        lis.append(cnt)
    else:
        lis.append(cnt)
for i in range(q):
    l, r = map(int, input().split())
    print(lis[r-1] - lis[l-1])

Solution (Python):
n,q = map(int,input().split())
s = input()
cnt = [0] * (n+1)
for i in range(n):
    if s[i:i+2] == "AC":
        cnt[i+1] = cnt[i] + 1
    else:
        cnt[i+1] = cnt[i]
for i in range(q):
    l,r = map(int,input().split())
    print(cnt[r-1]-cnt[l-1])

Solution (Python):
N, Q = map(int, input().split())
S = " " + input()
lr = [list(map(int, input().split())) for _ in range(Q)]
ans = [0 for _ in range(N+10)]

for i in range(1, N+1):
    if S[i-1:i+1] == "AC":
        ans[i] += 1
    ans[i] += ans[i-1]

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

Solution (Python):
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

N, Q = map(int, input().split())
S = input()


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

Solution (Python):
n, q = map(int, input().split())
s = list(input())
ls = len(s)
for i in range(0, ls):
    if (s[i] == "A"):
        if (i != ls-1)and(s[i + 1] == "C"):
            s[i] = "a"

anum = [0]
for i in range(1, ls):
    if (s[i - 1] == "a"):
        anum.append(anum[i - 1] + 1)
    else:
        anum.append(anum[i - 1])

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

Solution (Python):
N, Q = map(int, input().split())
s = input()

A = [0] * N

prev = s[0]
for i, v in enumerate(s):
    if prev == 'A' and v == 'C':
        A[i] = A[i-1] + 1
    else:
        A[i] = A[i-1]
    prev = v

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

Solution (Python):
import numpy as np
n, q = map(int, input().split())
s = input()
lr = []
for i in range(q):
        l,r = map(int, input().split())
        lr.append([l,r])

n = len(s)
L = 0
R = 1
cntAC = [0] * n

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


cSum = np.cumsum(cntAC)


for _lr in lr:
    if _lr[L] == 1:
        print(cSum[_lr[R]-2])
    else:
        print(cSum[_lr[R]-2] - cSum[_lr[L]-2])
        

"""
ACACTACG
"""

Solution (Python):
n,q = map(int,input().split())
s = input()
li = [0]
t = 0
for i in range(len(s)-1):
  if s[i] == "A" and s[i+1] == "C":
    t += 1
  li.append(t)
for k in range(q):
  l,r = map(int,input().split())
  print(li[r-1] - li[l-1])

Solution (Python):
N, Q = map(int, input().split())
S = input()
d = [0, 0]
for i in range(N - 1):
    if S[i] + S[i + 1] == "AC":
        d.append(d[-1] + 1)
    else:
         d.append(d[-1])

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

Solution (Python):
N, Q = map(int, input().split())
S = input()
L = len(S)
ACnum = [0] * L
for i in range(1, L):
    ACnum[i] += ACnum[i - 1]
    if S[i - 1] == "A" and S[i] == "C":
        ACnum[i] += 1

lr = [None] * Q
for _ in range(Q):
    lr[_] = list(map(int, input().split()))

for i in range(Q):
    ans = ACnum[lr[i][1] - 1] - ACnum[lr[i][0] - 1]
    print(ans)

Solution (Python):
n, q = map(int, input().split())
s = input()

ac_counts = [0 for _ in range(n + 1)]

for i in range(n):
    ac_counts[i + 1] = ac_counts[i] + (1 if s[i: i + 2] == 'AC' else 0)

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

Solution (Python):
n, q = map(int, input().split())
s = input()

a = [0, 0]
for i in range(2, n + 1):
    a.append(a[i - 1] + (s[i - 2:i] == 'AC'))


for _ in range(q):
    li, ri = map(int, input().split())
    print(a[ri] - a[li])

Solution (Python):
n, q = map(int, input().split())
s = input()
a = [0 for i in range(n)]
ct = 0
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        ct += 1
    a[i] = ct

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

Solution (Python):
N, Q = list(map(int, input().split()))
S = input()

flags = [0] * N
for i in range(N):
    if i != 0 and S[i - 1:i + 1] == 'AC':
        flags[i] = 1

acc_sum = [0] * N
for i in range(1, N):
    if flags[i] == 1:
        acc_sum[i] = acc_sum[i - 1] + 1
    else:
        acc_sum[i] = acc_sum[i - 1]

for i in range(Q):
    l, r = list(map(int, input().split()))
    if l == r:
        print(0)
    else:
        print(acc_sum[r - 1] - acc_sum[l - 1])

Solution (Python):
import sys
import bisect
input = sys.stdin.readline
n,q = map(int,input().split())
s = list(input())
lr = [list(map(int,input().split())) for _ in range(q)]
ac = []
for i in range(n-1):
  if s[i] == "A" and s[i+1] == "C":
    ac.append(i)
for i in range(q):
  print(bisect.bisect_left(ac,lr[i][1]-1)-bisect.bisect_left(ac,lr[i][0]-1))

Solution (Python):
n,q=map(int,input().split())
s=input()+'Z'
A=[0]*(n+1)
cnt=0
for i in range(n):
    A[i]=cnt
    if s[i]=='A' and s[i+1]=='C':
        cnt+=1
ANS=[]
for i in range(q):
    l,r=map(int,input().split())
    ANS.append(A[r-1]-A[l-1])
for ans in ANS:
    print(ans)

Solution (Python):
n,q=map(int,input().split())
s=input()
count=[0]*n
for i in range(1,n):
    count[i]+=count[i-1]
    if s[i-1:i+1]=="AC":count[i]+=1
for i in range(q):
    l,r=map(int,input().split())
    print(count[r-1]-count[l-1])

Solution (Python):
import bisect

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

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

for i in range(Q):
    a,b = map(int,(input().split()))
    print(bisect.bisect_left(l,b) - bisect.bisect_left(l,a))

Solution (Python):
n,m=map(int,input().split()) 
q=input() 
l=[list(map(int,input().split())) for _ in range(m)] 
ans=0 
lst_j=[0]*(n+1) 
for i in range(n-1): 
	cnt=0 
	if q[i]+q[i+1]=="AC": 
		cnt=1 
		lst_j[i+1]=cnt+lst_j[i] 
	else:lst_j[i+1]=lst_j[i] 
for i,j in l: 
	ans=lst_j[j-1]-lst_j[i-1] 
	print(ans)

Solution (Python):
N,Q=map(int,input().split())
S=input()
L=[0]*len(S)
for i in range(len(S)-1):
  if S[i]=='A':
    if S[i+1]=='C':
      L[i+1]=1
for i in range(1,len(S)):
  L[i]=L[i-1]+L[i]
for i in range(Q):
  l,r=map(int,input().split())
  l-=1
  r-=1
  ans=L[r]-L[l]
  print(ans)

Solution (Python):





from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product





def resolve():
    N,Q=map(int,input().split())
    S=str(input())

    L, R = [0] * Q, [0] * Q
    for i in range(Q):
        L[i], R[i] = map(int, input().split())
        L[i], R[i] = L[i]-1, R[i]-1

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

    B = [0] + A
    B = list(accumulate(B))  

    
    for j in range(Q):
        ans=B[R[j]]-B[L[j]]
        print(ans)



resolve()

Solution (Python):
n, q = map(int, input().split())
s = list(str(input()))


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


t[-1] = t[-2]


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

Solution (Python):
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])

Solution (Python):
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])

Solution (Python):
N, Q = map(int, input().split())
S = list(input())
cnt = [0] * (N)

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

for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)

Solution (Python):


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

AC_cumsum = list()
AC_cumsum.append(0)

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

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

Solution (Python):
n, q = map(int, input().split())
s = str(input())
lr = [list(map(int, input().split())) for _ in range(q)]

cnt = 0
res = [0 for _ in range(len(s))]
for i in range(1, len(s)):
    if s[i - 1] == "A" and s[i] == "C":
        cnt += 1
    res[i] = cnt

for i in range(q):
    l, r = lr[i][0], lr[i][1]
    print(res[r - 1] - res[l - 1])

Solution (Python):
n, q = map(int, input().split())
s = input()
t = [0] * n
for i in range(1, n):
    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])

Solution (Python):
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])

Solution (Python):
N, Q = map(int, input().split())
S = input()
count_AC = [0]
tmp = 0
for i in range(1, len(S)):
    if S[i - 1] + S[i] == 'AC':
        tmp += 1
    count_AC.append(tmp)
for i in range(Q):
    l, r = map(int, input().split())
    print(count_AC[r-1] - count_AC[l-1])

Solution (Python):
N, Q=map(int, input().split())
S=list(input())
L=[0]*(N)
s=[0]*(N+1)
for i in range(1,N):
  if S[i-1]=="A" and S[i]=="C":
    L[i]=1
    
for i in range(N):
  s[i+1]=s[i]+L[i]
for i in range(Q):
  l,r=map(int, input().split())
  print(s[r]-s[l])

Solution (Python):
n,q = map(int,input().split())
s = "p" + str(input())
lr = [list(map(int,input().split())) for i in range(q)]
cnt = 0
ans = [0] * (n+1)
for i in range(1,n+1):
    if s[i-1] == "A" and s[i] == "C":
        cnt += 1
    ans[i] = cnt
for i in lr:
    print(ans[i[1]] - ans[i[0]])

Solution (Python):
N, Q = map(int, input().split())
S = input()
AC = [0] * (N)
for i in range(1, N):
    if S[i] == "C" and S[i - 1] == "A":
        AC[i] = AC[i - 1] + 1
    else:
        AC[i] = AC[i-1]
for _ in range(Q):
    l,r = map(int,input().split())
    l-=1
    r-=1
    print(AC[r]-AC[l])

Solution (Python):
import sys
input = sys.stdin.readline


import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random



from bisect import bisect_left, bisect_right, insort_left, insort_right







'''
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  
def grid(n): return [s_list() for _ in range(n)]

def dfs(G, v):
    global time, first_order,seen,last_order
    time += 1
    first_order[v-1] = time   

    seen[v-1] = True 
    
    for next_v in G[v]:
        if seen[next_v-1]:
            continue
        dfs(G, next_v)

    time += 1
    last_order[v - 1] = time  
'''

def main():

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

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

    for task_n in task:
        print(count[task_n[1]] - count[task_n[0]])

if __name__ == '__main__':
    main()

Solution (Python):
n, q = map(int, input().split())
s = input()
list_s = list(s)
list_score = [ list(map(int,input().split(" "))) for i in range(q)]
list_c = [0]
a = 0
for i in range(n-1):
    if list_s[i] == "A" and list_s[i+1] == "C":
        a += 1
        list_c.append(a)
    else:
        list_c.append(a)

for i in range(q):
    g = list_score[i]
    print(list_c[g[1]-1]-list_c[g[0]-1])

Solution (Python):
n,q = map(int,input().split())
s = input()
li = [0]*n
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        li[i+1] = li[i] + 1
    else:
        li[i+1] = li[i]
for i in range(q):
    l,r = map(int,input().split())
    print(li[r-1]-li[l-1])

Solution (Python):
n,q = map(int,input().split())

s = input()
t = [0] * (n+1)
p = []
for i in range(n):
	t[i+1] = t[i] + (1 if s[i:i+2] =='AC' else 0)

for _ in range(q):
	l,r= map(int,input().split())
	p.append(t[r-1]-t[l-1])

for i in p:
	print(i)

Solution (Python):
N, Q=map(int, input().split())
S=list(input())
L=[0]*(N)
s=[0]*(N+1)
for i in range(1,N):
  if S[i-1]=="A" and S[i]=="C":
    L[i]=1
    
for i in range(N):
  s[i+1]=s[i]+L[i]
for i in range(Q):
  l,r=map(int, input().split())
  print(s[r]-s[l])

Solution (Python):
N, Q = map(int, input().split())
S = input()
count = [0]*N  
for i in range(1, N):
    count[i] = count[i-1]
    if S[i-1: i+1] == "AC":
        count[i] += 1
for _ in range(Q):
    l,r = map(int, input().split())
    print(count[r-1] - count[l-1])

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, q = MAP()
s = STR()
arr = [1 if s[i] + s[i + 1] == 'AC' else 0 for i in range(n - 1)]
arr2 = [[0, False] for _ in range(n - 1)]
arr2[0] = [arr[0], True if arr[0] == 1 else False]
for i in range(1, n - 1):
    arr2[i][0] = arr2[i - 1][0] + arr[i]
    arr2[i][1] = True if arr[i] == 1 else False
for _ in range(q):
    l, r = MAP()
    print(arr2[r - 2][0] - arr2[l - 1][0] + arr2[l - 1][1])

Solution (Python):
N, Q = map(int, input().split())
S = input()
T = [0]*(N+1)

for i in range(1, N):
    T[i+1] = T[i] + (1 if S[i-1:i+1]=='AC' else 0)
ans = []
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(T[r] - T[l])
print(*ans, sep='\n')

Solution (Python):
from itertools import accumulate
n, q = map(int, input().split())
s = input()
A =[1 if s[i]+s[i+1] == 'AC' else 0 for i in range(n-1)]

S = [0] + list(accumulate(A))

Q = []
Q_append = Q.append
for _ in range(q):
    l, r = map(int, input().split())
    Q_append((l-1, r-1))

for qi in Q:
    print(S[qi[1]]-S[qi[0]])

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    N,Q=map(int,readline().split())
    S=readline().strip()
    l=[0]*Q
    r=[0]*Q
    for i in range(Q):
        l[i],r[i]=map(lambda x:int(x)-1,readline().split())

    sum_ac=[0]*N
    for i in range(N):
        if i==0:
            sum_ac[i]=0
        else:
            if S[i-1]=="A" and S[i]=="C":
                sum_ac[i]=sum_ac[i-1]+1
            else:
                sum_ac[i]=sum_ac[i-1]

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

if __name__=="__main__":
    main()

Solution (Python):
n,q = map(int,input().split())
s = input()
ans = []
li = [0] * (len(s))
count = 0

for i in range(1,len(s)):
    if s[i] == 'C' and s[i-1] == 'A':
        count += 1
    li[i] = count

for i in range(q):
    l,r = map(int,input().split())
    tmp = li[r-1] - li[l-1]
    ans.append(tmp)

for aa in ans:
    print(aa)

Solution (Python):
import sys
N, Q = map(int, sys.stdin.readline().rstrip().split(" "))

S = sys.stdin.readline().rstrip()

cs = [0] * (N+1)

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

for _ in range(Q):
    l, r = map(int, sys.stdin.readline().rstrip().split())
    print(cs[r] - cs[l])

Solution (Python):




def main():
    N, Q = map(int, input().split())
    S = input()

    ac_count = [0]
    ac = 0
    for i in range(1, N):
        if S[i - 1:i + 1] == "AC":
            ac += 1
        ac_count.append(ac)

    result = []

    for _ in range(Q):
        left, right = map(int, input().split())
        result.append(ac_count[right - 1] - ac_count[left - 1])

    print(*result, sep="\n")


if __name__ == "__main__":
    main()

Solution (Python):
N,Q = map(int,input().split())
S = list(input())
ac = [0 for i in range(N)]
for i in range(1,N):
    ac[i] = ac[i-1]
    if S[i-1] == "A" and S[i] == "C": ac[i] += 1

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

for i in range(Q):
    l,r = quest[i]
    print(ac[r-1]-ac[l-1])

Solution (Python):

import bisect


def read_input():
    n, q = map(int, input().split())
    s = list(input().strip())
    queries = []
    for _ in range(q):
        st, ed = map(int, input().split())
        queries.append((st - 1, ed - 1))

    return n, s, queries


def submit():
    n, s, queries = read_input()

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

    for ql, qr in queries:
        print(bisect.bisect_right(ac_st, qr - 1) -\
              bisect.bisect_left(ac_st, ql))


if __name__ == "__main__":
    submit()

Solution (Python):
N,Q = map(int,input().split())
S = list(input())

cnt = [0] * N
for i in range(1,N):
    cnt[i] = cnt[i-1]
    if S[i-1] == "A" and S[i] == "C":
        cnt[i] += 1

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

Solution (Python):
n,q=map(int,input().split())
l=[0 for i in range(n)]
for i,v in enumerate(list(input().replace("AC","X!"))):
    l[i]=l[i-1]+(v=="!")
for c in range(q):
    h,m=map(int,input().split())
    print(l[m-1]-l[h-1])

Solution (Python):

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

data[n - 1] = cnt

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

    ans[i] = data[r - 1] - data[l - 1]

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

Solution (Python):
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]



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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, Q = MAP()
S = input()
L = [LIST() for i in range(Q)]
ruiseki = [0] * (N)

for i in range(N-1):
    if S[i+1] == "C" and S[i] == "A":
        
            ruiseki[i+1] += ruiseki[i] + 1
    else:
        ruiseki[i+1] = ruiseki[i]
for l, r in L:
    ans = ruiseki[r-1] - ruiseki[l-1]
    print(ans)

Solution (Python):
n, q = map(int, input().split())
s = input()
















hoge = [0]
cnt = 0
for i in range(1, n):
    if s[i - 1] + s[i] == 'AC':
        cnt += 1
    hoge.append(cnt)

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

Solution (Python):
n, q = map(int, input().split())
s = input()
lr = [tuple(map(int, input().split())) for _ in range(q)]


table = [None] * (n+1)
table[0] = 0
table[1] = 0
for i in range(2, n+1):
    if s[i-2:i] == 'AC':
        table[i] = table[i-1] + 1
    else:
        table[i] = table[i-1]

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians

from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, Q = MAP()
    S = INPUT()

    lis = [0]
    for i in range(N-1):
        lis.append(lis[i] + int(S[i:i+2] == "AC"))

    for _ in range(Q):
        l, r = MAP()
        print(lis[r-1] - lis[l-1])


if __name__ == '__main__':
        main()

Solution (Python):
N, Q = map(int, input().split())
S = input()

cnt = [0] * N
for i in range(1, N):
    if S[i-1:i+1] == "AC":
        cnt[i] = cnt[i-1] + 1
    else:
        cnt[i] = cnt[i-1]

for _ in range(Q):
    L, R = map(int, input().split())
    ans = cnt[R-1] - (cnt[L-2] if L >= 2 else 0)
    if L >= 2 and cnt[L-1] != cnt[L-2]:
        ans -= 1
    print(ans)

Solution (Python):
n,q = map(int,input().split())
s = input()

geta = []
acam = [0]*n
c = 0

for i in range(1,n):
    if s[i-1] == 'A' and s[i] == 'C':
        c += 1
        geta.append(i-1)
    acam[i] = c
    
for i in range(q):
    l , r = map(int,input().split())
    l -= 1
    r -= 1
    print(acam[r] - acam[l])