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

a = [0] * n
num = 0

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

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

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

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()
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 = str(input())
W = [0] * (N+1)
L = []
R = []
for q in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

for n in range(N-1):
    W[n+1] = W[n] + (1 if S[n:n+2] == 'AC' else 0)    

for q in range(Q):
    print(W[R[q]-1]-W[L[q]-1])

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

Solution (Python):
from sys import stdin
import bisect

N,Q = list(map(int,stdin.readline().strip().split()))
S = input().strip()

P = [0]*N
cnt = 0

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

for i in range(Q):
    l,r = list(map(int,stdin.readline().strip().split()))
    print(P[r-1] - P[l-1])

Solution (Python):
from sys import stdin
import numpy as np
n, q = map(int, stdin.readline().rstrip().split())
s = input()
lr = [list(map(int, stdin.readline().rstrip().split())) for _ in range(q)]
cum = np.array([0 for _ in range(n-1)])
for i in range(n-1):
    if s[i:i+2] == "AC":
        cum[i] = 1
cum2 = np.cumsum(cum)
for l, r in lr:
    if l == 1: print(cum2[r-2])
    else: print(cum2[r-2] - cum2[l-2])

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

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

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

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

Solution (Python):
n, q = map(int, input().split())
s = input()
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()

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

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

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

Solution (Python):
n, q = map(int, input().split())
s = input()
a = [0]*(len(s)+5)

for i in range(len(s)):
    if s[i:i+2] == 'AC':
        a[i+2] = a[i+1]+1
    else:
        a[i+2] = a[i+1]


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

Solution (Python):
import bisect

N,Q = map(int,input().split())
S = input()
a = [input().split() for l in range(Q)]
x = []
for i in range (0,N-1):
  if (S[i] == "A") and (S[i+1] == "C"):
    x.append(i)
for k in range (0,Q):
  l = int(a[k][0]) - 1
  r = int(a[k][1]) - 1
  p = bisect.bisect_left(x,l)
  q = bisect.bisect_left(x,r)
  print(q-p)

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

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

count_list = [0] * (N+1)
count = 0
for n in range(N-1):
    if (S[n] == 'A' and S[n+1] == 'C'):
        count += 1
    count_list[n+2] = count

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

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

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

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

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

for _ in range(Q):
  start,end = map(int,input().split())
  print(arr[end-1]-arr[start-1])

Solution (Python):
n, m = 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(m):
    a, b = 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):
  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())
lr = []
for i in range(Q):
    l, r = map(int, input().split())
    lr.append([l-1, r-1])
AC = []
pre = None
cnt = 0
for c in S:
    if c == "A":
        pre = "A"
    elif pre == "A" and c == "C":
        cnt += 1
        pre = None
    elif pre == "A":
        pre = None
    AC.append(cnt)
for l, r in lr:
    print(AC[r] - AC[l])

Solution (Python):
from bisect import bisect_left
import sys
sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))

N, Q = inpl()
S = input()

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

for i in range(Q):
    l, r = inpl()
    Nl = bisect_left(ACs,l-1)
    Nr = bisect_left(ACs,r-1)
    print(Nr-Nl)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n, q = list(map(int, input().rstrip('\n').split()))
    s = str(input().rstrip('\n'))
    ls = [0] * n
    cnt = 0
    for i in range(1, n):
        if s[i] == "C" and s[i-1] == "A":
            cnt += 1
        ls[i] = cnt
    for i in range(q):
        l, r = list(map(int, input().rstrip('\n').split()))
        print(ls[r-1] - ls[l-1])


if __name__ == '__main__':
    slove()

Solution (Python):
from sys import stdin


def main():
    def iterate_tokens():
        for line in 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)) - 1
        R[i] = int(next(tokens)) - 1
    AC = [int()] * N
    pre = None
    cnt = 0
    for i, c in enumerate(S):
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC[i] = cnt
    for i in range(Q):
        print(AC[R[i]] - AC[L[i]])
    return


main()

Solution (Python):
from sys import stdin


def iterate_tokens():
    for line in stdin:
        for word in line.split():
            yield word


def main():
    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)) - 1
        R[i] = int(next(tokens)) - 1
    AC = [int()] * N
    pre = None
    cnt = 0
    for i, c in enumerate(S):
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC[i] = cnt
    for i in range(Q):
        print(AC[R[i]] - AC[L[i]])
    return


main()

Solution (Python):
from sys import stdin


def iterate_tokens():
    for line in stdin:
        for word in line.split():
            yield word


def main():
    tokens = iterate_tokens()
    N = int(next(tokens))
    Q = int(next(tokens))
    S = next(tokens)
    L = [0] * Q
    R = [0] * Q
    for i in range(Q):
        L[i] = int(next(tokens)) - 1
        R[i] = int(next(tokens)) - 1
    AC = [0] * N
    pre = None
    cnt = 0
    for i, c in enumerate(S):
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC[i] = cnt
    for i in range(Q):
        print(AC[R[i]] - AC[L[i]])
    return


