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

Solution (Python):
N , Q = map(int, input().split())
S = input()
LR = [[int(i)-1 for i in input().split()] for j in range(Q)]
T = list(S)
ACtimes = [0] * len(T)

for i in range(1,len(T)):
    if T[i-1] == "A" and T[i] == "C":
        ACtimes[i] = ACtimes[i-1] + 1
    else:
        ACtimes[i] = ACtimes[i-1]

for k in LR:
    print(ACtimes[k[1]] - ACtimes[k[0]])

Solution (Python):
n,q = map(int,input().split())
S = input()
N = [0]*(10**5+1)
for i in range(1,n):
    if S[i-1]=='A'and S[i]=='C':
        N[i] = 1
SUM = [0]*(10**5+1)
for i in range(1,n):
    SUM[i] += SUM[i-1]+N[i]
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())
Ss=[i for i in input()]
counterlist=[0]*N
for s in range(len(Ss)-1):
    if Ss[s]=="A" and Ss[s+1]=="C":
        counterlist[s+1]=1
for c in range(len(counterlist)-1):
    counterlist[c+1]+=counterlist[c]
for i in range(Q):
    l,r = map(int,input().split())
    print(counterlist[r-1]-counterlist[l-1])

Solution (Python):
n,q = map(int,input().split())
s = input()
lr = []
for i in range(q):
    lr.append([int(i) for i in input().split()])
    
acnum = []
acsum = 0
acnum.append(acsum)
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        acsum +=1
    acnum.append(acsum)
for i in range(q):
    l = lr[i][0] - 1
    r = lr[i][1] - 1
    retSum = 0
    print(acnum[r] - acnum[l])

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

s = input()
index = -1
indexes = []
while True:
    index = s.find("AC", index + 1)
    if index == -1:
        break
    indexes.append(index)
dp = []

for i in range (n):
    dp.append(len(indexes))
    if len(indexes)> 0 and indexes[0] == i:
        indexes.pop(0)
for i in range(q):
    l,r = map(int,input().split())
    print(dp[l-1] - dp[r-1])

Solution (Python):
N,Q = map(int,input().split())
S = input()
AC = [0] * N
buffer = []
lr =[]
for i in range(Q):
  buffer = list(map(int,input().split()))
  lr.append(buffer)
counts = 0
for i in range(N):
  if S[i:i+2] == "AC":
    counts +=1
  AC[i] =  counts
a =[0]
AC = a + AC
for q in range(Q):
  
  print(AC[lr[q][1]-1] - AC[lr[q][0]-1])

Solution (Python):
N, Q = map(int, input().split())
S = [ _ for _ in input()]
lr = [[int(_) for _ in input().split()] for _ in range(Q)]
ans = [0] * (N + 1)

for i, data in enumerate(S, 1):
    if data == "A":
        if i >= N:
            break

        if S[i] == "C":
            ans[i] = ans[i - 1] + 1
            continue

    ans[i] = ans[i - 1]

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

Solution (Python):
n,q = map(int,input().split())
s = input()
lr = []
for i in range(q):
    lr.append([int(i) for i in input().split()])
    
acnum = []
acsum = 0
acnum.append(acsum)
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        acsum +=1
    acnum.append(acsum)
for i in range(q):
    l = lr[i][0] - 1
    r = lr[i][1] - 1
    retSum = 0
    print(acnum[r] - acnum[l])

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









ftab = [0]*(n+1)
cnt = 0

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

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

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

l_list = []
r_list = []

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


n_count = []
n_sum = 0
for n in s_count:
    n_sum = n_sum + n
    n_count.append(n_sum)




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

Solution (Python):

import sys

def main():
	N, Q = map(int, input().split(" "))
	S = input()
	S = list(S)
	
	Qs = []
	for _ in range(Q):
		l, r = map(int, input().split(" "))
		Qs.append((l, r))
	
	ptn = []
	hit = 0
	flg = False
	for i, val in enumerate(S):
		if val == "A":
			ptn.append(hit)
			if i+1 < len(S) and S[i+1] == "C":
				hit += 1
				ptn.append(hit)
				flg = True
		else:
			if flg == False:
				ptn.append(hit)
			else:
				flg = False
		
	ans = []
	for i, val in enumerate(Qs):
		l, r = val
		if l == r:
			ans.append(0)
			break
			
		tmp = ptn[r-1] - ptn[l-1]
		ans.append(tmp)
	
	
	for i in ans:
		print(i)
	
if __name__ == "__main__":
	main()

Solution (Python):

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















