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
input = sys.stdin.readline
N, Q = map(int,input().split())
S = input()
ls = []
rs = []
for i in range(Q) :
    l, r = map(int,input().split())
    ls.append(l)
    rs.append(r)

ans = [0 for _ in range(N+1)]
temp = 0
for i in range(N) :
    if S[i:i+2] == "AC" :
        temp += 1
    ans[i+1] += temp

for i in range(Q) :
    print(ans[rs[i]-1] - ans[ls[i]-1])

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

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

lis = [0]*N
count = 0

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

lis_acc = list(accumulate(lis))

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

Solution (Python):

n, q = map(int, input().split())
a = [0 for i in range(n+1)]
s = input()
for i in range(n):
    a[i+1] = a[i] + (1 if s[i:i+2] == 'AC' else 0)


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

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


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


for q in range(Q):
  start, end = map(int, input().split())
  count = AC_numbers[end-1] - AC_numbers[start-1]
  print(count)

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

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

for l, r in X:
    print(cnt[r - 1] - cnt[l - 1])

Solution (Python):

from itertools import accumulate
A = []
N, Q = map(int, input().split())
B = [0]*N
S = list(input())
ans = []
for i in range(1, N):
    if S[i-1]=='A' and S[i]=='C':
        B[i] = 1
A = list(accumulate(B))
for j in range(Q):
    l, r = map(int, input().split())
    ans.append(A[r-1]-A[l-1])
print('\n'.join(map(str, ans)))

Solution (Python):
import numpy

n,q = [int(x) for x in input().split()]
s = input()

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

Solution (Python):

import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    table = [0] * (N + 1)
    for i, (s1, s2) in enumerate(zip(S, S[1:]), 1):
        table[i+1] = table[i] + (1 if s1 == 'A' and s2 == 'C' else 0)
    for ll, rr in zip(l, r):
        yield table[rr] - table[ll]


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))
    for r in solve(N, Q, S, l, r):
        print(r)

if __name__ == '__main__':
    main()

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

s=input()

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]

for _ in range(q):
    x,y = map(int,input().split())
    print(check[y-1]-check[x-1])

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

Solution (Python):
N, Q = map(int, input().split())
S = input()
l, r = [0]*Q, [0]*Q
for i in range(Q):
    l[i], r[i] = map(int,input().split())
    l[i] -= 1
    r[i] -= 1
lr = zip(l,r)

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

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

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

if __name__=='__main__':
  main()

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

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

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

Solution (Python):
n, q = [int(i) for i in input().split()]
s = input()
l = []
r = []
for _ in range(q):
    i, k = [int(i) for i in input().split()]
    l.append(i)
    r.append(k)

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

for i, k in zip(l, r):
    print(cum_sum[k-1] - cum_sum[i-1])

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

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

