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):
class SegmentTree:
    def __init__(self, n, init_val, ide_ele=0):
        self.num = 2 ** (n - 1).bit_length()
        self.seg = [ide_ele] * 2 * self.num
        self.ide_ele = ide_ele
        for i in range(n):
            self.seg[i + self.num - 1] = init_val[i]
        for i in range(self.num - 2, -1, -1):
            self.seg[i] = self.seg_func(self.seg[2 * i + 1], self.seg[2 * i + 2])

    def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k:
            k = (k - 1) // 2
            self.seg[k] = self.seg_func(self.seg[2 * k + 1], self.seg[2 * k + 2])

    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = self.seg_func(res, self.seg[p])
            if q & 1 == 1:
                res = self.seg_func(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.seg_func(res, self.seg[p])
        else:
            res = self.seg_func(self.seg_func(res, self.seg[p]), self.seg[q])
        return res

    def seg_func(self, x, y):
        return x + y


def p_c():
    n, q = map(int, input().split())
    s = input().replace("AC", "01")
    li = list(map(lambda x: 1 if x == "0" else 0, s))
    seg = SegmentTree(n, li)
    ans = []
    for _ in range(q):
        l, r = map(int, input().split())
        ans.append(str(seg.query(l - 1, r - 1)))
    print("\n".join(ans))
    
p_c()

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

count_list = []
bef_str = ''
bef_count = 0

for x in s:
  if bef_str == 'A' and x == 'C':
    bef_count += 1
    
  count_list.append(bef_count)
  bef_str = x
    
for i in range(q):
  l, r = (int(i) for i in input().split())
  print(count_list[r-1] - count_list[l-1])

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

s = input()

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

for i in range(len(s)-1):
	if s[i] == 'A' and s[i+1] == 'C':
		arr[i+2] += 1

for i in range(1, len(arr)):
	arr[i] = arr[i-1] + arr[i]

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

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

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

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

sum_list = [0]







[sum_list.append(sum_list[-1]+1) if s == 'C' and S[i-1] == 'A' else sum_list.append(sum_list[-1]) for i, s in enumerate(S)]

for l, r in lr_list:
    print(sum_list[r] - sum_list[l])

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

sum_list = [0]

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



for l, r in lr_list:
    print(sum_list[r] - sum_list[l])

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

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

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

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

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

for j in range(q):
    l, r = list[j]
    print(ans_list[r-1]-ans_list[l-1])

Solution (Python):
import collections

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

new_S = S.replace("AC", "12")


count_one_list = [0] * len(S)
for i in range(len(S)-1):
    if new_S[i] == '1' and i == 0:
        count_one_list[i+1] += 1
    elif new_S[i] == '1':
        count_one_list[i+1] = count_one_list[i] + 1
    else:
        count_one_list[i+1] = count_one_list[i]



for i in range(Q):
    left, right = map(int, input().split())
    count_one = count_one_list[right-1] - count_one_list[left-1]
    print(count_one)

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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
def print_ans(N, Q, S, arr):
    """Test Case
    >>> print_ans(8, 3, "ACACTACG", [[3, 7], [2, 3], [1, 8]])
    2
    0
    3
    """
    t = [0] * (N+1)
    for i in range(N):
        t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)
    for ar in arr:
        print(t[ar[1] - 1] - t[ar[0] - 1] )

if __name__ == '__main__':
    N, Q = map(int, input().rstrip().split())
    S = input().rstrip()
    arr = [list(map(int, input().rstrip().split())) for _ in range(Q)]
    print_ans(N, Q, S, arr)

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

Solution (Python):
def main():
    import sys
    import re
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    dp = [0] * N
    for i in range(1,N):
        if S[i] == "C" and S[i-1] == "A":
            dp[i] = dp[i-1] + 1
        else:
            dp[i] = dp[i-1]
    for j in range(Q):
        l,r = L[j]
        print(dp[r-1] - dp[l-1])
if __name__ == '__main__':
    main()

Solution (Python):
N, Q = map(int, input().split())
S = input()
W = [0 for i in range(N + 1)]
AC = [False for b in range(N + 1)]
for i in range(1, N):
    if S[i] == 'C' and S[i - 1] == 'A':
        W[i + 1] = W[i] + 1
        AC[i] = True
    else:
        W[i + 1] = W[i]

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

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

count_sum_list = [0]*(N+1)
start_A_pointa = [0]*(N+1)

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


output_list = []

