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):
def resolve():
    '''
    code here
    '''
    N, Q = [int(item) for item in input().split()]
    S = input()
    queries = [[int(item) for item in input().split()] for _ in range(Q)]

    memo = [0 for _ in range(N)]

    prev = S[0]
    for i in range(1, N):
        memo[i] = memo[i-1]
        if S[i] == 'C' and prev == 'A':
            memo[i] += 1
        prev = S[i]
    
    for l, r in queries:
        print(memo[r-1] - memo[l-1])




if __name__ == "__main__":
    resolve()

Solution (Python):
from itertools import accumulate
N, Q = map(int,input().split())
S = input()
AC = [0]*N
flag = 0
for idx, s in enumerate(S):
    if flag and s == "C":
        AC[idx] = 1
    if s == "A":
        flag = 1
    else:
        flag = 0

acc = list(accumulate(AC))

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

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

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

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

for l, r in question:
    ans = nums[r] - nums[l]
    print(ans)

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

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

def cumulative_sum(collection):
    result = [0]
    for item in collection:
        result.append(result[-1] + item)
    return result
csml = cumulative_sum(ml)

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

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

Solution (Python):
N,Q=map(int,input().split())
S=list(input())
answers=[0 for _ in range(N)]
for n in range(1,N):
    if S[n]=='C':
        if S[n-1]=='A':
            answers[n]=answers[n-1]+1
        else:
            answers[n]=answers[n-1]
    else:
        answers[n]=answers[n-1]


