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()
l=[0]*n
for i in range(1,n):
    l[i]+=l[i-1]
    if s[i-1:i+1]=="AC":
        l[i]+=1

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

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


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

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

for i in ans:
    print(i)

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

for i in range(n-1):
    if s[i:i+2]=="AC":
        x[i+1]=x[i]+1
    else:
        x[i+1]=x[i]
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()

count_seq = [0]*n

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

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

Solution (Python):
n,q = map(int,input().split())
s = input()
lr = [tuple(map(int,input().split())) for _ in range(q)]
x = [0,0]
for i in range(1,len(s)):
  if s[i-1] == "A" and s[i] == "C":
    x.append(x[-1]+1)
  else:
    x.append(x[-1])
for i,j in lr:
  print(x[j]-x[i])

Solution (Python):
from bisect import bisect, bisect_left

n,q=map(int,input().split())
s=input()
l=[]
r=[]
for i in range(q):
	L,R=map(int,input().split())
	l.append(L-1)
	r.append(R-1)

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

for i in range(q):
	print(bisect(c,r[i])-bisect_left(a,l[i]))

Solution (Python):
def calculate(n,q,S):
    indexes = [0 for i in range(n)]

    arr = list(S)

    for i in range(len(arr)):
        if i == 0:
            indexes[i] = 0
            continue
        if arr[i] == 'C' and arr[i-1] == 'A':
                indexes[i] = indexes[i-1] + 1
        else:
            indexes[i] = indexes[i-1]
    return indexes

def conclution(res,Q):
    for qrr in Q:
        s2 = res[qrr[1]-1]
        s1 = res[qrr[0]-1]
        print(s2-s1)


input1 = input().split(" ")

n = int(input1[0])
q = int(input1[1])
S = input()

res = calculate(n,q,S)

qrr = []

for i in range(q):
    qrr.append([int(s) for s in input().split()])

conclution(res, qrr)

Solution (Python):

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

ls=[0]

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

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

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

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


if __name__ == '__main__':
    main()

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

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

for l, r in l_r_list:
    print(tmp[r-1] - tmp[l-1])

Solution (Python):

import sys
input = sys.stdin.readline
import bisect
left = bisect.bisect_left
right = bisect.bisect_right

def question():
    n ,q = 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)

question()

Solution (Python):
import sys

n, q = map(int, sys.stdin.readline().split())
s = '$' + sys.stdin.readline().rstrip()
lr = zip(*[map(int, sys.stdin.read().split())] * 2)

def main():
    res = [None] * (n + 1); res[0] = 0
    prev = '$'
    for i in range(1, n+1):
        res[i] = res[i-1]
        cur = s[i]
        res[i] += (prev == 'A' and cur == 'C') & 1
        prev = cur
    
    for l, r in lr:
        yield res[r] - res[l]

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Solution (Python):
import sys

n, q = map(int, sys.stdin.readline().split())
s = '$' + sys.stdin.readline().rstrip()
lr = zip(*[map(int, sys.stdin.read().split())] * 2)

def main():
    res = [None] * (n + 1); res[0] = 0
    prev = '$'
    for i in range(1, n+1):
        res[i] = res[i-1]
        res[i] += (prev == 'A' and s[i] == 'C') & 1
        prev = s[i]
    
    for l, r in lr:
        yield res[r] - res[l]

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Solution (Python):
import sys
input = sys.stdin.readline
 
def main():
    N, Q = map(int, input().split())
    S = input().rstrip()
 
    cnt_ac = 0
    arr_ac = [0] * (N)
    for x in range(0, N-1):
        if S[x:x+2] == 'AC':
            cnt_ac += 1
        arr_ac[x+1] = cnt_ac
 
    for i in range(Q):
        L, R = map(int, input().split())
        print(arr_ac[R-1] - arr_ac[L-1])
 
 
main()

Solution (Python):
import sys
input = sys.stdin.readline
 
def main():
    N, Q = map(int, input().split())
    S = input().rstrip()
 
    cnt_ac = 0
    arr_ac = [0] * (N)
    for x in range(0, N-1):
        if S[x:x+2] == 'AC':
            cnt_ac += 1
        arr_ac[x+1] = cnt_ac
 
    for i in range(Q):
        L, R = map(int, input().split())
        print(arr_ac[R-1] - arr_ac[L-1])
 
 
main()

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

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

Solution (Python):

import math
import heapq
import bisect
import numpy as np


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

L = []
R = []

for i in range(Q):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)

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

for i in range(Q):
    ans = rs[R[i]]-rs[L[i]]
    print(ans)

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