for _ in range(Q):
    l,r = map(int,input().split(' '))
    if start_A_pointa[r] == 1:
        output_list.append(count_sum_list[r]-count_sum_list[l-1] -1)
    else:
        output_list.append(count_sum_list[r]-count_sum_list[l-1])

for out in output_list:
    print(out)

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

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

for i in range(Q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    ans = W[r + 1] - W[l]
    if l > 0 and S[l - 1] == 'A' and S[l] == 'C':
        ans -= 1
    print(ans)

Solution (Python):
import sys
def main():
    n, q = map(int, sys.stdin.readline().split())
    s = sys.stdin.readline().rstrip()
    lr = map(int, sys.stdin.read().split())
    lr = list(zip(lr, lr))

    cumsum = [None] * (n + 1)
    cumsum[0] = 0

    flag = False
    for i in range(n):
        t = s[i]
        if t == 'A':
            flag = True
            cumsum[i+1] = cumsum[i]
        else:
            if t == 'C' and flag:
                cumsum[i+1] = cumsum[i] + 1
            else:
                cumsum[i+1] = cumsum[i]
            flag = False

    for l, r in lr:
        res = cumsum[r] - cumsum[l]
        print(res)

if __name__ == "__main__":
    main()

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

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

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


def main():
    N, Q = [int(x) for x in input().split()]
    S = input().strip()

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

    for _ in range(Q):
        x, y = [int(x) for x in input().split()]
        l = bisect.bisect_left(ac, x - 1)
        r = bisect.bisect_right(ac, y - 2)
        print(r - l)

    
    




if __name__ == '__main__':
    main()

Solution (Python):
import bisect
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())
cnt=[]
ans=0
a=[]
a1=[]
for j in range(1,n):
    if s[j-1]+s[j]=='AC':
        ans+=1
        a.append(j-1)
        a1.append(j)
        cnt.append([j-1,j,ans])
for k in range(q):
    print(bisect.bisect_right(a1,r[k]-1)-bisect.bisect_left(a,l[k]-1))

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

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

Solution (Python):

from itertools import accumulate


N, Q = list(map(int, input().split()))
S = input()
A = [list(map(int, input().split())) for i in range(Q)]

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

flg2 = [0] + flg
flg2 = list(accumulate(flg2))

for a in A:
    print(flg2[a[1]-1] - flg2[a[0]-1])

Solution (Python):



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

L = []
R = []

for i in range(q):
    a,b = map(int, input().split())
    L.append(a)
    R.append(b)


ans = [0]

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

        
for i in range(q):
    print(ans[R[i]-1]-ans[L[i]-1])

Solution (Python):

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

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()
lr = [tuple(map(int, input().split())) for _ in range(Q)]
ac_indexes = [0]
ac = 0
for i in range(1, N):
    if S[i - 1] == "A" and S[i] == "C":
        ac += 1
    ac_indexes.append(ac)
for l, r in lr:
    print(ac_indexes[r - 1] - ac_indexes[l - 1])

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

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

ac=[0]*n 
ac[0]=0
def isac(i):
  if s[i]=='A' and s[i+1]=='C':
    return 1
  else:
    return 0
ac[1]=isac(0)
for i in range(n-1):
    ac[i+1] = ac[i] + isac(i)
for i in range(q):
  print(ac[r[i]-1]-ac[l[i]-1])

Solution (Python):
n,q = map(int, input().split())
import bisect
str = list(input())
index = []
for i in range(n-1):
    if str[i] == "A" and str[i+1] == "C":
        index.append(i)
index.sort()
li = []
counter = 0
for i in range(q):
    s,t = map(int, input().split())
    head = bisect.bisect_left(index, s-1)
    tail = bisect.bisect_left(index, t-1)
    print(tail - head)

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

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

for i in range(q):
      print(L2[L[i][1]-1]-L2[L[i][0]-1])

Solution (Python):
N, Q = map(int, input().split())
S = input()
lr = [tuple(map(int, input().split())) for _ in range(Q)]
acindex_list = []
ac = 0
old = ""
for c in S:
    if old == "A" and c == "C":
        ac += 1
    old = c
    acindex_list.append(ac)
for l, r in lr:
    print(acindex_list[r - 1] - acindex_list[l - 1])

Solution (Python):
import sys

input = sys.stdin.readline

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

if __name__ == '__main__':
    main()

