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

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

counts = [0 for _ in range(len(S))]
for i in range(1, len(S)):
  if S[i] == 'C' and S[i-1] == 'A':
    counts[i] = counts[i-1] + 1
  else:
    counts[i] = counts[i-1]
    
for q_i in range(Q):
  l, r = input().strip().split()
  l = int(l)-1
  r = int(r)-1  
  print(counts[r] - counts[l])

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

Solution (Python):
"16時57分開始"
N, Q = map(int, input().split())  
S = str(input())

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



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

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

ac_list = [0]

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



for i 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 = input()
list = [[0 for i in range(2)] for j in range(Q)]

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

Solution (Python):


N,Q=input().split()
S=input()
S= S.replace("AC","Ac")


def judge(x):
  if x=="c":
    return 1
  else:
    return 0


t=[]
t.append(0)

for i in range(1,int(N)):
  t.append(t[i-1]+judge(S[i]))

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

Solution (Python):


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

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

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

Solution (Python):
from itertools import accumulate
from operator import add

N, Q = map(int, input().split())
S = input()
idx_list = [1 if S[i:i + 2] == 'AC' else 0 for i in range(len(S) - 1)]
idx_list_cumsum = [0] + list(accumulate(idx_list, add))

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

Solution (Python):
import sys


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

cnt = 0
table = [0] * N
for i, Si in enumerate(S):
    if i == 0: continue
    elif Si == 'C':
        if S[i - 1] == 'A':
            cnt += 1
    table[i] = cnt

for i, (li, ri) in enumerate(lr):
    ans = table[ri - 1]
    if li > 1:
        ans -= table[li - 2]
        if S[li - 2] == 'A' and S[li - 1] == 'C': ans -= 1
    print(ans)

Solution (Python):
import sys
imput =sys.stdin.readline
N, Q =map(int,input().split())
S =[i for i in input()]
q = [[int(i) for i in input().split()] for _ in range(Q)]
num = 0
for i in range(N-1):
    if S[i]+S[i+1]=="AC":
        num += 1
    S[i] = num
S[-1] = num
S.append(0)
for lr in q:
  print(S[lr[1]-2] -S[lr[0]-2])

Solution (Python):
import sys
imput =sys.stdin.readline
N, Q =map(int,input().split())
S =[i for i in input()]
q = [[int(i) for i in input().split()] for _ in range(Q)]
num = 0
for i in range(N-1):
    if S[i]+S[i+1]=="AC":
        num += 1
    S[i] = num
S[-1] = num
S.append(0)
for lr in q:
  print(S[lr[1]-2] -S[lr[0]-2])

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b



def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)



def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


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

    v = [0] * (10**5 + 100)
    for i in range(N - 1):
        if S[i] == "A" and S[i + 1] == "C":
            v[i + 1] = 1

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

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


if __name__ == '__main__':
    main()

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

cnt =[0]
for a,b in zip(S,S[1:]):
  if a == 'A' and b == 'C':
    cnt.append(cnt[-1] + 1)    
  else:
    cnt.append(cnt[-1])

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

Solution (Python):



import sys

input = sys.stdin.readline

def main():
    _ = input()
    s = input()

    freq = [0 for _ in range(len(s))]
    for i, c in enumerate(s):
        if i > 0 and s[i-1] == 'A' and c == 'C':
            freq[i] = freq[i-1] + 1
        else:
            freq[i] = freq[i-1]

    for l in sys.stdin:
        x, y = [int(e) for e in l.split()]
        print(freq[y-1]-freq[x-1])


main()

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


a = [0]*n

end = [False]*n
for i in range(1,n):
    if s[i] == 'C' and s[i-1] == 'A':
        a[i] = a[i-1]+1
        end[i] = True
    else:
        a[i] = a[i-1]

for i in range(q):
    L,R = map(int,input().split())
    L,R = L-1,R-1
    if L == 0:
        print(a[R])
    else:
        if end[L]:
            print(a[R]-a[L-1]-1)
        else:
            print(a[R]-a[L-1])

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

c = [0 for i in range(n)]

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

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

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

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

    lis = [0 for _ in range(len(S))]
    for i in range(len(S)):
        if i > 0:
            lis[i] += lis[i - 1]
        if i < len(S) - 1 and S[i] == 'A' and S[i + 1] == 'C':
            lis[i + 1] += 1

    for _ in range(Q):
        L = tuple(map(int, input().split()))
        print(lis[L[1] - 1] - lis[L[0] - 1])


if __name__ == '__main__':
    main()

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

acc = [0] * (n+5)

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