main()

Solution (Python):
from sys import stdin


def iterate_tokens():
    for line in stdin:
        for word in line.split():
            yield word


def main():
    tokens = iterate_tokens()
    next(tokens)
    Q = int(next(tokens))
    S = next(tokens)
    L = []
    R = []
    for i in range(Q):
        L.append(int(next(tokens)))
        R.append(int(next(tokens)))
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in zip(L, R):
        print(AC[r - 1] - AC[l - 1])
    return


main()

Solution (Python):
from sys import stdin


def iterate_tokens():
    for line in stdin:
        for word in line.split():
            yield word


def main():
    tokens = iterate_tokens()
    next(tokens)
    Q = int(next(tokens))
    S = next(tokens)
    L = []
    R = []
    for i in range(Q):
        L.append(int(next(tokens)) - 1)
        R.append(int(next(tokens)) - 1)
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for i in range(Q):
        print(AC[R[i]] - AC[L[i]])
    return


main()

Solution (Python):
from sys import stdin


def iterate_tokens():
    for line in stdin:
        for word in line.split():
            yield word


def main():
    tokens = iterate_tokens()
    next(tokens)
    Q = int(next(tokens))
    S = next(tokens)
    L = []
    R = []
    for i in range(Q):
        L.append(int(next(tokens)) - 1)
        R.append(int(next(tokens)) - 1)
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in zip(L, R):
        print(AC[r] - AC[l])
    return


main()

Solution (Python):
from sys import stdin


def main():
    lines = stdin.readlines()
    S = lines[1]
    lr = [[int(j) - 1 for j in i.split()] for i in lines[2:]]
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in lr:
        print(AC[r] - AC[l])
    return


main()

Solution (Python):
from sys import stdin


def main():
    lines = stdin.readlines()
    S = lines[1]
    lr = [[int(j) - 1 for j in i.split()] for i in lines[2:]]
    AC = [0]
    pre = 0
    for c1, c2 in zip(S[:], S[1:]):
        if c1 == "A" and c2 == "C":
            pre += 1
        AC.append(pre)
    for l, r in lr:
        print(AC[r] - AC[l])
    return


main()

Solution (Python):
from sys import stdin


def main():
    lines = stdin.readlines()
    N = int(lines[0].split()[0])
    S = lines[1]
    lr = [[int(j) - 1 for j in i.split()] for i in lines[2:]]
    AC = [0] * N
    pre = 0
    for i, c1, c2 in zip(range(1, N), S[:], S[1:]):
        if c1 == "A" and c2 == "C":
            pre += 1
        AC[i] = pre
    for l, r in lr:
        print(AC[r] - AC[l])
    return


main()

Solution (Python):
from sys import stdin


def main():
    lines = stdin.readlines()
    N = int(lines[0].split()[0])
    S = lines[1]
    lr = [[int(j) - 1 for j in i.split()] for i in lines[2:]]
    AC = [0] * N
    pre = 0
    for i, c1, c2 in zip(range(1, N), S[:], S[1:]):
        AC[i] += pre
        if c1 == "A" and c2 == "C":
            AC[i] += 1
        pre = AC[i]
    for l, r in lr:
        print(AC[r] - AC[l])
    return


main()

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

encount_func = {}
count = 0
encount_func[0] = 0
for i in range(1,N):
    check_str = S[i-1] + S[i]
    
    if check_str == "AC":
        count += 1
        encount_func[i] = count
    else:
        encount_func[i] = count





ans = []
for _ in range(Q):
    L, R = map(int, input().split())
    ans.append(encount_func[R-1] - encount_func[L-1])

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

Solution (Python):
N, Q = map(int, input().split())
S = input()
q =[]
temp = [0] * (N+1)
tmp = 0
for i in range(1,N):
    if S[i-1] == "A":
        if S[i] == "C":
            tmp +=1
    temp[i+1] = tmp
for j in range(Q):
    inp = input().split()
    print(temp[int(inp[1])] - temp[int(inp[0])])

Solution (Python):
n,q=map(int,input().split())
s=input()+"P"
A=[list(map(int,input().split())) for i in range(q)]
B=[0]*(n+1)
cnt=0
for i in range(1,n):
    if s[i-1]+s[i]=="AC":cnt +=1
    B[i+1]=cnt

for l,r in A:print(B[r]-B[l])

Solution (Python):
n,q=map(int,input().split()) 
s=input()
area=[]
for i in range(q):
    start,end=map(int,input().split())
    area.append([start,end])
num=[0,0]
total=0
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        total+=1
    num.append(total)
for i in range(q):
    print(num[area[i][1]]-num[area[i][0]])

