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):
n,q = (int(num) for num in input().split())
s = input()
list_ac = [0]*n
list_sum = [0]*n
for i in range(n-1):
    if s[i:i+2] == 'AC':
        list_ac[i] = 1
for i in range(1,n):
    list_sum[i] = list_sum[i-1] + list_ac[i-1]
    
for j in range(q):
    l,r = (int(num)-1 for num in input().split())
    print(list_sum[r]-list_sum[l])

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

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

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

    res = [None]*q

    for i in range(q):

        l, r = map(int, input().split())
        res[i] = cumsum[r-1] - cumsum[l-1]

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


main()

Solution (Python):

N,Q=map(int, input().split())
s = input();
charList=list(s);
AClist=[0]*N;

for i in range(N-1):
 if charList[i]=='A' and charList[i+1]=='C':
  AClist[i+1]=AClist[i]+1;
 else:
  AClist[i+1]=AClist[i];

result=[0]*Q;
for i in range(Q):
 l, r = map(int, input().split())
 result[i]=AClist[r-1]-AClist[l-1];
 if result[i]<0:
  result[i]=0;
for i in range(Q):
 print(result[i]);

Solution (Python):
from itertools import accumulate

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

t = [0] * N

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

T = list(accumulate(t))

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())
cum = [0 for i in range(n+1)]
i = 0
while i < n:
    if i < n-1 and s[i] == "A" and s[i+1] == "C":
        cum[i+1] = cum[i]
        cum[i+2] = 1+cum[i+1]
        i += 2
    else:
        cum[i+1] = cum[i]
        i += 1

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

Solution (Python):
n,q = map(int,input().split())
S = input()
d = [0] * n
counter = 1
for i in range(n - 1):
    d[i] = counter
    if S[i]+S[i + 1] == 'AC':
            d[i+1] = counter
            counter += 1
d[len(S)-1] = counter
for i in range(q):
    r,l = map(int,input().split())
    print(d[l-1]-d[r-1])

Solution (Python):
import sys
from itertools import accumulate
 
N, Q = map(int, input().split())
S = input()
 
t = [0] * N
 
for i in range(1, N):
    s = S[i-1:i+1]
    if s == 'AC':
        t[i] += 1

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

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


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

for i,j in lr:
    print(count[j-1]-count[i-1])

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


count=[0]

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

