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

Solution (Python):
from itertools import accumulate

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

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


z = [0] + list(accumulate(z))


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

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

count = [0]

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


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

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

for k in range(len(ans)):
    print(ans[k])

Solution (Python):
def main():
  import sys
  input=sys.stdin.readline
  n,q=map(int,input().split())
  s=input()
  
  ac=[0]*(n+1)
  for i in range(1,n):
    if s[i-1]=='A' and s[i]=='C':
      ac[i+1]=ac[i]+1
    else:
      ac[i+1]=ac[i]  
  
  for i in range(q):
    l,r=map(int,input().split())
    if l==1:
      ans=ac[r]-ac[l-1]
    elif s[l-2]=='A' and s[l-1]=='C':
      ans=ac[r]-ac[l-1]-1
    else:
      ans=ac[r]-ac[l-1]
    print(ans)
    
if __name__=='__main__':
  main()

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

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

for i in range(q):
    left = lr[i][0] - 1
    right = lr[i][1] - 1
    ans = ac[right] - ac[left]
    print(ans)

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


a = [0] * (n + 1)


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()
counts = [0] * n
for i in range(1, n):
    if s[i - 1] == 'A' and s[i] == 'C':
        counts[i] = counts[i - 1] + 1
    else:
        counts[i] = counts[i - 1]

ret = [0] * q
for i in range(q):
    l, r = map(int, input().split())
    ret[i] = counts[r - 1] - counts[l - 1]

print(*ret, sep='\n')

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

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

for i in range(Q):
    print(rui[L[i][1]-1]-rui[L[i][0]-1])

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

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

    tmp = [0] * (n + 1)

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

for i in range(1, N):
    t[i] = t[i-1]
    if S[i-1:i+1] == 'AC': t[i] += 1
    
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 = [0] * N
for i in range(N-1):
  if S[i:i+2] == 'AC':
    a[i] = 1

cumsum = [0]
for _a in a:
  cumsum.append(cumsum[-1] + _a)