Solution (Python):
import bisect

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

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

for i in range(len(lr)):
  left_index = bisect.bisect_left(AC_index,lr[i][0]-1)
  right_index = bisect.bisect_left(AC_index,lr[i][1]-1)
  print(right_index-left_index)

Solution (Python):
import bisect
n,q=map(int,input().split())
s=input()
lr=[[int(i) for i in input().split()] for j in range(q)]

li=[0]*(n-1)
check=0
for i in range(n-1):
    if s[i]=='A' and s[i+1]=='C':
        check+=1
    li[i]=check
for l,r in lr:
    if l>=2:
        print(li[r-2]-li[l-2])
    else:
        print(li[r-2])

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())
    print(t[r-1]-t[l-1])

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

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

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=list(input())
C=[0]
for i in range(1,N):
  if S[i-1]=="A" and S[i]=="C":
    C.append(C[i-1]+1)
  else:
    C.append(C[i-1])

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()
C = [0] * len(S)
for i, c in enumerate(S):
    if i != 0 and c == 'C' and S[i-1] == 'A':
        C[i] += 1
    C[i] += C[i - 1]
ans = []
for i in range(Q):
    l, r = map(int, input().split())
    ans.append(C[r-1] - C[l-1])
for i in ans:
    print(i)

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

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

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

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

Solution (Python):
N , Q = map(int,input().split())
S = list(input())
slice_list = []
for _ in range(Q):
    l , r =map(int,input().split())
    slice_list.append([l - 1,r - 1])
cnt_list = [0] * (N + 1)

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

for i in range(Q):

    print(cnt_list[slice_list[i][1]] - cnt_list[slice_list[i][0]])

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

s = input()

count = [0] * n

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

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

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

b=[]
sum=0
b.append(sum)
for x in a:
    sum+=x
    b.append(sum)

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

Solution (Python):
N,Q=map(int,input().split())
S=list(str(input()))
lst=[[0,0] for _ in range(Q)]
for i in range(Q):
  lst[i]=list(map(int,input().split()))
tmp=[0]*N
for i in range(1,N):
  if S[i-1]=='A' and S[i]=='C':
    tmp[i]=1+tmp[i-1]
  else:
    tmp[i]=tmp[i-1]
for i in range(Q):
  a,b=lst[i][0],lst[i][1]
  print(tmp[b-1]-tmp[a-1])

Solution (Python):
n, q = map(int, input().split(' '))
s = str(input())
checker = [0]
counter = 0
for i in range(1, n):
    if s[i-1] == 'A' and s[i] =='C':
        counter += 1
    checker.append(counter)
result = []
for i in range(q):
    L, r = map(int, input().split(' '))
    a = checker[L-1]
    b = checker[r-1]
    result.append(b-a)
for i in result:
    print(i)

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

ans = [0 for _ in range(N+1)]
for i in range(1, N):
    if (str[i-1] == "A"):
        if (str[i] == "C"):
            ans[i] = ans[i-1] + 1
        else:
            ans[i] = ans[i-1]
    else:
        ans[i] = ans[i-1]
        ans[i+1] = ans[i-1]
        i += 1

for l1, l2 in length:
    
    print(ans[l2-1] - ans[l1-1])

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

ans = [0 for _ in range(N)]
for i in range(1, N):
    if (str[i-1] == "A"):
        if (str[i] == "C"):
            ans[i] = ans[i-1] + 1
        else:
            ans[i] = ans[i-1]
    else:
        ans[i] = ans[i-1]
        if i != N-1:
            ans[i+1] = ans[i-1]
        i += 1

for l1, l2 in length:
    
    print(ans[l2-1] - ans[l1-1])

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

for l, r in length:
  print(AC_list[r-1] - AC_list[l-1])

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

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())
str = input()
length = [list(map(int, input().split())) for _ in range(Q)]

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

for l1, l2 in length:
    
    print(ans[l2-1] - ans[l1-1])

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

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

for l1, l2 in length:
    
    print(ans[l2-1] - ans[l1-1])

Solution (Python):
import re, bisect

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

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



match_index_list = [m.span() for m in re.finditer('AC', S)]
match_first_index_list = []

for i in range(len(match_index_list)):
    match_first_index_list.append(match_index_list[i][0])

match_last_index_list = [x+1 for x in match_first_index_list]

for question in range(Q):
    print(bisect.bisect_right(match_last_index_list, r[question]) - bisect.bisect_left(match_first_index_list, l[question]))

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

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

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

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

Solution (Python):
import re
N, Q = map(int, input().split())
S = input()
query = [list(map(int, input().split())) for _ in range(Q)]
s = re.sub(r"AC", "0", S)
accum = [0 for _ in range(N)]
for i in range(1, N):
    accum[i] = accum[i-1]
    if S[i-1]=="A" and S[i]=="C":
        accum[i] += + 1