Solution (Python):
N,Q = input().split()
N,Q = int(N),int(Q)
S = input()
l,r = [],[]
for i in range(Q):
    l_,r_ = input().split()
    l_,r_ = int(l_)-1,int(r_)-1
    l.append(l_)
    r.append(r_)
    
A = [0]
sum_ = 0
for i in range(1,N):
    if(S[i-1]=="A" and S[i]=="C"):
        sum_ += 1
    A.append(sum_)

for i in range(Q):
    if(l[i]==0):
        num = r[i]
        print(A[r[i]])
    else:
        sa = A[r[i]]-A[l[i]]
        print(sa)

Solution (Python):
import bisect

n,q = map(int,input().split())
s = input()
l=[]
r=[]
a = []
c = []
for i in range(q):
    l1,r1 = map(int,input().split())
    l.append(l1)
    r.append(r1)
for i in range(n-1):
    if s[i] + s[i+1] == 'AC':
        a.append(i+1)
        c.append(i+2)
for i in range(q):
    ans = 0
    ans = bisect.bisect_right(c,r[i]) - bisect.bisect_left(a,l[i])
    print(ans)

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

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

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

cum_counts=[0]*n
for i in range(1,n):
  cum_counts[i]=cum_counts[i-1]+counts[i-1]




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

Solution (Python):
from itertools import accumulate

N, Q = map(int, input().split())
S = input()
A = [list(map(int, input().split())) for i in range(Q)]



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


ans = []
ans = [0] + flg 
ans = list(accumulate(ans)) 


for li in A:
    print(ans[li[1]-1] - ans[li[0]-1] )

Solution (Python):
n,q = map(int,input().split())
s = input()
l = []
r = []
for i in range(q):
    li,ri = map(int,input().split())
    l.append(li)
    r.append(ri)
  
al = [0]*n
for i in range(1,n):
    if s[i-1] == "A" and s[i] == "C":
        al[i] = al[i-1] + 1
    else:
        al[i] = al[i-1]
        
for j in range(q):
    left = l[j]-1
    right = r[j]-1
    print(al[right]-al[left])

Solution (Python):
N,Q = [int(i) for i in input().split()]
S = str(input())
lrlist = []
for i in range(Q):
    lrlist.append([int(i)-1 for i in input().split()])




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


for l,r in lrlist:
    print(Asite[r]-Asite[l])

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

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

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

Solution (Python):
N,Q=map(int,input().split())
S=input()
cs=[0]*N
cnt=0
for i in range(1,len(S)):
  if S[i-1]=="A" and S[i]=="C":
    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 = map(int,input().split())
s = input()
    
ans = 0
ls = [0]
for i in range(len(s)-1):
    if s[i] == "A" and s[i+1] == "C":
        ans += 1
        ls.append(1+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):
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for i in range(Q)]

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

Solution (Python):
n,m=map(int,input().split())
l=list(input())
count=0
clist=[0]
for i in range(1,n):
  if l[i-1]=="A" and l[i]=="C":
    count+=1
  clist.append(count)
for i in range(m):
  i1,i2=map(int,input().split())
  if i1==1:
    ans=clist[i2-1]
  elif l[i1-1]=="C" and l[i1-2]=="A":
    ans=clist[i2-1]-clist[i1-2]-1
  else:
    ans=clist[i2-1]-clist[i1-2]
  print(ans)

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

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

Solution (Python):
tmp = list(map(int, input().split()))
n = tmp[0]
q = tmp[1]
s = input()

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

ans = []
for i in range(q):
  tmp = list(map(int, input().split()))
  l = tmp[0]
  r = tmp[1]
  ans.append(acc[r-1] - acc[l-1])

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

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

Solution (Python):

N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
cnt_list = [0] * N
tmp = 0
for i in range(N-1):
    cnt_list[i] = tmp
    if S[i] == "A" and S[i+1] == "C":
        tmp += 1
cnt_list[N-1] = tmp

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

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

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

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

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

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

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

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

	tmp = S[i-1]

for l,r in Q:
	ans = cnt[r] - cnt[l-1]

	if S[l-2] == "A" and S[l-1] == "C":
		ans -= 1

	print(ans)

Solution (Python):
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[0]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

for j in range(0,n-1):
  if s[j]=="A" and s[j+1]=="C":
    ans+=1
    x.append(ans)
  else:
    x.append(ans)

for k in range(0,q):
  print(x[r[k]-1]-x[l[k]-1])

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

for i in range(1,N):
  if S[i-1:i+1]=="AC":
    cnt=cnt+1
  T.append(cnt)