for i in range(q):
    first, last = map(int, input().split())
    print(table[last - 1] - table[first - 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 = [int(x) for x in input().split()]
S = input()
R = [0]
res = 0
ans = []
for i in range(N - 1):
    if S[i:i+2] == 'AC':
        res += 1
    R.append(res)
for i in range(Q):
    l, r = [int(x) for x in input().split()]
    ans.append(R[r-1] - R[l-1])
for r in ans:
    print(r)

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

t_sum=[0]*n
for i in range(n):
    if i==0:
        t_sum[i]=t[0]
        continue
    t_sum[i]=t_sum[i-1]+t[i]

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

Solution (Python):

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


s=list(input())

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

ansl=[]
for i in range(q):
    l,r=map(int,input().split())
    if l==1:
        ansl.append(cuml[r-1])
    else:
        ansl.append(cuml[r-1]-cuml[l-1])

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

Solution (Python):
n,q=map(int,input().split())
s=input()
cnt=[0]*n
for i in range(1,n):
  if s[i-1]=='A' and s[i]=='C':
    cnt[i]=cnt[i-1]+1
  else:
    cnt[i]=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())
text=input()
sum_=[]
count=0
for i in range(n):
    if text[i-1]=='A' and text[i]=='C':
        count+=1
    sum_.append(count)
for i in range(q):
    l,r=map(int,input().split())
    print(sum_[r-1]-sum_[l-1])

Solution (Python):





import itertools



import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, q = list(map(int,ipti().split()))
    s = input()
    ls = len(s)
    ac = [0] * ls

    for i in range(ls-1):
        if s[i] == 'A':
            if s[i+1] == 'C':
                ac[i+1] += 1

    cs = list(itertools.accumulate(ac))

    for i in range(q):
        left, right = list(map(int,ipti().split()))
        print(cs[right-1] - cs[left-1])

if __name__ == '__main__':
    main()

Solution (Python):
n, m = map(int, input().split())
graph = list(input())
ans = [0] * n
sans = [0] * n
for i in range(n-1):
    if graph[i] == "A" and graph[i+1] == "C":
        ans[i] += 1
for j in range(n-1):
    sans[j+1] = sans[j] + ans[j]

for _ in range(m):
    j, k = map(int, input().split())
    print(sans[k-1] - sans[j-1])

Solution (Python):
N, Q = map(int, input().split())
S = str(input())
Cs = []
for _ in range(Q):
  l, r = map(int, input().split())
  Cs.append((l, r))

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

from bisect import bisect_left
for c in Cs:
  ans = bisect_left(det_idx, c[1]-1) - bisect_left(det_idx, c[0]-1)
  print(ans)

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

n, q = map(int, input().split())
s = input()
memo = [0] * n
cnt = 0

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

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

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

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


for q in query:
    print(cum_sum[q[1]] - cum_sum[q[0]])

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

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()
info = [list(map(int, input().split())) for _ in range(q)]
all = s.count('AC')
ans = []
lt = [all]
rt = [all]



for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        lt.append(lt[i-1] - 1)
    else:
        lt.append(lt[i-1])
    if s[n-i-1] == 'A' and s[n-i] == 'C':
        rt.append(rt[i-1] - 1)
    else:
        rt.append(rt[i-1])

rt.reverse()



for l, r in info:
    ans.append(lt[l-1] + rt[r-1] - all)

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

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

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

for i in range(Q):
    L = LR[i][0]-1
    R = LR[i][1]-1
    print(U[R]-U[L])

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

t = [0 for i in range(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()
l_r = []
for i in range(Q):
  l_r.append(list(map(int,input().split())) )


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

for i in range(Q):
  r = ac_wa[l_r[i][1]-1] 
  l = ac_wa[l_r[i][0]-1]
  ans = r-l
  print(ans)

Solution (Python):
import bisect
n, q = map(int, input().split())
s = input()
li = []

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

ans = []
num = 0

for i in range(q):
    l, r = map(int, input().split())
    num = bisect.bisect_right(li, r-2)-bisect.bisect_left(li, l-1)
    ans.append(num)

for i in ans:
    print(i)

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

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

for i in range(q):
    l, r = map(int, input().split())
    print(cum_sum[r-1] - cum_sum[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()

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

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

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

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

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

Solution (Python):
n, q = map(int, input().split())
s = input()
lr = [[0] * 2 for _ in range(q)]
for i in range(q):
    l, r = map(int, input().split())
    lr[i][0], lr[i][1] = l, r

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

for i in lr:
    print(cnt[i[1]-1] - cnt[i[0]-1])

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

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

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

Solution (Python):
N,Q=[int(i) for i in input().rstrip().split()]
S = input().strip()
lr_list=[[int(j) for j in input().split()] for i in range(Q)]

calc_cnt=[0]
for i in range(1,len(S)):
    sub_str = S[(i-1):(i+1)]
    
    if sub_str == "AC":
        calc_cnt += [calc_cnt[i-1] + 1]
    else:
        calc_cnt += [calc_cnt[i-1]]
        

for l,r in lr_list:
    ans = calc_cnt[r-1] - calc_cnt[l-1]
    print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations
    
    from math import floor, ceil

    

    n,q = map(int, input().split())
    s = input()
    l = [0]*(n+1)
    for i in range(n):
        if s[i]=='A':
          if s[i+1]=='C':
            l[i+1]=l[i] + 1
            continue
        l[i+1]=l[i]

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


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations
    
    from math import floor, ceil

    

    n,q = map(int, input().split())
    s = input()
    l = [0]*(n+1)
    for i in range(n):
        if s[i:i+2]=='AC':
            l[i+1]=l[i] + 1
        else:
            l[i+1]=l[i]

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


if __name__ == '__main__':
    main()

Solution (Python):
N, Q = map(int, input().split())
S = input()
s = S[:2]
ans = 'AC'
lst = [0]
count = 0
for i in range(N-1):
    s = S[i] + S[i + 1]
    count += (s == ans)
    lst.append(count)

for _ in range(Q):
    a, b = map(int, input().split())
    print(lst[b - 1] - lst[a - 1])

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

S = list(input())

A = [0]

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

A = A[1:]
for i in range(q):
    a, b = map(int, input().split())
    print(A[b-1] - A[a-1])

Solution (Python):
from itertools import accumulate
n,q = map(int,input().split())
s = input()
L = [0]*n

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

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

Solution (Python):
n,q=map(int,input().split())
s=input()
ac=[0]
buf=0
for i in range(1,n):
    if s[i-1:i+1]=="AC":
        buf+=1
    ac.append(buf)
for i in range(q):
    l,r=map(int,input().split())
    ans=ac[r-1]-ac[l-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,q = map(int,input().split())

s=input()

dp = [0]*n

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

for _ in range(q):
    a, b = (int(x) for x in input().split())
    print(dp[b-1]-dp[a-1])

Solution (Python):

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

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

Solution (Python):
def main():
    n,Q = map(int,input().split())
    s = input()
    q =[]
    for i in range(Q) :
        l,r=map(int,input().split())
        q.append([l-1,r-1])
    sum_ary = [0] * n

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

    for i,query in enumerate(q):
        print(sum_ary[query[1]] - sum_ary[query[0]])
if __name__ == '__main__':
    main()

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

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,Q=MI()
    S=ST()
    cumsum = [0]*N
    for i in range(N-1):
        if S[i:i+2]=="AC":
            cumsum[i+1]+=1
        cumsum[i+1]+=cumsum[i]
    for _ in range(Q):
        l,r = MI()
        print(cumsum[r-1]-cumsum[l-1])
if __name__ == '__main__':
    main()

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()
lis = [0] * (n + 1)

for i in range(n):
    if s[i:i+2] == "AC":
        lis[i + 1] = lis[i] + 1
    else:
        lis[i + 1] = lis[i] + 0
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()
X=[0]*N
for i in range(N-1):
	if S[i:i+2]=="AC":
		X[i+1]=X[i]+1
	else:
		X[i+1]=X[i]
for i 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 = str(input())
lr_lst = [list(map(int,input().split())) for i in range(q)]

ac_lst = [0] * (n+1)

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

for i in range(q):
    start = lr_lst[i][0]
    end = lr_lst[i][1]

    print(ac_lst[end-1] - ac_lst[start-1])

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

ac = [0] * n
for itr, (i, j) in enumerate(zip(S, S[1:])):
  if i + j == "AC":
    ac[itr+1] = ac[itr] + 1
  else:
    ac[itr+1] = ac[itr]

for l, r in lr:
  print(ac[r-1] - ac[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):
def main():
    N, Q = (int(i) for i in input().split())
    S = input()
    C = [0] * (len(S) + 1)
    for i in range(1, len(S)):
        C[i+1] = C[i] + (1 if S[i] == "C" and S[i-1] == "A" else 0)

    for q in range(Q):
        le, ri = (int(i) for i in input().split())
        print(C[ri] - C[le])


if __name__ == '__main__':
    main()

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

mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n, q = na()
s = ns()
ac = list()
now = 0
f = False
for si in s:
    if si == "C" and f:
        now += 1
        f = False
    elif si == "A":
        f = True
    else:
        f = False
    ac.append(now)
for _ in range(q):
    l, r = na()
    l -= 1; r -= 1
    print(ac[r] - ac[l])

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,Q=map(int,input().split())
    S=list(input())+['Z']
    ans=[0]*(N+1)
    for i in range(N):
        if S[i]=='A' and S[i+1]=='C':
            ans[i+1]=ans[i]+1
        else:
            ans[i+1]=ans[i]
    for _ in range(Q):
        l,r=map(lambda x:int(x)-1,input().split())
        print(ans[r]-ans[l])

if __name__ == '__main__':
    main()

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

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

ans = []
for l,r in LR:
    l,r = l-1,r-1
    ans.append(cums[r] - cums[l])
print(*ans,sep='\n')

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


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

Solution (Python):
from itertools import accumulate
N, Q = map(int, input().split())
S = "?" + input()
query = (tuple(map(int, input().split())) for _ in range(Q))

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

cnt = tuple(accumulate(cnt))

ans = (cnt[r] - cnt[l] for l, r in query)
print(*ans, sep="\n")

Solution (Python):
N, Q = map(int, input().split())
S = input().strip()
b = None
nm = 0
dp = [0]
for c in S:



    if b == 'A' and c == 'C':
        nm += 1
    dp.append(nm)
    b = c

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

Solution (Python):
n,k=map(int,input().split())
a=input()
ac=[0]*n
x=0
for i in range(n-1):
    if a[i]=='A' and a[i+1]=='C':
        x+=1
    ac[i+1]=x
ac[-1]=x
for i in range(k):
    l,r=map(int,input().split())
    print(ac[r-1]-ac[l-1])

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

ac = [0] * n

for i in range(1, n):
        if s[i-1:i+1]=="AC": ac[i] = 1
        ac[i] += ac[i-1]

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

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

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

Solution (Python):
n, q = map(int, input().split())
S = input().strip()
*LR, = (map(int, input().split()) for _ in range(q))

A = [0] * n
for i in range(1, n):
    A[i] = A[i-1] + (S[i-1:i+1] == 'AC')
for l, r in LR:
    print(A[r-1]-A[l-1])

Solution (Python):
n, q = map(int, input().split())
S = input().strip()
*LR, = (map(int, input().split()) for _ in range(q))

A = [0] * n
for i in range(1, n):
    A[i] = A[i-1] + (S[i-1] == 'A' and S[i] == 'C')
for l, r in LR:
    print(A[r-1]-A[l-1])

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

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

for i in range(q):
    l = ll[i][0]
    r = ll[i][1]
    print(acl[r-1] - acl[l-1])

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

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

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

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

Solution (Python):
n,q = map(int,input().split())
s = input()
lis = [list(map(int,input().split())) for _ in range(q)]
rui = []
for i,ss in enumerate(s):
    if i == 0:
        rui.append(0)
    else:
        if ss == 'C' and  s[i-1] == 'A':
            rui.append(rui[-1]+1)
        else:
            rui.append(rui[-1])

for l in lis:
    print(rui[l[1]-1]-rui[l[0]-1])

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

Solution (Python):
from bisect import bisect_left

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

ac_pos = []
p = 0
while p < N-1:
    if S[p]=="A" and S[p+1]=="C":
        ac_pos.append(p+1)
        p+=2
    else:
        p+=1

for _ in range(Q):
    l, r = map(int, input().split())
    p = bisect_left(ac_pos, l)
    q = bisect_left(ac_pos, r)
    print(q-p)

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

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


for l,r in L:
    ans=s[r-1]-s[l-1]
    print(ans)

Solution (Python):
n,q = map(int,input().split())
s = input()
ac = [0 for i in range(n+1)]
ans = []
for i in range(len(s)-1):
    if s[i:i+2]=="AC":
        ac[i+1] = ac[i] + 1
    else:
        ac[i+1] = ac[i]

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

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

ans_list=[]
for g in range(q):
    l,r=map(int,input().split())
    ans_list.append(accumlate[r-1]-accumlate[l-1])

for m in range(q):
    print(ans_list[m])

Solution (Python):
N, Q = [int(i) for i in input().split()]
S = input()
lr = [[int(i) for i in input().split()] for _ in range(Q)]
ary = [0]*(N+1)
c = 0
f = bool(S[0] == "A")
for i in range(1, N):
    if S[i] == 'C' and f:
        c += 1
        f = False
    else:
        f = bool(S[i] == "A")
    ary[i] = c
for l, r in lr:
    print(ary[r-1]-ary[l-1])

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n,q=mii()
s=list(ss())

dp=[0]*n

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

for i in range(q):
    x,y=mii()
    print(dp[y-1]-dp[x-1])

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

li = [0]*N
Aflag = 0
AC = 0
for i in range(N):
    if S[i] == 'A':
        Aflag = 1
    elif S[i] == 'C' and Aflag:
        AC += 1
        Aflag = 0
    else:
        Aflag = 0
    li[i] = AC

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

[print(i) for i in ans]

Solution (Python):
from itertools import accumulate

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

lr = [list(map(int, input().split())) for _ in range(q)]

p = [0] * n
for i in range(1, n):
  pp = 0
  if s[i-1:i+1] == "AC":
    pp = 1
  p[i] = pp
  
p = [0] + list(accumulate(p))

for e in lr:
  print(p[e[1]] - p[e[0]])

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])