Solution (Python):
n,q=map(int,input().split())
s=input()
c=[0]
t=0

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

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

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

for j in range(Q):
    x,y = map(int, input().split())
    print(A[y-1]-A[x-1])

Solution (Python):


N,Q=input().split()
S=input()
S= S.replace("AC","Ac")


def judge(x):
  if x=="c":
    return 1
  else:
    return 0


t=[]
t.append(0)

for i in range(1,int(N)):
  t.append(t[i-1]+judge(S[i]))

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

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

Solution (Python):
n,q=map(int,input().split())
s=input()
i=0
bb=[]
c=0
while True:
    b=s.find('AC', i)
    if b<0:
        bb.extend([c]*(len(s)-i))
        break
    bb.extend([c]*(b-i+1))
    i=b+1
    c+=1
for _ in range(q):
    l,r=map(int,input().split())
    print(bb[r-1]-bb[l-1])

Solution (Python):
import bisect

def sub():
    N, Q = [int(e) for e in input().split(" ")]
    cc = [c for c in input()]
    qs = [input() for _ in range(Q)]
    qs = [[int(e) for e in q.split(" ")] for q in qs]
    
    buf_left = []
    buf_right = []
    for i in range(N-1):
        if cc[i] == "A" and cc[i+1] == "C":
            buf_left.append(i+1)
            buf_right.append(i+2)
    
    for left, right in qs:
        index_left = bisect.bisect_left(buf_left, left)
        index_right = bisect.bisect_right(buf_right, right)
        
        print(index_right-index_left)

sub()

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

ac_count = [0]
ac = 0
for i in range(1, n):
    if arr[i-1:i+1] == "AC":
        ac += 1
    ac_count.append(ac)

ans = []

for _ in range(q):
    left, right = map(int, input().split())
    ans.append(ac_count[right-1] - ac_count[left-1])

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

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

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

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

import numpy
res = numpy.cumsum(t)

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

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

counts = [0]*N

count = 0
for i, (a, b) in enumerate(zip(S, S[1:])):
    if a == 'A' and b == 'C':
        count += 1
        counts[i+1] = count
    else:
        counts[i+1] = count

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

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

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

Solution (Python):

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

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

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

    tmp = cumurative_sum_lst[r] - cumurative_sum_lst[l]
    outputs.append(int(tmp))

for i in outputs:
    print(i)

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

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

for i in range(q):
    l = lr[i][0] - 1
    r = lr[i][1] - 1
    counter = ac_count_before[r] - ac_count_before[l]
    print(counter)

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


a = [0]*n

end = [False]*n
for i in range(1,n):
    if s[i] == 'C' and s[i-1] == 'A':
        a[i] = a[i-1]+1
        end[i] = True
    else:
        a[i] = a[i-1]
for i in range(q):
    L,R = map(int,input().split())
    L,R = L-1,R-1
    if L == 0:
        print(a[R])
    else:
        if end[L]:
            print(a[R]-a[L-1]-1)
        else:
            print(a[R]-a[L-1])

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

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

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

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

Solution (Python):
n, nQueries = map(int,input().split())
inString = input()
queries = [ [int(x)-1 for x in input().split()] for i in range(nQueries)]
occurance_list = [0]*n
idx = 0
while(idx < n):
    if(idx<n-1 and inString[idx] == "A" and inString[idx+1] == "C"):
        occurance_list[idx] = occurance_list[idx-1]
        occurance_list[idx+1] += occurance_list[idx-1] + 1
        idx += 2
    else:
        occurance_list[idx] = occurance_list[idx-1]
        idx+=1



for (i,j) in queries:
    print(occurance_list[j] - occurance_list[i])

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

Solution (Python):
N, Q = map(int, input().split())
S = str(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] = [int(i) for i in input().split()]
s = input() + '_'
l = [[int(j) - 1 for j in input().split()] for i in range(q)]

cnt = 0
num = []
for i in range(len(s) - 1):
    if (s[i:i + 2] == 'AC'):
        cnt += 1
        num.append(cnt)
    else:
        num.append(cnt)
for i in l:
    temp = num[i[1]] - num[i[0]]
    if i[1] - i[0] > 0:
        if (s[i[0]:i[0] + 2] == 'AC'):
            temp += 1
        if (s[i[1]:i[1] + 2] == 'AC'):
            temp -= 1 
    print(temp)

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

for i in range(Q):
  begin, end = map(int,input().split())
  print(AC_cnt[end-1]-AC_cnt[begin-1])

Solution (Python):