for i in range(Q):
  l, r = map(int, input().split())
  print(cumsum[r-1] - cumsum[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):
import numpy as np
n, q = map(int, input().split())
s = input()
w = np.zeros(n, dtype=int)

a = 0
for i in range(n):
    if s[i] == "A":
        if a == 0:
            a += 1
    elif s[i] == "C":
        if a:
            w[i-1] = 1
            a -= 1
    else:
        if a:
            a -= 1

ans = np.append(np.zeros(1, dtype=int), np.cumsum(w))
for _ in range(q):
    l, r = map(int, input().split())
    print(ans[r-1] - ans[l-1])

Solution (Python):
from itertools import accumulate

N,Q=map(int,input().split())
S=input()
l=[0 for i in range(0,Q)]
r=[0 for i in range(0,Q)]
for i in range(0,Q):
    l[i],r[i]=map(int,input().split())
check=[]
for i in range(0,N-1):
    if S[i]+S[i+1]=='AC':
        check.append(1)
    else:
        check.append(0)
ans=list(accumulate(check))
for i in range(0,Q):
    if l[i]==1:
        print(ans[r[i]-2])
    else:
        print(ans[r[i]-2]-ans[l[i]-2])

Solution (Python):
from itertools import accumulate

def main():
    N,Q=map(int,input().split())
    S=input()
    l=[0 for i in range(0,Q)]
    r=[0 for i in range(0,Q)]
    for i in range(0,Q):
        l[i],r[i]=map(int,input().split())
    check=[]
    check_append=check.append
    for i in range(0,N-1):
        if S[i]+S[i+1]=='AC':
            check_append(1)
        else:
            check_append(0)
    ans=list(accumulate(check))
    for i in range(0,Q):
        if l[i]==1:
            print(ans[r[i]-2])
        else:
            print(ans[r[i]-2]-ans[l[i]-2])

if __name__ == '__main__':
    main()

Solution (Python):
n, q = map(int, input().split())
s = input()
t = []
c = 0
for i in range(n - 1):
    if i != 0:
        if s[i - 1] == "A" and s[i] == "C":
            c += 1
    t.append(c)
if s[n - 2] == "A" and s[n - 1] == "C":
    t.append(c + 1)
else:
    t.append(c)
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()

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


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

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


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

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


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

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

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

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

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

Solution (Python):
N, Q = [int(i) for i in input().split()]
S = input()
ary = [0]*(N+1)
af = False
ans = []
for i, s in enumerate(S):
    ary[i+1] = ary[i]
    if s == "A":
        af = True
    elif s == "C" and af:
        ary[i+1] += 1
        af = False
    else:
        af = False
for _ in range(Q):
    l, r = [int(i) for i in input().split()]
    ans.append(ary[r]-ary[l])
for a in ans:
    print(a)

Solution (Python):
N,Q = map(int,input().split())
S = input()
X = []
x = 0
check = 0
for i in S:
    if check == 1 and i == 'C':
        x += 1
        check = 0
    if i == 'A':
        check = 1
    else:
        check = 0
    X.append(x)

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

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

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


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

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

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

for i in range(1, n):
    cnt[i] += cnt[i - 1]  

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

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

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

Solution (Python):
import sys
def input():
    return sys.stdin.readline().rstrip()

N, Q = map(int, input().split())
S = input()
li = [0]*(N+1)

for i in range(N):
    if S[i:i+2] == 'AC':
        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 = [int(x) for x in 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 _ in range(q):
    l,r = [int(x) for x in input().split()]
    print(t[r-1]-t[l-1])

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

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

for range_list in range_list:
    print(ac_counter[range_list[1]-1] - ac_counter[range_list[0]-1])

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

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

for lr in LR:
    print(ac_cnt[lr[1]-1] - ac_cnt[lr[0]-1])

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

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

num=[0]*N

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

sums=[0]*(N+1)
for i in range(1,N+1):
    sums[i]=sums[i-1]+num[i-1]

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

Solution (Python):

N,Q=map(int,input().split())
S=list(input())
W=[0]*N
W[0]=0

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


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

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

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

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

for i in range(Q):
  l, r = map(int, input().split())
  print(bisect.bisect_right(arr, r-2) - bisect.bisect_left(arr, l-1))

Solution (Python):
h,n = list(map(int, input().split()))
st = str(input())
a = [list(map(int, input().split())) for _ in range(n)]

o = "B"
b = []
c = 0
for i in range(len(st)):
    sti = st[i]
    if sti == "A":
        o = "A"
        b.append(c)
    elif sti == "C" and o == "A":
        o = "C"
        c += 1
        b.append(c)
    else:
        o = "B"
        b.append(c)

for a1,b1 in a:
    print(b[b1-1] - b[a1-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
input = sys.stdin.readline


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

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

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

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

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

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

Solution (Python):
n,q=map(int,input().split())
s=input()
cnt=[0]*n
icnt=0
for i in range(n-1):

    if s[i:i+2]=="AC":
      icnt=icnt+1
      cnt[i+1]=cnt[i]+1
    else:
      cnt[i+1]=cnt[i]

for i in range(q):
    li,ri=map(int,input().split())


    print(cnt[ri-1]-cnt[li-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)

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

[print(x) for x in ans]

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

def convert_N_AC():
    
    for i in range(1, len(S)):
        tmp = 0
        if (S[i - 1 : i + 1] == 'AC'):
            tmp = 1
        S_con[i] += tmp + S_con[i-1]

convert_N_AC()

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

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

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

ss=[0]*(n+1)

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

for i in range(q):
    print(ss[lr[i][1]] - ss[lr[i][0]])

Solution (Python):
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())

sys.setrecursionlimit(10 ** 9)


def main():
    N, Q = MAP()
    S = INPUT()
    
    L = [0]
    for i in range(N-1):
        L.append(L[-1] + (1 if S[i:i+2] == "AC" else 0))

    ans = []
    for i in range(Q):
        l, r = MAP()
        ans.append(L[r-1] - L[l-1])

    print(*ans)


if __name__ == '__main__':
    main()

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

t = [0] * len(S)

for index, s in enumerate(S):
  if index+1 > len(S)-1:
    break

  if s == 'A' and S[index+1] == 'C':
    t[index+1] = t[index] + 1
    
  else:
    t[index+1] = t[index]

for i in li:
  print(t[i[1]-1] - t[i[0] - 1])

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

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

Solution (Python):
f = lambda:map(int,input().split())
n,q = f()
s = input()
ln = [0]
for i in range(n):
  ln.append(ln[i]+(s[i-1:i+1]=='AC'))
for _ in range(q):
  l,r = f()
  print(ln[r]-ln[l])

Solution (Python):
f = lambda:map(int,input().split())
n,q = f()
s = input()
ln = [0]
for i in range(n):
  ln += [ln[i]+(s[i-1:i+1]=='AC')]
for _ in range(q):
  l,r = f()
  print(ln[r]-ln[l])

Solution (Python):
import sys
input = sys.stdin.readline
f = lambda : map(int,input().split())

n, q = f()
s = input()

ln = [0]
for i in range(n):
  ln += [ln[i] + (s[i-1:i+1]=='AC')]

for _ in range(q):
  l, r = f()
  print(ln[r] - ln[l])

Solution (Python):
import sys
input = sys.stdin.readline
f = lambda : map(int,input().split())

n, q = f()
s = input()

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

for _ in range(q):
  l, r = f()
  print(ln[r-1] - ln[l-1])

Solution (Python):
f = lambda : map(int,input().split())

n, q = f()
s = input()

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

for _ in range(q):
  l, r = f()
  print(ln[r-1]-ln[l-1])

Solution (Python):
f = lambda : map(int,input().split())

n, q = f()
s = input()

cnt = 0
ln = [0]*n
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    cnt += 1
  ln[i] = cnt
for _ in range(q):
  l, r = f()
  print(ln[r-1]-ln[l-1])

Solution (Python):
import sys
input = sys.stdin.readline
f = lambda : map(int,input().split())

n, q = f()
s = input()

cnt = 0
ln = [0]*n
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    cnt += 1
  ln[i] = cnt
for _ in range(q):
  l, r = f()
  print(ln[r-1]-ln[l-1])

Solution (Python):
import sys
input = sys.stdin.readline
f = lambda : map(int,input().split())

n, q = f()
s = input()

cnt = 0
ln = [0]*n
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    cnt += 1
  ln[i] = cnt
for _ in range(q):
  l, r = f()
  print(ln[r-1]-ln[l-1])

Solution (Python):
f = lambda : map(int,input().split())

n, q = f()
s = input()

cnt = 0
ln = [0]*n
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    cnt += 1
  ln[i] = cnt
for _ in range(q):
  l, r = f()
  print(ln[r-1]-ln[l-1])

Solution (Python):
import sys
input = sys.stdin.readline
f = lambda : map(int,input().split())

n, q = f()
s = input()

cnt = 0
ln = [0]*n
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    cnt += 1
  ln[i] = cnt
for _ in range(q):
  l, r = f()
  print(ln[r-1]-ln[l-1])

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

cnt = 0
ln = [0]*n
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    cnt += 1
  ln[i] = cnt
for _ in range(q):
  l, r = f()
  print(ln[r-1]-ln[l-1])

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

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

for _ 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()
t=[0]*(n+1)
for i in range(n):
	t[i+1]=t[i]+(s[i:i+2]=='AC')
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 = [0] * Q, [0] * Q
cnt = [0] * len(S)
for i in range(Q):
    l[i], r[i] = map(int, input().split())
    l[i] -= 1
    r[i] -= 1
for i in range(1, len(S)):
    if(i == 0): pass
    cnt[i] = cnt[i - 1]
    if (S[i] == 'C' and S[i - 1] == 'A'):
        cnt[i] += 1
for i in range(Q):
    print(cnt[r[i]] - cnt[l[i]])

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

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

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

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]
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):
    D = list(map(int, input().split()))
    lr.append(D)

ac_list=[]

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

import bisect

for j in range(q):
    ind1 = bisect.bisect_left(ac_list,lr[j][0]-1)
    ind2 = bisect.bisect_left(ac_list,lr[j][1]-1)

    print(ind2-ind1)

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

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

s.append("")

cusum = [0]*(len(s))
for i in range(len(s)-1):
    if s[i] == "A" and s[i+1] == "C":
        cusum[i+1] = cusum[i] + 1
    else:
        cusum[i+1] = cusum[i]

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

Solution (Python):
import numpy as np

N, Q = map(int, input().split())
S = np.zeros(N+1, dtype="S1")
S[1:] = list(input())

A = (S == b'A')
C = (S == b'C')
AC = (A[:-1] & C[1:]) 
AC_cum = list(AC.cumsum())

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

Solution (Python):
N, Q = map(int, input().split())
S = input()
LR = [[int(x)-1 for x in input().split()] for _ in range(Q)]
AC = []
pre = None
cnt = 0
for s in S:
  if s == "A":
    pre = "A"
  elif pre == "A" and s == "C":
    cnt += 1
    pre = None
  elif pre == "A": 
    pre = None
  AC.append(cnt)

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

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

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

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

Solution (Python):
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(input()) 
def ifn(): return float(input()) 
def isn(): return input().split() 
def imn(): return map(int, input().split()) 
def fmn(): return map(float, input().split()) 
def iln(): return list(map(int, input().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def fln(): return list(map(float, input().split())) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 
def m_add(a,b): return (a+b) % MOD

N,Q = imn()
S = input()
lr = [iln() for _ in range(Q)]

c = [0 for _ in range(N+1)]

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

for i in range(Q):
    left = lr[i][0]-1
    right = lr[i][1]-1
    print(c[right]-c[left])

Solution (Python):
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(input()) 
def ifn(): return float(input()) 
def isn(): return input().split() 
def imn(): return map(int, input().split()) 
def fmn(): return map(float, input().split()) 
def iln(): return list(map(int, input().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def fln(): return list(map(float, input().split())) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 
def m_add(a,b): return (a+b) % MOD

N,Q = imn()
S = input()
lr = [iln() for _ in range(Q)]

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

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

for i in range(Q):
    l = lr[i][0]
    r = lr[i][1]
    print(s[r-1]-s[l-1])

Solution (Python):

import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

def main():
    N,Q = cin.mapInt()
    S = cin.string()
    A = cin.intListList(Q)
    sums = [0] * N 
    for i in range(1,N):
        sums[i] = sums[i - 1]
        if S[i] == "C" and S[i - 1] == "A":
            sums[i] +=1
    for q in A:
        print(sums[q[1] - 1] - sums[q[0] - 1])
    return

if __name__ == "__main__":
    main()

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


ac = [0] * n

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

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

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

lr = []

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

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

for i in range(Q):
    print(acs[lr[i][1]-1]-acs[lr[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):
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    N, Q = read_values()
    S = input()
    
    num = [0]
    pre = None
    count = 0
    for s in S:
        if pre == "A" and s == "C":
            count += 1
        num.append(count)
        pre = s

    for _ in range(Q):
        l, r = read_values()
        print(num[r] - num[l])


if __name__ == "__main__":
    main()

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

  print(ans)

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

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

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

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