for _ in range(Q):
    l, r = map(int, input().split())
    if S[l-1:l+1] == 'AC':
        print(acm_cntAC[r] - acm_cntAC[l - 1] - 1)
    else:
        print(acm_cntAC[r] - acm_cntAC[l-1])

Solution (Python):
import sys


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

AC = [0] * N

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

LR = [map(int, x.split()) for x in sys.stdin.readlines()]

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
a=0
for i in range(n-1):
    if s[i:i+2]=='AC':
        a+=1
    t[i+1]=a
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()
tmp = [0] * (N+1)

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

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

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

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

AC = [0] * N

flag = 0
for i, s in enumerate(S):
    if s == 'C':
        if flag == 1:
            AC[i] = AC[i - 1] + 1
            flag = 0
        else:
            AC[i] = AC[i - 1]
            flag = 0
    elif s == 'A':
        AC[i] = AC[i - 1]
        flag = 1
    else:
        AC[i] = AC[i - 1]
        flag = 0


ans = [0] * Q
for q in range(Q):
    l, r = map(lambda x: int(x) - 1, input().split())
    ans[q] = AC[r] - AC[l]

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

Solution (Python):
from itertools import accumulate
n,q = map(int,input().split())
s = input()
a = [0] + [s[i-1:i+1] == 'AC' for i in range(1,n)]
acc = list(accumulate(a))

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()
lst = [0] * n
for i in range(1, n):
  lst[i] = lst[i-1]
  if s[i-1:i+1] == 'AC':
    lst[i] += 1

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

Solution (Python):
import bisect
n,m = map(int,input().split())
l = list(input())
check = []
for i in range(n-1):
    if l[i] == "A" and l[i+1] == "C":
        check.append(i+1)
for i in range(m):
    a,b = map(int,input().split())
    left = bisect.bisect_left(check,a)
    right = bisect.bisect_left(check,b)
    print(right-left)

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

csm = [0]
cnt = 0

for i in range(n - 1):
	if s[i:i+2] == 'AC':
		cnt += 1
	csm.append(cnt)
	
for j in range(q):
	print(csm[ls[j][1] - 1] - csm[ls[j][0] - 1])

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

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

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

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

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

    cnt_ac = 0
    arr_ac = [0] * (N)
    for x in range(0, N-1):
        if S[x:x+2] == 'AC':
            cnt_ac += 1
        arr_ac[x+1] = cnt_ac

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


main()

Solution (Python):
n,q = map(int,input().split())
s = list(input())
ac = ["A","C"]
li = []

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

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

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

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

    ans = [0] * n
    pre = ''
    sum = 0
    for i, w in enumerate(s):
        if pre == 'A' and w == 'C':
            sum += 1
        ans[i] = sum
        pre = w
    
    for i in range(q):
        l, r = map(lambda x: int(x) - 1, input().split())
        print(ans[r] - ans[l])

if __name__ == '__main__':
    main()

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

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

    ans = [0] * (n + 1)
    pre = ''
    sum = 0
    for i, w in enumerate(s):
        if pre == 'A' and w == 'C':
            sum += 1
        ans[i+1] = sum
        pre = w
    
    for i in range(q):
        l, r = map(int, input().split())
        print(ans[r] - ans[l])

if __name__ == '__main__':
    main()

Solution (Python):
n,q=map(int,input().split())
s=input()
t=[0]*(n+1)
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])

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

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

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

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

f = [0]*(n)
x = 0
for i in range(n):
    f[i] = x
    if s[i:i+2] == "AC":
        x += 1
        
for l, r in lr:
    print(f[r-1] - f[l-1])

Solution (Python):
N, Q = map(int, input().split())
S = input()
acc = [0] * (N+1)
for i in range(0, N):
    acc[i+1] = acc[i] + (i+1 < N and S[i+1] == "C" and S[i] == "A")
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=list(input())

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

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

Solution (Python):
n, q = list(map(int, input().split()))
s = input().strip()
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 = list(map(int, input().split()))
    print(t[r - 1] - t[l - 1])

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

Solution (Python):
n,q=map(int,input().split())
s=input()
t=[0]*(n+1)
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])

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,Q=map(int,input().split())
    S=list(input())+['X']
    A=[0]*N
    for i in range(N):
        if S[i]=='A' and S[i+1]=='C':
            A[i+1]+=1
    S_A=[0]*(N+1)
    for i in range(N):
        S_A[i+1]=S_A[i]+A[i]
    for i in range(Q):
        l,r=map(int,input().split())
        print(S_A[r]-S_A[l])

if __name__ == '__main__':
    main()

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

data=[0 for i in range(N)]
for i in range(N-1):
    data[i+1]=data[i]
    if S[i]+S[i+1]=="AC":
        data[i+1]+=1
