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()
a=[0,0]
for l in range(1,n):
    if s[l-1]=='A' and s[l]=='C':
        a.append(a[l]+1)
    else :
        a.append(a[l])
for k in range(q):
    x,y=map(int,input().split())
    print(a[y]-a[x])

Solution (Python):
N,K = map(int,input().split())
moji = str(input())
ans = [0]
for i in range(N-1):
    if moji[i] == "A" and moji[i+1] == "C":
        ans.append(ans[i]+1)
    else:
        ans.append(ans[i])

        
for i in range(K):
    st,sp = map(int,input().split())
    print(ans[sp-1]-ans[st-1])

Solution (Python):

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


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

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

Solution (Python):

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


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

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

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

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

Solution (Python):
import bisect
n,q = map(int, input().split(" "))
s = input()
lr = [list(map(int, input().split(" "))) for i in range(q)]
a = []
for i in range(n-1):
  if s[i] +s[i+1]== 'AC':
    a.append(i+1)
for l, r in lr:
  print(bisect.bisect(a, r-1) - bisect.bisect(a, l-0.1))

Solution (Python):
n, q = map(int, input().split())
s = input()
ls = [list(map(int, input().split())) for i in range(q)]
d = [0]
pre = 0
c = 0

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



for start, end in ls:
    print(d[end-1]-d[start-1])

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

result=[0]
cnt=0
for i in range(1,len(s)):
	if s[i-1]+s[i]=="AC":
		cnt+=1
		result.append(cnt)
	elif s[i-1]+s[i]!="AC":
		result.append(cnt)
        

for a,b in arr:
	print(result[b-1]-result[a-1])

Solution (Python):
import sys

input = sys.stdin.readline

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

S = input()
S = S.replace('\n','')
s_list = list(S)

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

ac_sum_list = [0 for i in range(len(s_list))]
tmp = ""
ac_sum = 0
for i,s in enumerate(s_list):
    if tmp + s == "AC":
        ac_sum += 1
    ac_sum_list[i] = ac_sum
    tmp = s


for i in range(q):
    l_index = l[i]
    r_index = r[i]
    l_ac = ac_sum_list[l_index-1]
    r_ac = ac_sum_list[r_index-1]
    print(r_ac - l_ac)

Solution (Python):

N, Q = map(int, input().split())
S = input()
dl=[]
dr=[]
for i in range(Q):
    line = list(map(int, input().split()))
    dl.append(line[0])
    dr.append(line[1])


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


s = [0]
for i in range(len(a)):
    s.append(s[i]+a[i])


ans=[]
for l, r in zip(dl, dr):
    ans.append(s[r-1]-s[l-1])

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

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

class bit:
  def __init__(self, N):
    self.__N = N
    self.__a = [0] * N
  def add_(self, x, v):
    x += 1
    while x < self.__N:
      self.__a[x] += v
      x += x & -x
  def show_(self):
    print(self.__a[1:])
    
  def sum_(self, x):
    ans = 0
    while x > 0:
      ans += self.__a[x]
      x -= x & -x
    return ans
  def sub_sum_(self, x, y):
    return self.sum_(y) - self.sum_(x)
prev = "0"
BIT = bit(N)
for i, val in enumerate(S):
  if prev == "A" and val == "C":
    BIT.add_(i-1, 1)
  prev = val
for i in range(Q):
  x, y = map(int, input().split())
  x -= 1
  y -= 1
  print(BIT.sub_sum_(x,y))

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

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

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


if __name__ == '__main__':
    main()

Solution (Python):

N,Q = map(int,input().split())
S = input()
L = []
R = []
for _ in range(Q):
    l,r = map(int,input().split())
    l -= 1;r -= 1
    L.append(l)
    R.append(r)


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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    for i in ans:
        print(i)

main()

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

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

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

for x in a:
  print(c[x[1]-1]-c[x[0]-1])

Solution (Python):
n,q = map(int,input().split())
s = input()
cnt = [0]*n
for i in range(1,n):
    cnt[i] += cnt[i-1]
    if s[i-1:i+1] == "AC":
        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=input()
cnt=[0,0]
for i in range(1,N):
    cnt.append(cnt[-1]+S[i-1:i+1].count("AC"))