import sys
from bisect import bisect_left
from bisect import bisect_right


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    aclist = [] 
    end = N - 1
    for i in range(end):
        if S[i] == 'A' and S[i+1] == 'C':
            aclist.append(i)

    len_ac = len(aclist)

    for i in range(Q):
        res = 0
        begin = l[i] - 1
        end   = r[i] - 2

        s_start = bisect_left(aclist,begin)
        s_end   = bisect_right(aclist,end)

        print(s_end-s_start)
            



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    Q = int(next(tokens))  
    S = next(tokens)  
    l = [int()] * (Q)  
    r = [int()] * (Q)  
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)

if __name__ == '__main__':
    main()

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


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


b = [0] * (n + 1)
for i in range(n):
    b[i+1] = b[i] + a[i]

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

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

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

for i in range(len(ans_table)):
    print(ans_table[i])

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

sum_table = [0] * (N+1)

for i in range(N):
    sum_table[i+1] = sum_table[i] + (1 if S[i:i+2] == "AC" else 0)
for i in range(Q):
    left, right = map(int, input().split())
    print(sum_table[right-1] - sum_table[left-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 = [int(nq) for nq in input().split()]
S = input()
AC = []
for s in range(len(S)-1):
    if S[s:s+2] == "AC":
        AC.append(1)
    else:
        AC.append(0)
CS = [0]*len(AC)
CS[0] = AC[0]
for i in range(len(AC)-1):
    CS[i+1] = CS[i] + AC[i+1]
for q in range(Q):
    l, r = [int(lr) for lr in input().split()]
    if l == 1:
        print(CS[r-2])
    else:
        print(CS[r-2] - CS[l-2])

Solution (Python):
N, Q = map(int, input().split())
ruisekiwa = [0]
lists = []
cnt = 0
S = str(input())
for t in range(1, N):
    if S[t - 1] == "A" and S[t] == "C":
        cnt += 1
    ruisekiwa.append(cnt)
ruisekiwa.append(cnt)
for i in range(Q):
    l, r = map(int, input().split())
    ans = ruisekiwa[r - 1] - ruisekiwa[l - 1]
    lists.append(ans)
for m in range(len(lists)):
    print(lists[m])

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

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

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

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

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

Solution (Python):
n, q=map(int,input().split())
str=input() 
q_list=[input().split() for _ in range(q)]  
pattern='AC'


count_ac=[0 for i in range(len(str))]
count=0
for i in range(len(count_ac)-1):
    if str[i]=='A' and str[i+1]=='C':
        count+=1
        count_ac[i]=count
    else:
        count_ac[i]=count
count_ac[len(str)-1]=count    
for a,b in q_list:
    A,B=int(a),int(b)
    if A>=2:
        print(count_ac[B-2]-count_ac[A-2])
    elif B>=2 and A<2:
        print(count_ac[B-2])
    else:
        print(0)

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 = tuple([int(i) for i in input().split(' ')])
s = input()

c = [0] * n

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

for i in range(q):
    l, r = tuple([int(i) for i in 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):
def main():
    n,q = list(map(int,input().split(' ')))
    s = input()
    tmp = 0
    s_tr =[]
    q_list = []
    for i in range(n-1):
        if len(s_tr) !=i:
            continue
        if s[i] == 'A' and s[i+1] =='C':
            tmp += 1
            s_tr.append(tmp)
            s_tr.append(tmp)
        else:
            s_tr.append(tmp)
    if len(s_tr) != n:
        s_tr.append(tmp)
    for i in range(q):
        q_list.append(list(map(int,input().split(' '))))

    for l,r in q_list:
        if s_tr[r-1] ==s_tr[r-2]:
            if l ==1:
                print(s_tr[r-1])
            else:
                print(s_tr[r-1]-s_tr[l-2])
        else:
            if l ==1:
                print(s_tr[r-1] - 1)
            else:
                print(s_tr[r-1] - s_tr[l-2] -1 )

if __name__ == '__main__':
    main()

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

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

for _ in range(q):
    l, r = map(lambda x: int(x) - 1, input().split())
    if l == 0:
        print(c[r])
    else:
        print(c[r] - c[l-1] - 1 if s[l-1:l+1] == 'AC' else c[r] - c[l-1])

Solution (Python):





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

sh = [0]
n = 0
for i in range(1, N):
    if S[i - 1] == "A" and S[i] == "C":
        n += 1
    sh.append(n)
for (l, r) in zip(L, R):
    print(sh[r - 1] - sh[l - 1])

Solution (Python):

"""
Created on Mon May 13 17:55:54 2019

@author: avina
"""

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

sN, sQ = stdin.readline().split()
N, Q = int(sN), int(sQ)

S = stdin.readline().rstrip()
data = [stdin.readline().split() for itr in range(Q)]


grid = [None] * N

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



for itr in range(Q):
    l = int(data[itr][0]) - 1
    r = int(data[itr][1]) - 1
    
    print(grid[r]-grid[l])

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

import bisect
left = bisect.bisect_left
right = bisect.bisect_right 

n, q = list(map(int, input().split()))
s = input()
lr = [list(map(int, input().split())) for i in range(q)]
a = [i for i in range(n-1) if s[i:i+2]=="AC"]

for i in range(q):
  left_index = left(a, lr[i][0]-1)      
  right_index = right(a, lr[i][1]-2)  
  print(right_index - left_index)

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 = list(input())
T = [0] * (N+1)
count = 0


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



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

Solution (Python):
NN, QQ = map(int, input().split())
SS = input('')
ll = [0]*(QQ)
rr = [0]*(QQ)
for ii in range(QQ):
    ll[ii], rr[ii] = map(int, input().split())

AC_indices = [0]*(NN)
for jj in range(NN-1):
    if SS[jj] == 'A' and SS[jj+1] == 'C':
        AC_indices[jj] += 1
        
cum_AC = [0]*(NN+1)
cum_AC[0] = AC_indices[0]
for jj in range(NN):
    cum_AC[jj+1] = cum_AC[jj] + AC_indices[jj]

for ii in range(QQ):
    print(cum_AC[rr[ii]-1]-cum_AC[ll[ii]-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] = t[i-1] + (1 if S[i:i+2] == "AC" else 0)
for i in range(Q):
    l,r = map(int, input().split())
    print(t[r-2] - t[l-2])

Solution (Python):



"""
累積和を用いて実装しないと時間が足りない
"""

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

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

"""
ACを数えるために受けた文字列ｓを展開して数えていく
"""

for i in range(1, len(s)):
    """
    s = ACACTACG
    cnt = [0,0,1,1,2,2,2,3,3]
    i == 1, 2, 3……len(s)
    
    i == 1
    s[i] == C s[i-1] == A
    ここで代入されるべきなのはcntのindex2番である　
        なぜならば、cntは最初に0を代入するので、s[i]の位置に当たるのはcnt[i]+1であるため
    """

    if s[i] == "C" and s[i-1] == "A":
        cnt[i+1] = cnt[i] + 1
    else:
        cnt[i+1] = cnt[i]


r_and_l = [list(map(int, sys.stdin.readline().split())) for _ in range(q)]

for e in r_and_l:
    num = e[0]
    print(cnt[e[1]] - cnt[num] )

Solution (Python):
def main(N, Q, S, lr_list):
    chars = list(S)

    s_list = [0]
    for i in range(N):
        if i+1 < N and chars[i] == 'A' and chars[i+1] == 'C':
            s_list.append(s_list[i] + 1)
        else:
            s_list.append(s_list[i])

    res_list = []
    for lr in lr_list:
        l, r = lr
        l -= 1
        r -= 1
        res_list.append(s_list[r] - s_list[l])

    return res_list


if __name__ == "__main__":
    N, Q = list(map(int, input().split()))
    S = input()
    lr_list = []
    for _ in range(Q):
        lr_list.append(tuple(map(int, input().split())))
    res = main(N, Q, S, lr_list)
    for r in res:
        print(r)

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

Solution (Python):
n,q = map(int, input().split())
s = list(input())
lr_list = [list(map(int,input().split())) for _ in range(q)]
tmp_list = [0]*(n+1)

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

for l,r in lr_list:
    print(tmp_list[r-1]-tmp_list[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: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())
str = input()
ac_list = [0]
for i in range(1,N):
  if str[i-1:i+1] == "AC":
    ac_list.append(ac_list[-1]+1)
  else:
    ac_list.append(ac_list[-1])
    
for i 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 = input()
q_list = [list(map(int, input().split()))for _ in range(q)]

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

for i in range(q):
    print(cum_sum[q_list[i][1] - 1] - cum_sum[q_list[i][0] - 1])

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

S = input()
d = [0] * N

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

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

    print(d[r] - d[l])

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

Solution (Python):

N, Q = map(int, input().split())
Str = input()
l_list = [0] * Q
s_list = [0] * Q
for i in range(0, Q):
    l_list[i], s_list[i] = map(int, input().split())

Mem = [0] * N
for i in range(1, N):
    if Str[i-1] + Str[i] == 'AC':
        Mem[i] = Mem[i-1] + 1
    else:
        Mem[i] = Mem[i-1]

for i in range(0, Q):
    print(Mem[s_list[i]-1] - Mem[l_list[i]-1])

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