for l,r in LR:
    print(data[r-1]-data[l-1])

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

A = [0]*N

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

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

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

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

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()
LR = []
for _ in range(Q):
  LR.append([int(i) for i in input().split()])

AC_point = []
for n in range(N-1):
  if S[n] == "A" and S[n+1] == "C":
    AC_point.append(n+1)
import bisect
for lr in LR:
  a = bisect.bisect_left(AC_point,lr[0])
  b = bisect.bisect_left(AC_point,lr[1])
  print(b-a)

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

before = ''
i = 0
num = 0
data_list = {}
for s in S:
    if before == 'A' and s == 'C':
        num += 1
    before = s
    data_list[i] = num
    i += 1

ans = ''
for q in range(Q):
    r,l = map(int, input().split())
    ans += str(data_list[l-1]-data_list[r-1])+'\n'

print(ans.rstrip())

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

X=[0]*(N)
cnt=0
for i in range(N-1): 
  if S[i]=='A' and S[i+1]=='C':
    cnt+=1
    X[i+1]=cnt
  else:
    X[i+1]=cnt
    
for i in range(Q):
  a=A[i][0]-1
  b=A[i][1]-1
  print(X[b]-X[a])

Solution (Python):
import bisect
N,Q = map(int,input().split())
S = input()
lista = []
for j in range(N-1):
    if S[j:j+2] == 'AC':
        lista.append(j)
for i in range(Q):
    l,r = map(int,input().split())
    l,r = l-1,r-1
    lind = bisect.bisect_left(lista,l)
    rind = bisect.bisect_right(lista,r-1)
    print(rind-lind)

Solution (Python):


(moji_len, query_count) = [int(i) for i in input().rstrip().split(" ")]

mojiretu = input().rstrip()

count_ac = [0]
for i in range(1, moji_len):
    count_ac.append(count_ac[i-1])
    if mojiretu[i] == "C":
        if mojiretu[i-1] == "A":
            count_ac[i] += 1

ans = []
for i in range(query_count):
    q = [int(i) - 1 for i in input().rstrip().split(" ")]
    cnt = count_ac[q[1]]
    if q[0] > 0:
        cnt -= count_ac[q[0] - 1]
        if mojiretu[q[0] - 1] == "A" and mojiretu[q[0]] == "C":
            cnt -= 1
    ans.append(cnt)

for i in ans:
    print(i)

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

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