for _ in range(Q):
    l,r=map(int,input().split())
    print(cnt[r]-cnt[l])

Solution (Python):
from itertools import accumulate

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

ac_list = [0]*n

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

ac_sum = list(accumulate(ac_list))

for l, r in lr:
    l -= 1
    r -= 1
    if l == 0:
        print(ac_sum[r-1])
        continue
    print(ac_sum[r-1] - ac_sum[l-1])

Solution (Python):

"""
Created on Mon Sep 14 00:57:13 2020

@author: liang
"""

N, Q = map(int, input().split())
S = input()
S += "a"
d = [0]*(N+1)
count = 0
for i in range(len(S)-1):
    if S[i:i+2] == "AC":
        count += 1
    
    d[i+1] = count


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

Solution (Python):
N, Q = map(int, input().split())
S = input()
t = [0 for _ in range(len(S)+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

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


if __name__ == '__main__':
    main()

Solution (Python):



import sys

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

S = input()

cum_ls = [0]

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



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

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

count = [0] * N

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

accum = count.copy()
for i in range(1, N):
	accum[i] += accum[i-1]

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

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

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

for i in range(q):
    st,fn = map(int,input().split())
    print(lr[fn-1] - lr[st-1])

Solution (Python):
class SegmentTree:
    def __init__(self, data, default=0, func=max):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()

        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])

    def __delitem__(self, idx):
        self[idx] = self._default

    def __getitem__(self, idx):
        return self.data[idx + self._size]

    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1

    def __len__(self):
        return self._len

    def query(self, start, stop):
        """func of data[start, stop)"""
        start += self._size
        stop += self._size

        res_left = res_right = self._default
        while start < stop:
            if start & 1:
                res_left = self._func(res_left, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res_right = self._func(self.data[stop], res_right)
            start >>= 1
            stop >>= 1

        return self._func(res_left, res_right)

    def __repr__(self):
        return "SegmentTree({0})".format(self.data)


def f(tup1,tup2):
    tot=tup1[1]+tup2[1]
    if tup1[2]==1 and tup2[0]==1:
        tot+=1
    a=tup1[0]
    b=tup2[2]
    return (a,tot,b)



n,q=map(int,input().strip().split(" "))
s=input()
ar=[]
for i in s:
    if i=="A":
        ar.append((0,0,1))
    elif i=="C":
        ar.append((1, 0, 0))
    else:
        ar.append((0,0,0))
defa=(0,0,0)
seg=SegmentTree(ar,defa,f)
for _ in range(q):
    a,b=map(int,input().strip().split(" "))
    k=seg.query(a-1,b)
    print(k[1])

Solution (Python):
n,q = map(int,input().split())
s = input()
cnt = [0]*n
for i in range(1,n):
    cnt[i] += cnt[i-1]
    if s[i-1:i+1] == "AC":
        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 = input()
flag = False
L = [0 for _ in range(n)]
cnt = 0
for i, s in enumerate(S):
    if flag:
        if s == "C":
            cnt += 1
        flag = False
    if s == "A":
        flag = True
    L[i] = cnt

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

Solution (Python):
from sys import stdin

n,q = map(int,stdin.readline().split())
s = input()
lr = [list(map(int,stdin.readline().split())) for i in [0]*q]

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

idx = 0
loc = 0
numac = [0 for i in [0]*n]
for i in range(n):
    if posac[idx]==i:
        loc += 1
        idx += 1
    numac[i] = loc
numac.append(loc)


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

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


s = input()

v = [0] * n

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

m = [0] * (n + 1)
for i in range(n):
    m[i + 1] = m[i] + v[i]


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

Solution (Python):
import sys

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

cnt = [0]*(N+1)
wasA = False

for i in range(0,N):
  if wasA and S[i] == "C":
    cnt[i+1] = cnt[i] + 1
    wasA = False
  elif S[i] == "A":
    cnt[i+1] = cnt[i]
    wasA = True
  else:
    cnt[i+1] = cnt[i]
    wasA = False



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

Solution (Python):
a,b=map(int,input().split())
n = input()
m = [0]*a
for i in range(1,a):
  if n[i-1:i+1]=="AC":
    m[i]=m[i-1]+1
  else:
    m[i]=m[i-1]
for j in range(b):
  s,t=map(int,input().split())
  print(m[t-1]-m[s-1])

Solution (Python):








def solve(N, Q, S, LRi):
    cumulative_sum = [0, 0]
    for i in range(1, N):
        tmp = cumulative_sum[-1]
        if S[i - 1:i + 1] == 'AC':
            tmp += 1
        cumulative_sum.append(tmp)

    for l, r in LRi:
        print(cumulative_sum[r] - cumulative_sum[l])


if __name__ == '__main__':
    N, Q = map(int, input().split())
    S = input()
    LRi = [[int(i) for i in input().split()] for _ in range(Q)]
    solve(N, Q, S, LRi)

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

cum = [0]*(N+1)

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

ans = []
for l, r in LR:
    result = cum[r-1] - cum[l-1]
    ans.append(result)

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

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

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

lsAC = [0,0]
AC = 0
for i in range(N-1):
    if S[i]=='A' and S[i+1]=='C':
        AC += 1
    lsAC.append(AC)
for i in range(Q):
    print(lsAC[lsline[i][1]]-lsAC[lsline[i][0]])

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

Solution (Python):
n,q=map(int,input().split())
s=input()
con=[0]
c=False
for i in range(n):
    if s[i]=='A':
        c=True
        con.append(con[-1])
        continue
    if c:
        if s[i]=='C':
            con.append(con[-1]+1)
            c=False
            continue
        else:
            con.append(con[-1])
            c=False
            continue
    con.append(con[-1])    
for j in range(q):
    l,r=map(int,input().split())
    print(max(0,con[r]-con[l]))

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

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

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

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

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

for i in range(q):
  print(rui[lr[i][1]-1] - rui[lr[i][0]-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 j 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()
R = [0]*(N+1)
A = False
C = False
for i in range(0,N):
  char = S[i]
  if char == 'A':
    A = True
  elif char == 'C' and A:
    R[i+1]+=1
    A = False
  else:
    A = False
  R[i+1]+=R[i]
for _ in range(Q):
  l, r = map(int,input().split())
  print(R[r]-R[l])

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


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


for _ in range(Q):
    l, r = map(int, input().split())
    l -= 1
    result = c[r] - c[l]
    if l > 0 and S[l-1:l+1] == 'AC':
        result -= 1
    print(result)

Solution (Python):
N,Q=map(int,input().split())
S=input()
li=[0]
A=False
ans=0
import copy
for i in range(N):
    if A==True:
        if S[i]=="C":
            ans+=1
        A=False
    if S[i]=="A":
        A=True
    li.append(copy.copy(ans))
for j in range(Q):
    a,b=map(int,input().split())
    print(li[b]-li[a])

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


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

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

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

F=[0]*len(S)
for i in range(N-1):
    F[i+1]+=F[i]+(1 if S[i:i+2]=='AC' else 0)
    
for l,r in LR:
    print(F[r-1]-F[l-1])

Solution (Python):

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

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

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

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

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

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

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

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

Solution (Python):
N, Q = map(int, input().split())
S = input()
A = []
for i in range(N - 1):
  if S[i] == "A" and S[i+1] == "C":
    A.append(i+1)
lA = len(A)
for i in range(Q):
  l, r = map(int, input().split())
  L1 = -1
  R1 = lA
  while L1 + 1 < R1:
    C1 = (L1 + R1) // 2
    if A[C1] < l:
      L1 = C1
    else:
      R1 = C1
  L2 = -1
  R2 = lA
  while L2 + 1 < R2:
    C2 = (L2 + R2) // 2
    if A[C2] < r:
      L2 = C2
    else:
      R2 = C2
  print(L2 - L1)

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

a = [0] * N
c = 0

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

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

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

nums = [0]*n
for i in range(1,n):
  if s[i] == "C":
    if s[i-1] == "A": nums[i] += 1
  nums[i] += nums[i-1]
  
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()
ans = []
a = [0]*(10**5+1)
add = 0
check = False
for i in range(n):
    if check and s[i] == 'C':
        add +=1
    if s[i] == 'A':
        check = True
    else:
        check = False
    
    a[i] += add
for i in range(q):
    b,c = map(int,input().split())
    ans.append(a[c-1]-a[b-1])
for i in range(q):
    print(ans[i])

Solution (Python):
def examA():
    N = DI()/dec(7)
    ans = N
    print(N)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    N, Q = LI()
    S = SI()
    SS = [0]*N
    SSS = [0]*N
    for i in range(N-1):
        if S[i]=="A" and S[i+1]=="C":
            SS[i] = 1
    for i in range(N-1):
        SSS[i+1] += SSS[i]+SS[i]
    ans = [0]*Q

    for q in range(Q):
        l,r = LI()
        l -= 1; r -= 1
        ans[q] = SSS[r] - SSS[l]

    for v in ans:
        print(v)
    return

def examD():
    ans = 0
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

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


cum_sum = [0] * N
count_AC = [0] * N

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

        count_AC[i+1] = 2
        cum_sum[i+1] = 2
    cum_sum[i+1] = cum_sum[i] + cum_sum[i+1]


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

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 j in range(Q):
  l,r = map(int,input().split())
  print(t[r-1] - t[l-1])

Solution (Python):

def input2():
	return map(int,input().split())


def input_array():
	return list(map(int,input().split()))
  
n,q=input2()
B=str(input())
LR=[input_array() for _ in range(q)]


T=[0]*(n+1) 

for i in range(n):
	if B[i:i+2] == "AC":	
		T[i+1] = T[i]+1
	else:
		T[i+1]=T[i]
for lr in LR:
	st=lr[0]-1
	fi=lr[1]-1
	print(T[fi]-T[st])

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

Solution (Python):
from bisect import bisect_left
n, q = map(int, input().split())
s = list(input())
L = []
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        L.append(i)
ans = []
for i in range(q):
    l, r = map(int, input().split())
    l, r = l - 1, r - 1
    st = bisect_left(L, l)
    fi = bisect_left(L, r)
    ans.append(fi - st)

for i in ans:
    print(i)

Solution (Python):
from bisect import bisect_left
n, q = map(int, input().split())
s = list(input())
L = []
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        L.append(i)
ans = []
for i in range(q):
    l, r = map(int, input().split())
    l, r = l - 1, r - 1
    st = bisect_left(L, l)
    fi = bisect_left(L, r)
    ans.append(fi - st)

for i in ans:
    print(i)

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

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

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

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

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

Solution (Python):


import sys


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


n, q = [int(i) for i in input().split()]
S = input()

ac_table = [0] * (n + 1)  

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

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

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




c = [0] * N
cnt = 0

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



for i,j in zip(l,r):
    
    
    print(c[j-1]-c[i-1])

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




c = [0] * N
cnt = 0

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



for i,j in zip(l,r):
    
    
    print(c[j-1]-c[i-1])

Solution (Python):
N,Q=map(int,input().split())
S=input()
L=[0]*N
p=S[0]
for i in  range(1,N):
  L[i]+=L[i-1]
  if p+S[i]=='AC':
    L[i]+=1
  p=S[i]
for _ in range(Q):
  i,j=map(int,input().split())
  print(L[j-1]-L[i-1])

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,q = LI()
    s = "$" + S()

    lst = [0 for _ in range(n+1)]
    for i in range(n):
        before = s[i]
        after = s[i+1]
        if before == "A" and after == "C":
            lst[i+1] = lst[i] + 1
        else:
            lst[i+1] = lst[i]
    for _ in range(q):
        l,r = LI()
        ans = lst[r] - lst[l]
        print(ans)
main()

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

dp=[[0]*2 for _ in range(N)]
if S[0]=='A':
    dp[0][1]=1

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


for i in range(Q):
    l,r=list(map(int, input().split()))
    if l==1:
        print(dp[r-1][0]) 
    elif S[l-2]=='A' and S[l-1]=='C':
        print(dp[r-1][0]-dp[l-2][0]-1)
    else:
        print(dp[r-1][0]-dp[l-2][0])

Solution (Python):

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

n = len(S)
ctr = [0] * n
for i in range(n):
    if i > 0 and S[i - 1] == "A" and S[i] == "C":
        ctr[i] = 1

cumsum = [0] * (n + 1)
for i in range(n):
    cumsum[i + 1] = cumsum[i] + ctr[i]

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

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