flag = False
dec_l_list = []
total = 0
for i in range(N):
    if flag and S[i] == "C":
        total += 1
    dec_l_list.append(total)
    flag = True if S[i] == "A" else False
dec_r_list = [total - x for x in dec_l_list]

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

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

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

for i in range(Q):
    hajime = bisect.bisect_left(numlist, l[i])
    owari = bisect.bisect_right(numlist,r[i]-1)
    print(owari - hajime)

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

arr = [0 for j in range(N)]
A_tmp = 0
S_tmp = 0

for i in range(N):
    if S[i] == "A":
        A_tmp = 1
        arr[i] = S_tmp
    elif A_tmp == 1 and S[i] == "C":
        S_tmp += 1
        arr[i] = S_tmp
        A_tmp = 0
    else:
        arr[i] = S_tmp
        A_tmp = 0

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

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

Solution (Python):
N,Q=list(map(int,input().split()))
S=input()
place=[0]*(N+1)
for i in range(0,len(S)-1):
    if S[i:i+2]=='AC':
        place[i+2]+=1
        
for i in range(N):
    place[i+1]=place[i]+place[i+1]
for i in range(Q):
    frm,to=list(map(int,input().split()))
    print(place[to]-place[frm])

Solution (Python):
import re
N,Q=[int(s) for s in input().split()]
S=input()
table=[1 if S[0:2] == "AC" else 0]
for i in range(1, N-1):
    table.append(table[i-1]+(1 if S[i:i+2] == "AC" else 0))
table.append(table[-1])
for i in range(Q):
    (li, ri)=[int(s) for s in input().split()]
    print(table[ri-2]-(table[li-2] if li > 1 else 0))

Solution (Python):


if __name__ == '__main__':
    n, q = map(int, input().split(" "))
    s = input()
    c = [0]
    ql = []
    for i in range(q):
        r, l = map(int, input().split(" "))
        ql.append((r,l))
    for i in range(1, len(s)):
        if s[i-1:i+1] == "AC":
            c.append(c[i-1]+1)
        else:
            c.append(c[i-1])
    for r, l in ql:
        print(c[l-1] - c[r-1])

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

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


main()

Solution (Python):


"""
Created on 2019/3/24
@author: shinjisu
"""




def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]

def getIntLines(n): return [int(input()) for i in range(n)]
def getIntMat(n, m):  
    
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

def zeros(n): return [0]*n

def zeros2(n, m): return [zeros(m) for i in range(n)] 

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob_TLE():
    d = Debug()
    
    N, Q = getIntList()
    d.dmp((N, Q), 'N, Q')
    S = input()
    d.dmp((S), 'S')
    for i in range(Q):
        L, R = getIntList()
        d.dmp((L, R), 'L, R')
        j = L-1
        count = 0
        while j < R-1:
            d.dmp(j,'j')
            d.dmp(S[j:j+2],'S[j:j+2]')
            if S[j:j+2] == 'AC':
                count += 1
                j += 2
            else:
                j += 1
        print(count)
    return None

def prob():
    d = Debug()
    d.off()
    N, Q = getIntList()
    d.dmp((N, Q), 'N, Q')
    S = input()
    d.dmp((S), 'S')
    aclist = zeros(N)  
    j = 0
    R = len(S)
    count = 0
    while j < R:
        
        
        if S[j:j+2] == 'AC':
            aclist[j] = count
            count += 1
            aclist[j+1] = count
            j += 2
        else:
            aclist[j] = count
            j += 1
    d.dmp((aclist), 'aclist')
   
    for i in range(Q):
        L, R = getIntList()
        
        print(aclist[R-1]-aclist[L-1])

    return None

ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  
    for elm in ans[1]:
        print(elm)
else:
    print(ans)

Solution (Python):
n,q = [int(i) for i in input().split()]
s = input()
cumsum = [0]*n
ans = 0
flag = False

for i in range(n):
    if flag:
        if s[i] == "C":
            ans += 1

    cumsum[i] = ans     

    flag = False

    if s[i] == "A":
        flag = True
    


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

Solution (Python):
from sys import stdin
from collections import deque

N, Q = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
lr_list = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]


count = 0

result_list = deque([])

for i in range(N):
    result_list.append(count)
    if S[i] != "A":
        continue
    try:
        if S[i+1] == "C":
            count += 1
    except:
       pass

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

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

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

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

Solution (Python):
def solve(lr,N,Q,S):
    
    count = [0]*N
    sum = 0
    for i in range(1,N):
       
        if S[i-1]=='A' and S[i]=='C':
            sum += 1
            count[i] = sum
        else:
            count[i] = sum

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



 
def main():
    N,Q= map(int,input().split())
    S = input()
    lr = [0]*Q
    for i in range(Q):
        lr[i]=input().rstrip().split()
    
    
    
    
    solve(lr,N,Q,S)
 
 