for i in range(q):
    print(ans[r[i]-1]-ans[l[i]-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())
S = input()

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

i = -1

while(True):
  i = S.find("AC", i + 1)
  
  if i == -1:
    break
  
  AC_num[i + 1] += 1

for i in range(N - 1):
  AC_num[i + 1] += AC_num[i]

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

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


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

for i in range(Q):
    L[i], R[i] = list(map(int, input().split()))
    
    print(SUM[R[i]-1] - SUM[L[i]-1])

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,q=map(int,readline().split())
s=readline().decode('utf-8')
dic={1:0}
c=0
for idx, (a,b) in enumerate(zip(s,s[1:]),1):
  if a=='A' and b=='C':
    c+=1
  dic[idx+1]=c
lst=map(int,read().split())
lr=list(zip(lst,lst))
for l,r in lr:
  print(dic[r]-dic[l])

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,q=map(int,readline().split())
s=readline().decode('utf-8')
dic={}
c=0
for idx, i in enumerate(s, 1):
  if i=='C' and s[idx-2]=='A':
    c+=1
  dic[idx]=c
lst=map(int,read().split())
lr=list(zip(lst,lst))

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

Solution (Python):
import sys
from collections import deque

def resolve():
    input=sys.stdin.readline
    N,Q=map(int,input().rstrip().split())
    S=list(input().rstrip())
    R=[list(map(int,input().rstrip().split())) for _ in range(Q)]
    cumsum=[0 for i in range(N)]

    _S=deque(S)
    prevT=_S.popleft()
    for i in range(1,N):
        
        """
        T+=_S.popleft()
        cumsum[i]=T.count("AC")
        """
        nowT=_S.popleft()
        if(prevT=="A" and nowT=="C"):
            cumsum[i]=cumsum[i-1]+1
        else:
            cumsum[i]=cumsum[i-1]
        prevT=nowT

    cumsum=[0]+cumsum
    for j in range(Q):
        print(cumsum[R[j][1]]-cumsum[R[j][0]])

from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """8 3
ACACTACG
3 7
2 3
1 8"""
        output = """2
0
3"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()

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

S = list(input())

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

cnt = [0]*N

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

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

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

Solution (Python):
from itertools import accumulate
N, Q = map(int, input().split())
S = input()
LR = [tuple(map(int, input().split())) for _ in range(Q)]
A = list(map(lambda s1,s2: int(s1 == "A" and s2 == "C"), S, S[1:]))
B = [0] + list(accumulate(A))
C = list(accumulate(A[::-1]))[::-1] + [0]
P = S.count("AC")
for l, r in LR:
    print(P - B[l-1] - C[r-1])

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

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

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 = str(input())
A = [list(map(int, input().split())) for i in range(Q)]
S1 = [0]*N
count = 0
for j in range(1,len(S)):
    if S[j] == 'C' and S[j - 1] == 'A':
        count += 1
    else:
        pass
    S1[j] = count


for k in range(Q):
    print(S1[A[k][1]-1]-S1[A[k][0]-1])

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

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

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

Solution (Python):


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

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

A.insert(0, 0)

for q in range(Q):
  s, t = map(int, input().split())
  print(A[t]-A[s])

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

Solution (Python):
n, q = map(int, input().split())
s = input().rstrip()
psums = [0]
for i, ch in enumerate(s):
    psums.append(psums[-1])
    if ch == 'C' and i - 1 >= 0 and s[i - 1] == 'A':
        psums[-1] += 1

def sumRange(left, right):
    res = psums[right + 1] - psums[left]
    if s[left] == 'C' and left - 1 >= 0 and s[left - 1] == 'A':
        res -=1
    return res

ret = []
for _ in range(q):
    left, right = map(lambda x: int(x) - 1, input().split())
    ret.append(sumRange(left, right))
print('\n'.join(map(str, ret)))

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

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

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

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

word = input()

counter = [0] * n

for i in range(1, len(word)):
    counter[i] = counter[i-1]
    if word[i-1] + word[i] == 'AC':
        counter[i] += 1

for i in range(q):
    start, end = map(int, input().split())
    print(counter[end-1] - counter[start-1])

Solution (Python):


from bisect import bisect_left
N,Q = map(int, input().split())
S = input()
tmp = ''
ac_count = []
for i, c in enumerate(S):
	if tmp + c == 'AC':
		ac_count.append(i-1)
	tmp = c
ac_count.sort()

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

Solution (Python):
n, k = list(map(int, input().split(' ')))
a = input()
acs = [0] * n
for i in range(1, n):
  acs[i] = acs[i-1] + (a[i-1: i+1] == 'AC')
print('\n'.join(map(str, [acs[e-1] - acs[s-1] for s, e in [list(map(int, input().split(' '))) for _ in range(k)]])))

Solution (Python):
n, q = [int(i) for i in input().split()]
st = input() + '-'
table = []
cnt = 0
for i, v in enumerate(st):
	if st[i: i+2] == 'AC':
		cnt += 1
	table.append(cnt)
table = [0] + table

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

Solution (Python):
N, Q = map(int, input().split())
S = input()
l = []
r = []
for _ in range(Q):
    l1, r1 = map(int, input().split())
    l.append(l1)
    r.append(r1)
    

m = S.count("AC")
S = "a" + S
ll = [0 for _ in range(N+1)]
rr = [0 for _ in range(N+1)]
for i in range(1,N+1):
    ll[i] = ll[i-1]
    if S[i-1] == "A" and S[i] == "C":
       ll[i] -= 1
    rr[i] = -m - ll[i]
       
for i in range(Q):
    print(m + rr[r[i]] + ll[l[i]])

Solution (Python):
import os, sys, re, math

(N, Q) = [int(n) for n in input().split()]
S = input()

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

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

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

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

S = input()
a = [0] * (len(S) + 1)
c = [0] * (len(S) + 1)
ac = [0] * (len(S) + 1)
for i in range(1, len(S) + 1):
    ac[i] = ac[i - 1]
    s = S[i - 1]
    if s == 'A':
        a[i] = 1
    if s == 'C':
        c[i] = 1
        if i > 1 and a[i - 1] == 1:
            ac[i] += 1
    
for q in range(Q):
    l, r = [int(s) for s in input().split(' ')]
    dl = ac[l]
    dr = ac[r]
    print(dr - dl)

Solution (Python):
n, k = list(map(int, input().split(' ')))
orig_a = input()
acs = {}
for i in range(n):
  if i < 1:
    acs[i] = 0
  else:
    acs[i] = acs[i-1] + (orig_a[i-1: i+1] == 'AC')
for _ in range(k):
  s, e = list(map(int, input().split(' ')))
  print(acs[e-1] - acs[s-1])

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

Solution (Python):
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



N, Q = list(map(int, sys.stdin.buffer.readline().split()))
S = sys.stdin.buffer.readline().decode().rstrip()
LR = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(Q)]


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

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

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


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

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