for l,r in query:
    print(accum[r-1]-accum[l-1])

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


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

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

cnt = 0
cnt_list = []

for i in range(n):
    if i < 1:
        cnt_list.append(0)
        continue
    if s[i-1:i+1] == "AC":
        cnt += 1
    cnt_list.append(cnt)

for start, end in ranges:
    print(cnt_list[end-1] - cnt_list[start-1])

Solution (Python):
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
i, c = 0, 0
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 p in lr:
    l, r = p[0] - 1, p[1] - 1
    print(int(ac[r] - ac[l]))

Solution (Python):
import sys
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, q = na()
s = ns()
su = [0] * (n + 1)

ac = 0
if s[0] =="A":
    ac = 1
for i in range(1, n):
    si = s[i]
    if si == "A":
        ac = 1

    elif si =="C" and ac == 1:
        su[i] = 1
        ac = 0
    else:
        ac = 0
    su[i] += su[i-1]




l, r = [], []
for _ in range(q):
    li, ri = na()
    l.append(li)
    r.append(ri)

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

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

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

L = [0]*(N+1)
R = [0]*N

tmp = 0
for ind,i in enumerate(s):
    if i == 1:
        tmp += 1
    L[ind+1] = tmp

tmp = 0
for i in range(N-2,-2,-1):
    if s[i] == 1:
        tmp += 1
    R[i+1] = tmp

R.append(0)
sums =sum(s)
for i in range(Q):
    ans = sums-L[LR[i][0]-1]-R[LR[i][1]]
    print(ans)

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

L = [0]*(N+1)
R = [0]*N

tmp = 0
for ind,i in enumerate(s):
    if i == 1:
        tmp += 1
    L[ind+1] = tmp

tmp = 0
for i in range(N-2,-2,-1):
    if s[i] == 1:
        tmp += 1
    R[i+1] = tmp

R.append(0)
sums =sum(s)
for i in range(Q):
    ans = sums-L[LR[i][0]-1]-R[LR[i][1]]
    print(ans)

Solution (Python):
N, Q = map(int, input().split())
S = str(input())
J=[0]*N


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


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

Solution (Python):
import re

n, q = map(int, input().split())
s = input()
count = [0] * len(s)
for ind, char in enumerate(s[1:], 1):
    if char == 'C' and s[ind-1] == 'A':
        count[ind] = count[ind-1] + 1
    else:
        count[ind] = count[ind-1]


answer = []

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

for ans in answer:
    print(ans)

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

counter = 0

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

Solution (Python):
N,Q=map(int,input().split())
S=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()
A = [0 for _ in range(n)]
C = [0 for _ in range(n)]
memo1 = [0 for _ in range(n)]
memo2 = [0 for _ in range(n)]

for i in range(n):
    if s[i]=="A":
        A[i] = 1
    elif s[i] =="C":
        C[i] = 1
    if i == 0:
        continue
    if A[i-1] and C[i]:
        memo1[i] = memo1[i-1] + 1
    else:
        memo1[i] = memo1[i-1]
for i in range(n-2,-1,-1):
    if A[i] and C[i+1]:
        memo2[i] = memo2[i+1] + 1
    else:
        memo2[i] = memo2[i+1]
total = memo2[0]
for _ in range(q):
    l,r = map(lambda x:int(x)-1,input().split())
    ans = total
    if l >0:
        ans -= memo1[l-1]
        if A[l-1] and C[l]:
            ans -=1
    if r<n-1:
        ans -= memo2[r+1]
        if A[r] and C[r+1]:
            ans -= 1
    print(ans)

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

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

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

for i in range(Q):
    print(min(L[LR[i][1]-1],R[LR[i][1]-1])-\
          min(L[LR[i][0]-1],R[LR[i][0]-1]))

Solution (Python):
N,Q = map(int, input().split())
S = input()
L = []
for i in range(Q):
    L.append([int(x) for x in input().split()])
    
ac_list = [0 for i in range(N)]
ac_num = 0
for i in range(1, N):
    pre = S[i-1]
    ac_list[i] = ac_list[i-1]
    if pre == "A" and S[i] == "C":
        ac_num += 1
        ac_list[i] = ac_num

for i in range(Q):
    ans = ac_list[L[i][1]-1] - ac_list[L[i][0]-1]
    print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))


n,q = inpl()
s = input()
qq = []
cnt = [0] * n
for i in range(q):
    a,b = inpl()
    qq.append([a,b])
for i in range(1,n):
    if s[i-1] == 'A' and s[i] == 'C':
        cnt[i] = cnt[i-1] + 1
    else:
        cnt[i] = cnt[i-1]
for i in qq:
    l = i[0]
    r = i[1]
    print(cnt[r-1] - cnt[l-1])