for _ in range(Q):
    l,r=map(int,input().split())
    print(answers[r-1]-answers[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 sys
input=sys.stdin.readline
n,q=map(int,input().split())
s=input()
a=[0]*n
for x in range(1,n):
  a[x]+=a[x-1]
  if s[x-1]=='A' and s[x]=='C':
    a[x]+=1
  
    
for y in range(q):
  
  l,r=map(int,input().split())
  ans=a[r-1]-a[l-1]
  print(ans)

Solution (Python):
n,q=map(int,input().split())
s=input()
L=[0 for i in range(n+1)]

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

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

Solution (Python):
import copy

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

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

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

Solution (Python):
import copy

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

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

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

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

ans = 0
ans_ls = []
ans_ls.append(0)

for n in range(N-1):
  if S[n] == "A" and S[n+1] =="C":
    ans += 1
  ans_ls.append(ans)

for q in range(Q):
  print(ans_ls[lr[q][1]-1]-ans_ls[lr[q][0]-1])

Solution (Python):
N, Q = map(int, input().split())
S = input()
quiz = [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 q in quiz:
  l = q[0]
  r = q[1]
  print(t[r-1] - t[l-1])

Solution (Python):
N, Q=map(int, input().split())
S=input()
count=0
ac=[0]
for i in range(N-1):
  if S[i]=="A" and S[i+1]=="C":
    count+=1
  ac.append(count)
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=list(input())
sum=[0]*n

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

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

for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        former_list.append(i+1)
        latter_list.append(i+2)
for j in range(q):
    l,r=map(int,input().split())
    start=bisect.bisect_left(former_list,l)
    end=bisect.bisect_right(latter_list,r)
    print(end-start)

Solution (Python):
import sys
input = sys.stdin.readline
n, q = [int(w) for w in input().split()]

s = input()
c_ac = [0]*(len(s)+1)

is_p_c = False
for i in range(len(s)-1, -1, -1):
    if s[i] == "A"and is_p_c:
        c_ac[i] = c_ac[i+1]+1
    else:
        c_ac[i] = c_ac[i+1]
    if s[i] == "C":
        is_p_c = True
    else:
        is_p_c = False


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

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd





def solve():
    n, q = [int(x) for x in input().split()]
    s = input()
    a = [0] * n
    b = [0] * n
    for i in range(n-1):
        if s[i:i+2] == 'AC':
            a[i] = 1
        b[i] = a[i]
        if i:
            b[i] += b[i-1]
    for _ in range(q):
        l, r = [int(x) for x in input().split()]
        l -= 1
        r -= 1
        ans = b[r-1]
        if l:
            ans -= b[l-1]
        print(ans)
    
    

        
    
t = 1

for case in range(1,t+1):
    ans = solve()


"""

R s
S p
P r

"""

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

Solution (Python):
N,Q = map(int,input().split())
S = input()
lr = [list(map(int,input().split())) for _ in range(Q)]
wa = [0,0]
num = 0
for i in range(2,N+1):
  if S[i-2:i] == "AC":
    num += 1
  wa.append(num)
left = 0
right = 0
for i in range(Q):
  left = lr[i][0]
  right = lr[i][1]
  print(wa[right]-wa[left])

Solution (Python):
N, Q = map(int, input().split())
S = input()
S = S.replace("AC", "XX")
acc = [0] * (N + 1)
i = 0
while i < N:
    if S[i] == "X":
        acc[i + 2] = 1 
        i += 2
    else:
        i += 1
for i in range(1, N + 1):
    acc[i] += acc[i - 1]

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

Solution (Python):
import sys
import math


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, Q = map(int, input().split())
    S = list(input())
    t = [0] * N
    count =0
    for i in range(1,N):
        if S[i-1]=="A" and S[i] =="C":
            count +=1
        t[i] =count

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

if __name__ == "__main__":
    main()

Solution (Python):

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

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


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


t=[0]
for i in range(1,N):
    t.append(t[-1] + flag[i])



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

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

def main():
    n, q = map(int, input().split())
    s = list(input())
    lr = [list(map(int, input().split())) for _ in range(q)]
    ac = [0] * len(s)
    for i in range(1, len(s)):
        if s[i-1]=='A' and s[i]=='C':
            ac[i] = ac[i-1] + 1
        else:
            ac[i] = ac[i-1]
    for i in lr:
        print(ac[i[1]-1]-ac[i[0]-1])
            
if __name__ == '__main__':
    main()

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

Solution (Python):
import sys
from operator import itemgetter

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def iif(n): return [int(input()) for _ in range(n)]
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    mod = 1000000007
    
    N, Q = mi()
    S = input()
    AC_cnt = [0] * len(S)
    cnt = 0
    for i in range(len(S)-1):
        if S[i] == "A" and S[i+1] == "C":
            cnt += 1
        AC_cnt[i+1] = cnt

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

    return

main()

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

cnt = [0] * (n)
for i in range(0, 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):
    ll = lr[i][0] - 1
    rr = lr[i][1] - 1
    print(cnt[rr] - cnt[ll])

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

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

for i in range(q):
    ll = lr[i][0] - 1
    rr = lr[i][1] - 1
    print(cnt[rr] - cnt[ll])

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

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


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n, q = map(int, input().split())
    s = input().rstrip()
    before = ''
    start_cumsum = []
    now_val = 0
    for (i, c) in enumerate(s):
        if c == 'A':
            before = 'A'
        elif c == 'C' and before == 'A':
            now_val += 1
            before = ''
        else:
            before = ''
        start_cumsum.append(now_val)
    for _ in range(q):
        l, r = map(int, input().split())
        print(start_cumsum[r - 1] - start_cumsum[l - 1])


if __name__ == '__main__':
    main()

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


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n, q = map(int, input().split())
    s = input().rstrip()
    before = ''
    start_cumsum = []
    end_cumsum = []
    now_val = 0
    for (i, c) in enumerate(s):
        end_cumsum.append(now_val)
        if c == 'A':
            before = 'A'
        elif c == 'C' and before == 'A':
            now_val += 1
            before = ''
        else:
            before = ''
        start_cumsum.append(now_val)
    end_cumsum.append(now_val)
    
    for _ in range(q):
        l, r = map(int, input().split())
        print(start_cumsum[r - 1] - start_cumsum[l - 1])


if __name__ == '__main__':
    main()

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

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

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

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


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

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

n, q = map(int, input().split())
s = input()
readline = sys.stdin.readline
LR = [[int(i)-1 for i in readline().split()] for _ in range(q)] 

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


tot = [0]*(len(nums)+1)
for i in range(len(nums)):
    tot[i+1] = tot[i]+nums[i]

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

Solution (Python):
N,Q = (int(X) for X in input().split())
S = input()
T = [0]*(N+1)
for I in range(0,N):
     T[I+1] = T[I] + (S[I:I+2]=='AC')
for J in range(0,Q):
    L,R = (int(X)-1 for X in input().split())
    print(T[R]-T[L])

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

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


for _ 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()
total = [0]*N

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

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

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 copy




N,X=map(int,input().split())
S=input()
lenS=len(S)

RS=S[::-1]

goukei=0
G=[]
G.append(0)
Rgoukei=0
RG=[]
for i in range(1,lenS):
    if S[i]=="C":
        if S[i-1]=="A":
            goukei+=1
    G.append(goukei)


RG.append(0)
for i in range(1,lenS):
    if RS[i]=="A":
        if RS[i-1]=="C":
            Rgoukei+=1
    RG.append(Rgoukei)
RG.reverse()




for i in range(X):
    A,B=map(int,input().split())
    print(goukei-G[A-1]-RG[B-1])

Solution (Python):
n,q = map(int,input().split())
s = input()
inf = [0]*n
num = 0
for i in range(1,n):
    if s[i] == "C" and s[i-1] == "A":
        num += 1
    inf[i] += num
for i in range(q):
    a,b = map(int,input().split())
    print(inf[b-1] - inf[a-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
n, q = map(int, input().split())
s = input()
cnt = 0
apoint = []
cpoint = []
for i in range(len(s) - 1):
    if s[i] + s[i + 1] == 'AC':
        cnt += 1
        apoint.append(i)
        cpoint.append(i)


for i in range(q):
    l, r = map(int, input().split())
    l, r = l - 1, r - 1
    left = bisect.bisect_left(apoint, l)
    right = bisect.bisect_left(cpoint, r)
    print(right - left)

Solution (Python):
def main():
    n, q = map(int, input().split())
    s = input()
    indic = {}
    for i in range(q):
        l, r = map(int, input().split())
        indic[i] = [l, r]
    
    ruisekidic = {}
    tmp = 0
    
    for i in range(n):
        if i == 0:
            mae = s[0]
            ruisekidic[i] = 0
        else:
            if mae == "A" and s[i] == "C":
                tmp += 1
                ruisekidic[i] = tmp
                mae = s[i]
            else:
                ruisekidic[i] = tmp
                mae = s[i]
    for i in range(q):
        [l, r] = indic[i]
        if l > 0:
            print(ruisekidic[r-1] - ruisekidic[l-1])
        else:
            print(ruisekidic[r-1])


    
if __name__ == "__main__":
    main()

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

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

cum = [0]*(n+1)
pre = s[0]
cnt=0
for i in range(1,n):
    now = s[i]
    if pre=="A" and now=="C":
        cnt+=1
    cum[i+1] = cnt
    pre = now
for l,r in lr:
    print(cum[r]-cum[l])

Solution (Python):


import io
import sys
import math

def solve(ac_lst,l,r):
    
    
    if l == 1:
        return ac_lst[r-2]
    return ac_lst[r-2] - ac_lst[l-2]
    

def make_ac_lst(s):
    ac_lst = [0] * len(s)
    for i in range(len(s)-1):
        if i != 0:
            ac_lst[i] += ac_lst[i-1]
        if s[i] == "A" and s[i+1] == "C":
            ac_lst[i] += 1
    ac_lst[-1] = ac_lst[-2]

    if _DEB: logd(f"{ac_lst}")
    return ac_lst

def main():
    
    n,q = map(int, input().split())
    s = input()
    
    
    ans = ""
    ac_lst = make_ac_lst(s)

    for _ in range(q):
        l,r = map(int, input().split())
        ans += str( solve(ac_lst,l,r) ) + "\n"
         
    
    print(ans)
    return ans
        

_DEB = 0   

_INPUT = """\
8 3
ACACTAAC
7 8
2 3
1 8
"""
_EXPECTED = """\
2
0
3

"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")


if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Solution (Python):
import copy

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 = str(input())
li = []
cnt = 0

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

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

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

Solution (Python):
import sys
read = sys.stdin.read
def main():
    n, q = map(int, input().split())
    s = input()
    acs = [0] * (n + 1)
    cnt = 0
    for i1 in range(1, n):
        if s[i1-1] =='A' and s[i1] == 'C':
            cnt += 1
        acs[i1+1] = cnt
    for _ in range(q):
        l, r = map(int, input().split())
        r = acs[r] - acs[l]
        print(r)


if __name__ == '__main__':
    main()

Solution (Python):

def solve():
    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 j in range(Q):
        print(t[lr[j][1]-1]-t[lr[j][0]-1])

if __name__ == "__main__":
    N,Q = list(map(int, input().split()))  
    S = input()
    lr = [list(map(int, input().split())) for _ in range(Q)]
    solve()

Solution (Python):
N, Q = (int(x) for x in 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 = (int(x) for x in input().split())
  print(t[r-1] - t[l-1])

Solution (Python):
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
sys.setrecursionlimit(10 ** 6)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, q = MAP()
s = input()
p = [LIST() for i in range(q)]
l = [0]*n
r = [0]*n

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

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

for i in range(q):
    print( r[p[i][1]-1] - r[p[i][0]-1] )

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


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


for q in LR:
    l = q[0] - 1
    r = q[1] - 1
    print(cumsum[r] - cumsum[l])

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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
N,Q = list(map(int,input().split()))
s = input().rstrip()
lis=[0]*N
 
count = 0
for i in range(1,len(s)):
    if s[i-1] == 'A' and s[i] == 'C':
        count +=1
    lis[i]+=count
for i in range(Q):
    l,r = list(map(int,input().split()))
    print(lis[r-1]-lis[l-1])

Solution (Python):
def ss():
    N,Q = list(map(int,input().split()))
    s = input()
    lis=[0]*N
     
    count = 0
    for i in range(1,len(s)):
        if s[i-1] == 'A' and s[i] == 'C':
            count +=1
        lis[i]+=count
    for i in range(Q):
        l,r = list(map(int,input().split()))
        print(lis[r-1]-lis[l-1])

ss()

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

Solution (Python):
import re
 
N,Q = list(map(int,input().split()))
s = input()
lis=[0]*N
 
count = 0
for i in range(1,len(s)):
    if s[i-1] == 'A' and s[i] == 'C':
        count +=1
    lis[i]+=count
for i in range(Q):
    l,r = list(map(int,input().split()))
    print(lis[r-1]-lis[l-1])

Solution (Python):
import re
 
N,Q = list(map(int,input().split()))
s = input()
lis=[0]
 
count = 0
for i in range(1,len(s)):
    if s[i-1] == 'A' and s[i] == 'C':
        count +=1
    lis.append(count)
for i in range(Q):
    l,r = list(map(int,input().split()))
    print(lis[r-1]-lis[l-1])

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

cnt = [0]*N
i = 0
while i < N-1:
    if S[i:i+2] == "AC":
        cnt[i] += 1
        i += 1
    i += 1

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

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

Solution (Python):
n,q=map(int,input().split())
s=input()
num=[0]
for i in range(n-1):
    if s[i+1]=="C" and s[i]=="A":
        num.append(num[-1]+1)
    else:
        num.append(num[-1])
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()
l = []
r = []
for q in range(Q):
    a,b = map(int, input().split())
    l.append(a)
    r.append(b)

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

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

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

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

a=[0]*n
from collections import defaultdict
tail=defaultdict(int)
for i in range(n-1):
    if t[i]=="A"and t[i+1]=="C":
        a[i+1]+=1
        tail[i]+=1
from itertools import accumulate
a=list(accumulate(a))
for _ in range(q):
    l,r=map(int,input().split())
    l,r=l-1,r-1
    if l==0:print(a[r])
    else:
        print(a[r]-a[l-1]-tail[l-1])

Solution (Python):
def resolve():
    import sys
    input = sys.stdin.readline
    N, Q = [int(i) for i in input().split()]
    S = input()
    pre = [0 for _ in range(N)]
    for i in range(N - 1):
        pre[i + 1] = pre[i] + (1 if S[i:i + 2] == "AC" else 0)
    for _ in range(Q):
        l, r = [int(i) for i in input().split()]
        print(pre[r - 1] - pre[l - 1])


resolve()

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

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

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

Solution (Python):
N, Q = map(int, input().split())
S = ['0'] + list(input())
C = [0] * len(S)
c = 0
for i in range(1, len(S)):
    if S[i-1] == "A" and S[i] == "C":
        c += 1
    C[i] = c
for _ in range(Q):
    l, r = map(int, input().split())
    print(C[r] - C[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):
N,Q=map(int,input().split())
S=input()
tot=[0]
for i in range(N-1):
    if S[i:i+2]=="AC":
        tot.append(tot[-1]+1)
    else:
        tot.append(tot[-1])

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

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

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

for k in range(Q):
  print(dp[R[k]-1]-dp[L[k]-1])

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

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

for k in range(Q):
  print(dp[R[k]-1]-dp[L[k]-1])

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

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


cumSum = [0] * (N + 1)

cnt = 0

for i in range(1, N):
    pre = S[i - 1]
    now = S[i]

    if pre == "A" and now == "C":
        cnt += 1

    cumSum[i + 1] = cnt
    pre = now

for l, r in lr:
    print(cumSum[r] - cumSum[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):
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()
s += ' '
ruiseki = []
i = 0
while i<n:
    if s[i]+s[i+1]=='AC':
        ruiseki.append('')
        ruiseki.append('AC')
        i= i+1
    else:
        ruiseki.append(s[i])
    i+=1
t = [0] * (n+1)
for i in range(n):
    if ruiseki[i] == '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]-t[l])

Solution (Python):
import bisect
def main():
    N, Q = map(int, input().split())
    S = input()
    ll = []
    t = -1
    for i, v in enumerate(S):
        if v == 'A':
            t = i
        elif v == 'C':
            if t == i-1:
                ll.append(i)
                t = -1
    for _ in range(Q):
        l, r = map(int, input().split())
        l -= 1
        r -= 1
        li = bisect.bisect_right(ll, l)
        ri = bisect.bisect_right(ll, r)
        print(ri-li)
main()

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

ac_cnts = [0]*(n)
curr_cnt = 0
for i, (s1,s2) in enumerate(zip(s[:-1],s[1:])):
    if s1 == 'A' and s2 == 'C':
        curr_cnt += 1
    ac_cnts[i+1] = curr_cnt

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




for a in ans:
    print(a)

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

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

cumSum = [0]*(n+1)
pre = s[0]
cnt = 0
for i in range(1,n):
    now = s[i]
    if pre=="A" and now=="C":
        cnt += 1
    cumSum[i+1] = cnt
    pre = now
for l,r in lr:
    print(cumSum[r]-cumSum[l])