if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

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

flags = [0] * len_S
for i, v in enumerate(S[:-1]):
  if v == 'A' and S[i + 1] == 'C':
    flags[i + 1] = 1
  else:
    flags[i + 1] = 0

sums = list(np.cumsum(flags))

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

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

ans = [0]
num = 0
for x, y in zip(S[:-1], S[1:]):
    if x == 'A' and y == 'C':
        num += 1
        ans.append(num)
    else:
        ans.append(num)

for _ in range(Q):
    l, r = map(int, input().split())
    if l == 1:
        print(ans[r-1])
    else:
        b = ans[r-1]-ans[l-2]
        if S[l-1] == 'C' and S[l-2] == 'A':
            print(b-1)
        else:
            print(b)

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

for index in lr:
    
    print(a[index[1]-1] - a[index[0]-1])

Solution (Python):

"""
Created on Sat Feb 16 20:52:46 2019

@author: Owner
"""


import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect


def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

    
all(nstr.count(c) for c in '753')


ABT = zip(A, B, totAB)
result = 0

sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)


(x >> i) & 1


dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break

"""


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

p_ac = []
n = 0
while True:
    tmp = S.find('AC', n, N+1)
    if tmp == -1:
        break
    else:
        p_ac.append(S.find('AC', n, N+1))    
        n = tmp+1
l = [0]*Q
r = [0]*Q
for i in range(Q):
    l[i], r[i] = map(int, input().split())
    li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-2)       
    
    print( len(S[li:ri]))

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

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

Solution (Python):
def main():
    N, Q = map(int, input().split())
    S = input()
    s_list = [str(c) for c in S]
    q_list = [list(map(int, input().split())) for i in range(Q)]

    ac_list = list()
    
    for i, n in enumerate(s_list):
        if n == "A" and i != (len(s_list) - 1):
            if s_list[i + 1] == "C":
                ac_list.append(i + 1)

    
    temp = list()
    pre = 0
    counter = 0
    for s in ac_list:
        for i in range(pre, s):
            temp.append(counter)
        pre = s
        counter += 1

    for i in range(pre, N):
        temp.append(counter)

    
    for qs in q_list:
        print(temp[qs[1] - 1] - temp[qs[0] - 1])


if __name__ == '__main__':
    main()

Solution (Python):
import bisect
N,Q=[int(i) for i in input().split()]
S=input()
AC=list()
for i in range(len(S)-1):
    if S[i]=='A' and S[i+1]=='C':
        AC.append(i)

for i in range(Q):
    L,R=[int(i)-1 for i in input().split()]
    R-=1
    ll=bisect.bisect_left(AC,L)
    rr=bisect.bisect_right(AC,R)
    print(rr-ll)

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

S=input()


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

prev=""

for i in range(N):
	if S[i]=="C":
		if prev=="A":
			cnt[i]+=1
	if i!=0:
		cnt[i]+=cnt[i-1]
	prev = S[i]

for q in range(Q):
 	L,R=map(int,input().split())
 	ans = cnt[R-1]-cnt[L-1]
 	print(ans)

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

Solution (Python):
import sys
import bisect
input = sys.stdin.readline
def 解():
    N,Q=[int(_) for _ in input().split()]
    S = input()
    aC = [-1]
    iC = 0
    bF = False
    for s in S:
        iC += 1
        if s == 'A':
            bF = True
        elif s == 'C' :
            if bF:
                aC.append(iC)
            bF = False
        else:
            bF = False

    aC.append(10**9)
    aAns = []
    for _ in range(Q):
        l,r = [int(_) for _ in input().split()]
        iL = bisect.bisect_left(aC,l)
        if l == aC[iL]:
            iL += 1
        iR = bisect.bisect_left(aC,r)
        if aC[iR] <= r:
            iR += 1
        aAns.append(iR-iL)
    print(*aAns,sep="\n")
解()

Solution (Python):
N, Q = map(int, input().split());
S = input();
check_AC = [];

char_prev = "0"
char_now = "0"
for i in S:
    if char_prev == "0":
        char_prev = i;
        check_AC.append(0);
    else:
        char_now = i;
        if(char_prev + char_now == "AC"):
            check_AC.append(check_AC[-1]+1);
        else:
            check_AC.append(check_AC[-1]);
        char_prev = i;

answer = []

for i in range(Q):
    left, right = map(int, input().split());
    answer.append(check_AC[right-1]-check_AC[left-1]);

for i in answer:
    print(i);

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

ans_list = []
fa = 0
ans = 0
for index, s in enumerate(S):
    if s == 'A' and fa == 0:
        fa = 1
        ans_list.append(ans)
    elif s == 'A' and fa == 1:
        ans_list.append(ans)
    elif s == 'C' and fa == 1:
        fa = 0
        ans += 1
        ans_list.append(ans)
    else:
        fa = 0
        ans_list.append(ans)
for _ in range(Q):
    l, r = map(int, input().split())
    print(ans_list[r-1] - ans_list[l-1])

Solution (Python):
from itertools import accumulate

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

ac = [0] + ac
acc = list(accumulate(ac))
for i in range(Q):
    l, r = map(int, input().split())
    print(acc[r-1] - acc[l-1])

Solution (Python):
n, q = map(int,input().split())
s = input()
l = [[int(i) for i in input().split()] for i in range(q)]
c = [0 for i in range(n)]
cc = 0
f = False
for i in range(n):
    if f:
        f = False
        if s[i] == "C":
            cc += 1
    if s[i] == "A":
        f = True
    c[i] = cc
for i in range(q):
    print(c[l[i][1]-1]-c[l[i][0]-1])

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

Solution (Python):
import bisect
n, q = map(int, input().split())
s = input()
ac = 'AC'
args = []
for i in range(len(s) - 1):
    if s[i:i+2] == 'AC':
        args.append(i)
for j in range(q):
    l, r = map(int, input().split())
    i_l = bisect.bisect_left(args, l-1)
    i_r = bisect.bisect_right(args, r-2)
    print(i_r - i_l)

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

start_position = []
prev = ""
counter = 0
for s in S:
    if s == "C" and prev == "A":
        counter += 1
        start_position.append(counter)
    else:
        start_position.append(counter)
    prev = s

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

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]=="A" and S[i]=="C":
        count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[l-1])

Solution (Python):

import bisect

n, q = map(int, raw_input().split())
s = raw_input()
i_list = []
i = -1
while True:
    i = s.find("AC", i+1)
    if(i == -1): break
    i_list.append(i)
for i in range(q):
    a, b = map(int, raw_input().split())
    a = bisect.bisect_left(i_list, a-1)
    b = bisect.bisect_left(i_list, b-1)
    print(b-a)

Solution (Python):
N, Q = map(int, input().split())
char = input()
num_list = [0]
for i in range(1,N):
  if char[i-1:i+1] == 'AC':
    num_list.append(num_list[-1]+1)
  else:
    num_list.append(num_list[-1])

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

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

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

Solution (Python):
def f():
    return map(int, input().split())


def main():
    N, Q = f()
    S = input()
    t = []
    flag = False
    n = 0
    for i, s in enumerate(S):
        if s == 'A':
            flag = True
        elif flag and s == 'C':
            n += 1
            flag = False
        else:
            flag = False
        t.append(n)

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


if __name__ == '__main__':
    main()

Solution (Python):
A = "AC"
N, Q = map(int, input().split())
S = list(input())
ans = [0]
cnt = 0
for j in range(N - 1):
    tmp1 = S[j] + S[j + 1]
    if tmp1 == A:
        cnt += 1
    ans.append(cnt)

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

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

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

cnt = 0
li = []

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




for k in range(Q):
    print(li[lr[k][1]-1] - li[lr[k][0]-1])

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

num_list = []
tochu = [0 for _ in range(N)]
tochu2 = [0 for _ in range(N)]

state = 0
count = 0
for t_i, t in enumerate(S): 
    if "A" == t:
        state = 1
    elif "C" == t and state == 1:
        tochu[t_i-1] = 1
        tochu2[t_i] = 1
        state = 0
        count += 1
    else:
        state = 0
    num_list.append(count)


outs = []
for Q_i in range(Q):
    l, r = list(map(int, input().split(" ")))
    l -= 1
    r -= 1
    
    tmp = 0 if l -1 < 0 else num_list[l-1]
    out = num_list[r] - tmp - tochu2[l]
    outs.append(out)

for out in outs:
    print(out)

Solution (Python):
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

n,q = read_int()
S = read_str()
lr = [read_int() for _ in range(q)]

dp = [0 for i in range(n+1)]
def solve():
    for i in range(1, n):
        dp[i+1] = dp[i]
        if S[i - 1:i + 1] == 'AC':
            dp[i +1] += 1

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

        
if __name__ == "__main__":
    solve()

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N, Q = LI()
S = input()
"""
ACのインデックスをすべて記録しておき、始点、終点で区切って出す
少ない方を取ったほうがいいかな
"""
ACs = []
for sidx in range(0, len(S)-1):
    if S[sidx] == 'A':
        if S[sidx+1] == 'C':
            ACs.append(sidx)



LR = []
for i in range(Q):
    LR.append(LI())











result = []

for l, r in LR:
    start = bisect.bisect_left(ACs, l-1)
    end = bisect.bisect_left(ACs, r-1)
    
    print(end-start)

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

Solution (Python):
n,q=map(int, input().split())
s=input()
lst=[list(map(int, input().split())) for i in range(q)] 
acwa=[0]*(n)
a=0
ac=0
for i in range(n):
  if(s[i]=="A"):
    a=1
  elif(s[i]=="C"):
    if(a==1):
      ac+=1
    a=0
  else:
    a=0
  acwa[i]=ac
for i in lst:
  ans=acwa[i[1]-1]-acwa[max(i[0]-2,0)]
  if(acwa[i[0]-1]!=acwa[max(i[0]-2,0)]):
    ans-=1
  print(ans)

Solution (Python):
import bisect
N, Q = map(int, input().split())
S = input()
lis = []
for i in range(len(S) - 1):
  if S[i] == "A" and S[i + 1] == "C":
    lis.append(i + 1)
for _ in range(Q):
  l, r = map(int, input().split())
  ko = bisect.bisect_left(lis, l)
  kk = bisect.bisect_left(lis, r)
  print(kk - ko)

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

ll = list([])
now = 0
for i, c in enumerate(s):
    if((c == "C") and (i>0) and (s[i-1] =="A")):
        now += 1
    count[i] = now

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

Solution (Python):

n, q = map(int, input().split())
s = str(input())
s_flag = [0] * n
v = 0
for i in range(n-1):
    if s[i:i+2] == 'AC':
        v += 1
    s_flag[i+1] = v

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

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n,q = map(int,input().split())
s = input()
a = [list(map(int,input().split())) for i in range(q)]
rui = [0] * n
for i in range(n-1):
        if s[i]+s[i+1] == "AC":
                rui[i+1] += rui[i] +1
        else:
                rui[i+1] = rui[i]
for i in range(q):
        tmp = rui[a[i][1]-1] - rui[a[i][0]-1]
        print(tmp)

Solution (Python):


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

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

for l, r in l_r:
    print(isAC[r - 1] - isAC[l - 1])

Solution (Python):
import itertools

N,Q = map(int,input().split())
S = input()
info = [[int(e)-1 for e in input().split()] for _ in range(Q)]
note = [0]*(N)
for i in range(1,N):
    if S[i-1] == "A" and S[i] == "C":
        note[i] = 1
note = list(itertools.accumulate(note))
for l,r in info:
    if l == 0:
        ans = note[r]
    else:
        ans = note[r] - note[l-1]
        if S[l-1] == "A" and S[l] == "C":
            ans -= 1
    print(ans)

Solution (Python):
import bisect

N, Q = map(int, input().split())
S = input()
oc = 'X'
results = []
for i in range(len(S)): 
    c = S[i] 
    if oc+c == "AC":
      results.append(i)
    oc = c


LRs = [tuple(map(int,input().split())) for i in range(Q)]

for L, R in LRs:
    fi = bisect.bisect_left(results,L)
    li = bisect.bisect_left(results,R)
    
    
    print(li - fi)

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

arr=[0]*N
for i,z in enumerate(arr):
  if i==0:
    continue
  if s[i-1]=="A" and s[i]=="C":
    arr[i]=arr[i-1]+1
  else:
    arr[i]=arr[i-1]
for z in range(0,Q):
  i=list(map(int,input().split(" ")))
  print(arr[i[1]-1]-arr[i[0]-1])

Solution (Python):

import sys



def solve(lines):
    N,Q = map(int, lines.pop(0).split(' '))
    S = lines.pop(0)
    NLIST = []
    for i in range(Q):
        a,b = map(int, lines.pop(0).split(' '))
        NLIST.append((a,b))
    sums = [0]
    res = 0
    for i in range(N-1):
        if S[i:i+2] == 'AC':
            res += 1
        sums.append(res)
    for k in NLIST:
        i = max( k[0] - 1, 0)
        j = k[1] - 1
        print(sums[j] - sums[i])
lines = [x.strip() for x in sys.stdin.readlines()]




solve(lines)

Solution (Python):
N, Q = map(int, raw_input().split())
S = raw_input()
ac_counter = [0] * (N + 1)
total = 0
for i in range(1, N):
  if S[i - 1:i + 1] == 'AC':
    ac_counter[i] += 1
  ac_counter[i] += total
  total = ac_counter[i]

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

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