for j in range(Q):
  print(T[R[j]-1]-T[L[j]-1])

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

sl = list(input())

pointl = []
point = 0
before_s = ""
for s in sl:
    if before_s == "A" and s=="C":
        point += 1
    before_s = s
    pointl.append(point)
    
for _ in range(q):
    l,r = map(int,input().split())
    print(pointl[r-1] - pointl[l-1])

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


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

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

Solution (Python):
n, q = map(int, input().split())
S = list(input())
num = [0 for _ in range(len(S))]
tmp = 0
for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        tmp += 1
    num[i + 1] = tmp
ans = [0 for _ in range(q)]
for i in range(q):
    l, r = map(int, input().split())
    ans[i] = str(num[r - 1] - num[l - 1])
print('\n'.join(ans))

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


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

    prev = buf[i+1]



for _ in range(Q):
    l, r = list(map(lambda x: int(x), input().split(' ')))
    l -=1
    r -=1
    ans = buf[r] - buf[l]
    print(ans)

Solution (Python):
def main():
    n,q = map(int, input().split())
    S = input()
    N = [0]*(n+1)

    for i in range(n):
        N[i+1] += N[i]
        if S[i:i+2] == 'AC':
            N[i+1] += 1
    for i in range(q):
        l,r = map(int,input().split())
        print(N[r-1]-N[l-1])


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

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

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

for q in range(Q):
    q_l, q_r = map(int, input().split())
    ans.append(t[q_r-1]-t[max(q_l-1, 0)])

for a in range(Q):
    print(int(ans[a]))

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

for i in range(N):
    if S[i] == 'A':
        cnt = 1
    elif S[i] == 'C':
        if cnt == 1:
            cnt = 0
            num += 1
    else:
        cnt = 0
    check.append(num)

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

Solution (Python):
from itertools import accumulate
N, Q =map(int, input().split())
s = input()
AC = [0]*(N-1)
for i in range(N-1):
  if s[i:i+2] == 'AC':
    AC[i] = 1   
B = [0] +AC
B = list(accumulate(B))
for i in range(Q):
  l,r = map(int, input().split())
  print(B[r-1]-B[l-1])

Solution (Python):
from itertools import accumulate
N, Q =map(int, input().split())
s = input()

lr = [[int(i) for i in input().split()] for i in range(Q)] 

AC = [0]*(N-1)

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

B = [0] +AC
B = list(accumulate(B))
for i in lr:
  print(B[i[1]-1]-B[i[0]-1])

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

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

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

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

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

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

ans = [0] * N

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

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

Solution (Python):
from sys import stdin
import bisect

n,q = [int(x) for x in stdin.readline().rstrip().split()]
s = stdin.readline().rstrip()
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(q)]
lin = []
point = 0
for i in range(n-1):
    if s[i] + s[i+1] == "AC":
        lin.append(i+1)
for j in range(q):
    hi = bisect.bisect(lin,li[j][1]-1)
    lo = bisect.bisect(lin,li[j][0]-1)
    print(hi-lo)

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):
import sys

N, Q = map(int, input().split())
S = input()
P = [[int(v) - 1 for v in sys.stdin.readline().split()] for _ in range(Q)]
X = [0] * (N + 1)

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


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

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

ans = [0 for _ in range(n)]

for i in range(n-1):
    if string[i] == 'A' and string[i+1] == 'C':
        ans[i+1] = ans[i] +1
    else:
        ans[i+1] = ans[i]
        
for x,y in l:
    print(ans[y-1] - ans[x-1])

Solution (Python):

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

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

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

Simos = [0] * n
Simos[0] = Sev[0]
for i in range(1, n):
  Simos[i] = Simos[i-1] + Sev[i]
    
for i in range(q):
  l, r = map(int, input().split())
  l = l-1
  r = r-1
  r = r-1
  if l == 0:
    print(Simos[r])
  else:
    print(Simos[r] - Simos[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()



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





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

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

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

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

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


def count_from_first(l, r):
    return from_first[r] - from_first[l]


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

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

Solution (Python):
from itertools import accumulate
N, Q = map(int,input().split())
S = [1 if i=='1' else 0 for i in input().replace("AC","10")]
s = list(accumulate(S))
lr = []
for i in range(Q):
    lr.append(tuple(map(int,input().split())))
for i in lr:
    l = s[i[0]-2] if i[0]-2 >= 0 else 0
    r = s[i[1]-2] if i[1]-2 >= 0 else 0
    print(r-l)