for i,j in lr:
    print(count[j-1]-count[i-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):
import bisect


def solve(memo, left, right):
    left_key = bisect.bisect_left(memo, left)
    right_key = bisect.bisect_right(memo, right)
    return right_key - left_key


def main():
    length, questions = map(int, input().split())
    string = input()

    memo = []
    for key in range(length - 1):
        if string[key:key+2] == "AC":
            memo.append(key + 1)

    for question in range(questions):
        left, right = map(int, input().split())
        right -= 1
        ans = solve(memo, left, right)
        print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
import sys
 
N, Q = map(int, input().split())
 
S = input()
 
lr = [list(map(int, i.split())) for i in sys.stdin]

Sum = [0]

sum_ = 0

for i in range(len(S)-1):
  if S[i] == 'A' and S[i+1] == 'C':
    sum_ += 1
  Sum.append(sum_)

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

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

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

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

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

Solution (Python):
n,q=map(int,input().split())
s=input()
ans=[0]*n+[0]
for i in range(n):
    if s[i:i+2]=='AC':
        ans[i+1]=ans[i]+1
    else:
        ans[i+1]=ans[i]
for i in range(q):
    l,r=map(int,input().split())
    print(ans[r-1]-ans[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()
A = [list(map(int,input().split())) for i in range(q)]

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

for i in range(q) :
    print(ANS[A[i][1]] - ANS[A[i][0]])

Solution (Python):


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

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

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

Solution (Python):
n,q=map(int, input().split())
s=input()
lr=[list(map(int, input().split())) for _ in range(q)]
count=[0]*(n)
for i in range(1,n):
    if s[i-1]+s[i]=='AC':
        count[i]+=count[i-1]+1
    else:
        count[i]+=count[i-1]
for j in range(q):
    start=lr[j][0]-1
    end=lr[j][1]-1
    print(count[end]-count[start])

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,q = LI()
    s = S()
    lr = [LI() for _ in range(q)]

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

    rr = []
    for a,b in lr:
        t = cc[b] - cc[a]
        rr.append(t)

    return '\n'.join(map(str, rr))


print(main())

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

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

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

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

Solution (Python):
from bisect import bisect_left
N, Q = map(int, input().split())
S = str(input())
LR = [list(map(int, input().split())) for i in range(Q)]

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


for l, r in LR:
    i = bisect_left(ans_list, l-1)
    j = bisect_left(ans_list, r-1)
    print(j-i)

Solution (Python):
from bisect import bisect_left
N, Q = map(int, input().split())
S = str(input())
LR = [list(map(int, input().split())) for i in range(Q)]

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


for l, r in LR:
    i = bisect_left(ans_list, l-1)
    j = bisect_left(ans_list, r-1)
    print(j-i)

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

Solution (Python):
import numpy as np

N, Q = map(int, input().split())
S = input()
t = np.zeros(N+1)
for i in range(N):
    t[i+1] = t[i]+(1 if S[i-1:i+1]=='AC' else 0)

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

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

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

Solution (Python):
N,Q=[int(x) for x in input().split()]
S=list(input())

t=[0]

for i in range(1,N):
  if (S[i-1]=='A')&(S[i]=='C'):
    t.append(t[i-1]+1)
  else:
    t.append(t[i-1])

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

Solution (Python):


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

num = [0] * (N+1)

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

        

for i in range(Q):
    l, r = map(int, input().split())
    print( num[r-1] - num[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())
S.append(0)
par = [0]*(N+1)
Ans = []
for i in range(N):
        par [i+1]=par[i]+(1 if (S[i]=='A') & (S[i+1]=='C') else 0)
for i in range(Q):
        x,y = map(int,input().split())
        print(par[y-1]-par[x-1])

Solution (Python):
def get_answer(a, start, end):
    return a[end] - a[start]

def create_answer_array(s):
    result = []
    result.append(0)

    for i in range(1, len(s)):
        if s[i - 1] == "A" and s[i] == "C":
            result.append(result[i - 1] + 1)
        else:
            result.append(result[i - 1])

    return result

n, q = map(int, input().split())
s = str(input())
questions = []
for _ in range(q):
    a, b = map(int, input().split())
    questions.append((a - 1, b - 1))

a = create_answer_array(s)

for question in questions:
    print(get_answer(a, question[0], question[1]))

Solution (Python):
N,Q = map(int,input().split())
S = input()
point = [list(map(int,input().split())) for i in range(Q)]
ac_list = [0]*(N+1)
 
for i in range(N):
  if S[i:i+2] == 'AC':
    ac_list[i+1] = ac_list[i] + 1
  else:
    ac_list[i+1] = ac_list[i]
 
 
for i in range(Q):
  print(ac_list[point[i][1]-1] - ac_list[point[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 = list(map(int, input().split()))

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

Solution (Python):
n,q = map(int,input().split())
s = input()
x = [list(map(int,input().split())) for i in range(q)]
cnt = 0
res = [0]
for i in range(1,len(s)):
    if s[i-1]=="A" and s[i]=="C":
        cnt += 1
    res.append(cnt)
for j in range(q):
    print(res[x[j][1]-1]-res[x[j][0]-1])

Solution (Python):

"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_b -d test-b
oj test -d test-c -c "python abc116c.py"
oj test -d test-b -c "python abc116b.py" test-b/sample-3.in
"""

from collections import defaultdict
import sys
import math
import time
import itertools


def deco(func):
    def wrapper(*args, **kwargs):
        s = time.time()
        
        ret = func(*args, **kwargs)
        logging.debug('--end in %f --' % (time.time() - s) )
        return ret
    return wrapper


@deco
def sol(N, Q, S, LR):
    M = [0] * N
    logging.debug("%s, %s, %s, %s, %s" % (N, Q, S, LR, M))
    for i in range(1, N):
        logging.debug("i:%s" % i)
        if S[i-1] + S[i] == "AC":
            M[i] = M[i-1] + 1
        else:
            M[i] = M[i-1]

    A = [0]*Q
    for j in range(Q):
        l, r = int(LR[j][0])-1, int(LR[j][1])-1
        A[j] = M[r] - M[l]

    return A





import logging

do_submit = False
do_submit = True

if do_submit:
    logging.basicConfig(level=logging.ERROR, format="%(message)s")
else:
    logging.basicConfig(level=logging.DEBUG, format="%(message)s")
def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(line.split()) for line in lines]
    (N, Q) = parsed_lines[0]
    N = int(N)
    Q = int(Q)
    S = parsed_lines[1][0]
    
    LR = []
    for i in range(2, 2+Q):
        l , r = int(parsed_lines[i][0]), int(parsed_lines[i][1])
        LR.append((l, r))
    return (N, Q, S, LR)



if not do_submit:
    
    
    
    
    (N, Q, S, LR) = input_parse("""
    8 3
    ACACTACG
    3 7
    2 3
    1 8
    """)
    for a in sol(N, Q, S, LR):
        print (a)

    (N, Q, S, LR) = input_parse("""
    20 6
    AGCTAATTTACACGTAATCC
    3 7
    2 3
    1 8
    1 20
    9 18
    14 18
    """)
    for a in sol(N, Q, S, LR):
        print (a)

else:
    str = ""
    NQ = input().strip()
    N, Q= list(map(int, NQ.split()))
    str += NQ + "\n"
    str += input().strip() + "\n"
    for i in range(Q):
        str += input().strip() + "\n" 
    (N, Q, S, LR) = input_parse(str)
    
    for a in sol(N, Q, S, LR):
        print (a)

Solution (Python):
N,Q = map(int,input().split())
S = input()
point = [list(map(int,input().split())) for i in range(Q)]
ac_list = [0]*(N+1)

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


for i in range(Q):
  print(ac_list[point[i][1]-1] - ac_list[point[i][0]-1])

Solution (Python):
N, Q = map(int, raw_input().split())
S = raw_input()
countlist = []
flag = False
cnt = 0
for i in range(0, len(S)):
	if flag:
		if S[i] == 'C':
			cnt += 1
		flag = False
	if S[i] == 'A':
		flag = True
	countlist.append(cnt)

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

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

for i in range(Q):
    a.append(list(map(int, input().split())))

for i in range(len(S)):
    an[i+1]=an[i]
    if S[i:i + 2] == "AC":
        an[i+1] += 1


for i in range(Q):
    print(an[a[i][1]-1] - an[a[i][0] - 1])

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

total_list = []
total = 0
for i in range(N-1):
  if S[i] == 'A' and S[i+1] == 'C':
    total += 1
  total_list.append(total)

for i in range(Q):
  l, r = T[i][0], T[i][1]
  if l != 1:
    print(total_list[r-2]-total_list[l-2])
  else:
    print(total_list[r-2])

Solution (Python):
N, Q = [int(x) for x in input().split()]
S = input()

t = [0] * N
a = [0] * N

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

a[0] = 0
for i in range(N - 1):
    a[i + 1] = a[i] + t[i]

for q in range(Q):
    l, r = [int(x) for x in input().split()]
    print(a[r - 1] - a[l - 1])

Solution (Python):
N, Q = [int(i) for i in input().split()]
S = input()
lrList = [[int(i) for i in input().split()] for _ in range(Q)]

ACNum = 0
ACList = [0]
for i in range(1, len(S)):
    if S[i - 1] == "A" and S[i] == "C":
        ACNum += 1
    ACList.append(ACNum)

for q in range(Q):
    l, r = lrList[q][0], lrList[q][1]
    ans = ACList[r - 1] - ACList[l - 1]
    print(ans)

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

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

c=0
s=[0]
for i in range(1,N):
    if S[i-1]=='A' and S[i]=='C':
        c+=1
    s.append(c)
    
for i in range(Q):
    l,r=map(int,input().split())
    out=s[r-1]-s[l-1]

    print(out)

Solution (Python):
N,Q = (int(x) for x in input().split())
S = list(input())
count = [0 for i in range(N)]
c = 0
for i in range(N-1):
    if S[i] == 'A':
        if S[i+1] == 'C':
            count[i] = c
            c += 1
            i += 1
        elif S[i+1] != 'A':
            count[i] = c
            i += 1 
    count[i] = c
if count[-2] > count[-1]:
    count[-1] = count[-2]

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

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

cumu = [0]*(N+1)

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

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

Solution (Python):
N, Q = map(int, input().split())
S = input()
a = []
an = [0] * (N + 1)
for i in range(Q):
    a.append(list(map(int, input().split())))

for i in range(len(S) - 1):
    an[i + 1] = an[i]
    if S[i:i + 2] == "AC":
        an[i + 1] += 1
for i in range(Q):
    print(an[a[i][1] - 1] - an[a[i][0] - 1])

Solution (Python):
N, Q = map(int, input().split())
S = input()
a = []
an = [0] * (N + 1)
for i in range(Q):
    a.append(list(map(int, input().split())))

for i in range(len(S) - 1):
    an[i + 1] = an[i]
    if S[i:i + 2] == "AC":
        an[i + 1] += 1
for i in range(Q):
    print(an[a[i][1] - 1] - an[a[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):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,Q=MAP()
S=input()

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

for i in range(Q):
    l,r=MAP()
    print(sm[r]-sm[l])

Solution (Python):
from bisect import bisect_left as b_l
n,q=map(int,input().split())
s=input()
pi=0
aci=[]
while 1:
    ni=s[pi:].find("AC")
    if ni==-1:
        break
    aci+=[ni+pi]
    pi+=ni+1
for i in range(q):
    si,ei=map(int,input().split())
    print(b_l(aci,ei-1)-b_l(aci,si-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()
temp=[0]*(n+1)
for i in range(n):
	if s[i:i+2]=="AC":
		temp[i+1]=temp[i]+1
	else:
		temp[i+1]=temp[i]

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

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

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

Solution (Python):
n,q = map(int,input().split())
str = input()
q = int(q)
dic = {}

for j in range(len(str)):
  if (j > 0):
    if (str[j-1] == 'A' and str[j] == 'C'):
      dic[j] = dic[j-1] + 1
    else:
      dic[j] = dic[j-1]
  else:
    dic[j] = 0

for i in range(q):
  s,e = map(int,input().split())
  ans = dic[e-1] - dic[s-1]
  print(ans)

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

total_list = []
total = 0
try:
  for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
      total += 1
    total_list.append(total)

  for i in range(Q):
    l, r = T[i][0], T[i][1]
    if l != 1:
      print(total_list[r-2]-total_list[l-2])
    else:
      print(total_list[r-2])
except IndexError:
  print(0)

Solution (Python):
n, q = list(map(int, input().split(" ")))
s = input()
s = s.replace("AC", "ZC")
num = 0
ac_index = []
for _s in s:
    if _s == "Z":
        ac_index.append(num)
        num += 1
    else:
        ac_index.append(num)
i = 0

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

Solution (Python):
n, q = map(int, input().split())
s = input()
SUM = [0]*n

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

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

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

numAC = 0
noAs, noCs = [0]*N, [0]*N
for i in range(N-1):
    if Ss[i:i+2] == 'AC':
        numAC += 1
        noAs[i] = numAC
        noCs[i+1] = numAC

noAs[-1] = numAC+1
for i in reversed(range(N-1)):
    if noAs[i] == 0:
        noAs[i] = noAs[i+1]
for i in range(1, N):
    if noCs[i] == 0:
        noCs[i] = noCs[i-1]

anss = []
for L, R in LRs:
    L, R = L-1, R-1
    anss.append(max(0, noCs[R]-noAs[L]+1))

print('\n'.join(map(str, anss)))

Solution (Python):
n, q = map(int, input().split())
st = input()
questions = [tuple(map(int, input().split())) for i in range(q)]
lis = []
cnt = 0
for i in range(len(st)-1):
    if st[i-1:i+1] == 'AC':
        cnt += 1
    lis.append(cnt)
if st[-2:] == 'AC':
    cnt += 1
lis.append(cnt)
for l, r in questions:
    print(lis[r-1] - lis[l-1])

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

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

for i in range(q):
    print(cum[a[i][1]-1]-cum[a[i][0]-1])

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

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

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


if __name__ == '__main__':
    main()

Solution (Python):
n, q = map(int, input().split())
s = input()
a = [list(map(int, input().split())) for i in range(q)]
cum=[0]*n
for i in range(1, n):
    cum[i] = cum[i - 1]
    if s[i-1:i+1]=='AC':
        cum[i]+=1
for i in range(q):
    print(cum[a[i][1]-1]-cum[a[i][0]-1])

Solution (Python):
n,q = [int(i) for i in input().split()]
s = input()
l = []
r = []
memo = [0] * 100001
for i in range(q):
    x,y=[int(i) for i in input().split()]
    l.append(x)
    r.append(y)

for i in range(len(s)):
    if i==0:
        continue
    else:
        memo[i] = memo[i-1] + s[i-1:i+1].count("AC")

for i in range(q):
    print(memo[r[i]-1]-memo[l[i]-1])

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

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

pattern = 'AC'
X = [0] * (N+1)

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

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

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

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

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

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

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

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

Solution (Python):

import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    c = [0 for i in range(N+1)]
    for i in range(N):
        c[i+1] = c[i] + (1 if S[i:i+2] == "AC" else 0)
    for q in range(Q):
        print(c[r[q]-1] - c[l[q] - 1])

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    Q = int(next(tokens))  
    S = next(tokens)  
    l = [int()] * (Q)  
    r = [int()] * (Q)  
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)

if __name__ == '__main__':
    main()

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

c = [0] * N

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

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

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

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

for _ 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
t[0] = 0
for i in range(1,N):
    if S[i-1] == 'A' and S[i] == 'C':
        t[i] = t[i-1] + 1
    else:
        t[i] = t[i-1]

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

for a in ans:
    print(a)

Solution (Python):
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ 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 i in range(Q):
    l, r = LR[i][0], LR[i][1]
    cnt = t[r - 1] - t[l -1]
    print(cnt)

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

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

Solution (Python):

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

query = [[int(e)-1 for e in input().split()] for _ in range(Q)]


acc = [0]*(N+1)

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

for l,r in query:
    
    
    ans = acc[r+1] - acc[l]
    
    if S[l-1] == "A" and S[l] == "C":
        ans -= 1
    print(ans)

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

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,mondaisuu=map(int,input().split())
s=input()
dp=[0]*n
for i in range(1,n):
  dp[i]=dp[i-1] + (1 if s[i]=="C" and s[i-1]=="A" else 0)
for i in range(mondaisuu):
  l,r=map(int,input().split())
  print(dp[r-1]-dp[l-1])

Solution (Python):
 

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=sss[l-1]-sss[r-1]
		
		print(rr)
	


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