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

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

f = [0]
for i in range(1,int(N)):
  if (s[i-1]== 'A')&(s[i] == 'C'):
    f.append(f[i-1]+1)
  else :
    f.append(f[i-1])
  
for i in range(int(Q)):
  a,b = map(int,input().split(' '))
  print(f[b-1]-f[a-1])

Solution (Python):
n, q = tuple(int(i) for i  in 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 i in range(q):
    l, r = tuple(int(i) for i  in input().split(' '))
    print(c[r - 1] - c[l - 1])

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

count = 0
counts = []
prev = ''
for c in list(s):
    if prev + c == 'AC':
        count += 1
    counts.append(count)
    prev = c

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

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

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

atgc_list= []

flag = 0
memo =0

for i in range (len(S)):
    if S[i]=='A':
        flag = 1
    elif flag == 1 and S[i] == 'C':
        memo+=1
        flag = 0
    elif S[i] in ['T','G','C']:
        flag = 0
    atgc_list.append(memo)
        

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

Solution (Python):
import sys

n, q = map(int, sys.stdin.readline().split())
s = sys.stdin.readline()

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

for i in range(q):
    l, r = map(int, sys.stdin.readline().split())
    print(elist[r] - elist[l])

Solution (Python):
import sys

n, q = map(int, sys.stdin.readline().split())
s = sys.stdin.readline()

mlist = [0] * q
for i in range(q):
    mlist[i] = list([int(i) for i in sys.stdin.readline().split()])

elist = [0] * (n+1)

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

for i in range(q):
    l, r = mlist[i]
    print(elist[r] - elist[l])

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

acn=[0 for i in range(N)]
count=0
for i in range(1,N):
  if S[i-1]+S[i]=="AC":
    count+=1
  acn[i]=count
for i in range(Q):
  l=lr[i][0]
  r=lr[i][1]
  print(acn[r-1]-acn[l-1])

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

result = 0
for i in range(q):
	num = counter[a[i][1]] - counter[a[i][0]]
	result += num
	print(num)

Solution (Python):
N,Q = map(int,input().split())
 
S = input()
list1 = [0] * (N + 1)
 
for i in range(N):
        list1[i + 1] = list1[i] + (1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
    l,r = map(int,input().split())
    print(list1[r-1]-list1[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()

for i in range(Q):
    lq,rq = map(int,input().split())
    s = S[lq-1:rq]
    count = 0
    while(s.find('A') != -1):
        j = s.find('A')
        if(s[j:j+2] == 'AC'):
            count+=1
            s = s[j+2:]
        else:
            s = s[j+1:]
    print(count)
"""




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


a = [0] * len(S)

s = [0] * (len(S) +1)


for i in range(len(S)):
    if S[i] == 'C':
        if S[i-1] == 'A':
            a[i] = 1 


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



for i in range(Q):
    lq,rq = map(int,input().split())
    print(s[rq] - s[lq])

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

c = [0]
n = 0

for i in range(1,len(S)):
    if S[i-1:i+1] == 'AC':
        n += 1
    c.append(n)

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

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

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

Solution (Python):
nq = list(map(int, input().split()))
n = nq[0]
q = nq[1]
s = input()
ac_list = []
ac_number = 0
for i in range(n - 1):
    if s[i : i+2] == "AC":
        ac_number += 1
    ac_list.append(ac_number)
ac_list.append(0)
for i in range(q):
    lr = list(map(int, input().split()))
    l = lr[0]
    r = lr[1]
    print(ac_list[r - 2] - ac_list[l - 2])

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

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

cnt=[0 for i in range(N+1)]
s=0
f=False
for i in range(N):
    if f and S[i]=='C':
        s+=1
    if S[i]=='A':
        f=True
    else:
        f=False
    cnt[i]=s
for i in range(Q):
    l,r=map(int,input().split())
    print(cnt[r-1]-cnt[max(0,l-1)])

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

check = []
for i in range(len(s)-1):
    temp = s[i:i+2]
    if temp == "AC":
        check.append(i)

check_begin = [0 for i in range(len(s))]
check_num = 0
for i in range(len(s)):
    if check_num != len(check) and (check[check_num]+1) == i :
        check_num += 1
    check_begin[i] = check_num



check_end = [len(check)-i for i in check_begin]

for quest in quests:
    begin = quest[0]-1
    end = quest[1]-1
    cnt = len(check) - check_begin[begin] - check_end[end]
    print(cnt)

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


for i in range(Q):
    l, r = map(int, input().split())
    if l != 1:
        num = cum[r-2] - cum[l-2]
    else:
        num = cum[r-2]
    ans_lst.append(num)

for ans in ans_lst:
    print(ans)

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

loc = [0 for i in range(N+1)]
for i in range(N) :
    if S[i:i+2] == "AC" :
        loc[i+1] = loc[i]+1
    else :
        loc[i+1] = loc[i]
for l,r in L :
    l -= 1
    r -= 1
    ans = loc[r] - loc[l]
    print(ans)

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

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

queries = [tuple(map(int, input().split())) for _ in range(q)]
for query in queries:
    print(ac[query[1]] - ac[query[0]])

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

Solution (Python):

x = input().split()
n = int(x[0]) 
q = int(x[1]) 
s = input()

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



def sc():
    global t
    global s
    global n
    global q
    global idbox
    maxx = 0
    count = 0
    com = [int(s)-1 for s in input().split()]
    
    
    print(t[com[1]-1] - t[com[0]-1])
        
    

    

for i in range(q):
    
    sc()

Solution (Python):
from bisect import bisect_left, bisect_right

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

for i  in range(N-1):
    if S[i]=='A' and S[i+1]=='C':
        A.append(i)
        
for i in range(Q):
    L=list(map(int,input().split()))
    minA=bisect_left(A,L[0]-1)
    maxA=bisect_left(A,L[1]-1)
    print(maxA-minA)

Solution (Python):
import re
n = int(input().split()[1])
s = input()

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

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

Solution (Python):
N, Q = map(int, input().split())
S = input()
t = [0] * (N)
for n in range(N-1):
    add = 1 if S[n:n+2] == "AC" else 0
    t[n+1] = t[n] + add
for q 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()
f = [0] * N
for i in range(N-1):
  add = 0
  if S[i:i+2] == 'AC':
    add = 1
  if i == 0:
    f[i+1] = add
  else:
    f[i+1] = f[i] + add


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

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

s=[0]

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

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

Solution (Python):
N,Q=map(int,input().split())
S=input()
s=[0]
for i in range(N) :
  s.append(s[-1]+(1 if S[i:i+2]=='AC' else 0))
for i 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()

count_list = [0]*(N+1)

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

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

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

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

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

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

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

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

Solution (Python):
n, q = map(int, input().split())
s = list(str(input()))
ac = [0]*100000
cnt = 0
for i in range(n-1) :
  if(s[i] + s[i+1] == "AC") : cnt += 1
  ac[i+1] = cnt
for i in range(q) :
  lr = list(map(int, input().split()))
  print(ac[lr[1]-1] - ac[lr[0]-1])

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

for i in range(q):
    print(a[d[i][1]]-a[d[i][0]])

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

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

Solution (Python):
import sys
input = sys.stdin.readline
 
N, Q = map(int,input().split())
S = input()
nums = [0] * (N + 1)
for i in range(N):
  nums[i+1] = nums[i] + (1 if S[i:i+2]=='AC' else 0)
    
for j in range(Q):
  l, r = map(int,input().split())
  print(nums[r-1] - nums[l-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())


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





for i in range(q):
    ans = sum[r[i]]-sum[l[i]]
    print(ans)

Solution (Python):

from itertools import accumulate
a,b = map(int, input().split())
c = str(input())
d = [list(map(int, input().split())) for i in range(0,b)]

flg = []
for i in range(a-1):
    moji = c[i:i+2]
    if moji == "AC":
        flg.append(1)
    else:
        flg.append(0)

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

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

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v



def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk



def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False



dp = None


def main():
    N, Q = li_input()
    S = input()

    A = [0] * N
    k = 0

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

    for i in range(Q):
        l, r = li_input()

        print(A[r-1] - A[l-1])




main()

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

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

comu = [0]*(N+1)

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

for l,r in list:
    print(comu[r-1]-comu[l-1])

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

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

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

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

for i in range(N):
  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):
dd = input().strip().split(' ')
N, Q = tuple(map(int, dd))
S = input().strip()

ac_indicies = []
cp = S.find('AC')
while cp != -1:
    ac_indicies.append(cp)
    cp = S.find('AC', cp + 1)

min_i = 0
ac = ac_indicies + [N]
l_index = []
for i in range(N):
    if i > ac[min_i]:
        min_i += 1
    l_index.append(min_i)

total = len(ac_indicies)
for i in range(int(Q)):
    l, r = tuple(map(int, input().strip().split(' ')))
    print(l_index[r-1] - l_index[l-1])

Solution (Python):


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

aclist = []

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

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

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

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

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

for i in range(Q):
    x, y = map(int, inputList[i].split())
    res = t[y-1] - t[x-1]
    print(res)

Solution (Python):
N,Q = map(int,input().split())
s = input()
a = [0] * (N + 1)

for i in range(N):
  a[i+1] = a[i] + (1 if s[i:i+2] == "AC" else 0)
for j in range(Q):
  l,r = map(int,input().split())
  print(a[r-1]-a[l-1])

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] + (1 if S[i:i + 2] == 'AC' else 0)

    print()
    
    for j in range(q):
        l, r = map(int, input().split())
        
        print(N[r-1] - N[l-1])
    
    
if __name__ == '__main__':
    main()

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

cum, now, bef = [], 0, False

for c in S:
    if bef and c == 'C':
        now += 1
    cum.append(now)
    if c == 'A':
        bef = True
    else:
        bef = False

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

Solution (Python):
N, Q = map(int, input().split())
S = input()
Ls = len(S)
x = [0 for _ in range(Ls)]
for i in range(Ls - 1):
    x[i + 1] = x[i]
    if S[i:i + 2] == 'AC':
        x[i + 1] += 1
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()
a = [0] * (N + 1)

for i in range(N):
	a[i + 1] = a[i] + (1 if s[i : i + 2] == "AC" else 0)
for i in range(Q):
	l, r = map(int, input().split())
	print(a[r - 1] - a[l - 1])

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

b = [0]
for j in range(n-1):
    if s[j] == 'A' and s[j+1] == 'C':
        b.append(b[j] + 1)
    else:
        b.append(b[j])
for i in range(q):
    l, r = lr[i]
    print(b[r-1] - b[l-1])

Solution (Python):
import re

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

count_array = []

count = 0
is_first = True
for index in range(N):
    if index == 0:
        pass
    elif S[index - 1] == 'A' and S[index] == 'C':
        count += 1
    count_array.append(count)


for l, r in lr_list:
    right_count = count_array[r-1]
    left_count = count_array[l-1]
    print(right_count - left_count)

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

ac = [0] * (N + 1)
for i in range(N - 1):
    ac[i + 1] = ac[i] + (1 if S[i] == 'A' and S[i + 1] == 'C' else 0)
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()
l,r = 0,0
csum = [0]*(N+1)


for ctr in range(N):
    if ctr == (N-1):
        csum[ctr+1] = csum[ctr]
    elif S[ctr]=='A' and S[ctr+1]=='C':
        csum[ctr+1] = csum[ctr] + 1
    else:
        csum[ctr+1] = csum[ctr]


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

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

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

for i in range(Q):
    print(counter[r[i]-1] - counter[l[i]-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())
counter = [0] * N

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

for i in range(Q):
    print(counter[r[i]-1] - counter[l[i]-1])

Solution (Python):
from itertools import accumulate

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

p = (S[i:i+2]=="AC" for i in range(N))
p = [0] + list(accumulate(p))



for l, r in LR:
    l, r = l-1, r
    
    print(p[r-1]-p[l])

Solution (Python):

N,Q=map(int,input().split())
S=str(input())
Slist=list(S)
pile=[0 for i in range(N)]
for i in range(N-1):
    if i == 0:
        pass
    else:
        pile[i]=pile[i-1]
  
    if Slist[i] == "A" and Slist[i+1] == "C":
        pile[i]+=1
pile[-1]=pile[-2]
pile.insert(0,0)
for i in range(Q):
    l,r=map(int,input().split())
    print(pile[r-1]-pile[l-1])

Solution (Python):


memo = []

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

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


        
        
        
        
        
        
        
        
        
        
        
        
        
        














if __name__ == "__main__":
    main()

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

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

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

Solution (Python):
n,q=map(int,input().split())
s=input()
a=[0]*(n)
for i in range(n-1):
  if s[i]=='A' and s[i+1]=='C':
    a[i+1]=a[i]+1
  else:
    a[i+1]=a[i]
for i 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()
lr = [list(map(int, input().split())) for _ in range(q)]

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

Solution (Python):
import bisect

N,Q = map(int,input().split())
S = input()
L = []
for i in range(N):
    if S[i:i+2] == 'AC':
        L.append(i)
for i in range(Q):
    l,r = map(int,input().split())
    a = bisect.bisect_left(L,l-1)
    b = bisect.bisect_right(L,r-2)
    print(b-a)

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

li_flg = [0] * len(s)

for i in range(q):
    li_lr.append(list(map(int, input().split())))


for idx, v in enumerate(s):
    if v == 'C' and idx != 0 and s[idx - 1] == 'A':
        li_flg[idx] = li_flg[idx - 1] + 1
    else:
        li_flg[idx] = li_flg[idx - 1]

for l in li_lr:
    print(li_flg[l[1] - 1] - li_flg[l[0] - 1])

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

t = [0] * (n + 1)

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

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

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

if __name__ == '__main__':
    main()

Solution (Python):
def main():
	n, q = map(int, input().split())
	s = input()
	acs = [0]*(n)
	for i in range(1, n):
		if s[i-1] == "A" and s[i] == "C":
			acs[i] = acs[i-1] + 1
		else:
			acs[i] = acs[i-1]
	results = [0]*q
	for i in range(q):
		l, r = map(int, input().split())
		if l == r:
			continue
		results[i] = acs[r-1] - acs[l-1]
	for result in results:
		print(result)

if __name__ == '__main__':
    main()