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 for i in range(len(s))]
count = 0
for j in range(len(s)-1):
    if s[j] == "A" and s[j+1] == "C":
        count += 1
    t[j+1] = count

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

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

Solution (Python):
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]

ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]

i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())

ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]

def main(N, Q, S, lrs):
    S2 = [0] * (N)
    for i in range(1, N):
        if S[i-1] == 'A' and S[i] == 'C':
            S2[i] = S2[i-1] + 1
        else:
            S2[i] = S2[i-1]
    for l, r in lrs:
        count = S2[r-1] - S2[l-1] 
        print(count)

N, Q = i2nn()
S = i2s()
lr = ss2nnn(ii2ss(Q))
main(N, Q, S, lr)

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

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

AC_appearance = [0] * len(S)
counter = 0
for i in range(1, len(S)):
    if S[i-1] == 'A' and S[i] == 'C':
        counter += 1
    AC_appearance[i] = counter 

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

Solution (Python):
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())



N, Q = mi()

S = li()
Alist = []
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        Alist.append(i)
Aset = set(Alist)
AClist = [0]*(N+1)
for i in range(N-1):
    if i in Aset:
        AClist[i + 2] = AClist[i + 1] + 1
    else:
        AClist[i+2] = AClist[i+1]
        

for i in range(Q):
    l, r = mi()
    if AClist[l - 1] != AClist[l]:
        print(AClist[r] - AClist[l])
    else:
        print(AClist[r] - AClist[l-1])

Solution (Python):
n,q=map(int, raw_input().split())
s=list(raw_input())
cum=0
cum_array=[0]
for p in range(len(s)-1):
    if s[p] == 'A' and s[p+1] == 'C':
        cum+=1
    cum_array.append(cum)
cum_array.append(cum)
for i in range(q):
    l,r=map(int, raw_input().split())
    print(cum_array[r-1]-cum_array[l-1])

Solution (Python):
import sys
n,q=input().split()
s=input();a=[0]*2
for i in range(2,int(n)+1):
 a+=[a[i-1]+s[i-2:i].count("AC")]
for e in sys.stdin:
 l,r=map(int,e.split())
 print(a[r]-a[l])

Solution (Python):
import numpy as np

N,Q=map(int,input().split())
y=input()
arr=np.zeros(len(y))
for i in range(len(y)-1):
    if y[i:i+2]=='AC':
        arr[i+1]=arr[i]+1
    else:
        arr[i+1]=arr[i]
              
for q in range(Q):
    l,r=map(int,input().split())
    print(int(arr[r-1]-arr[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=str(input())
a=[0]*(n+1)
a[0]=0
for i in range(n):
    if s[i:i+2]=="AC":
        a[i+1]=a[i]+1
    else:
        a[i+1]=a[i]+0
for i in range(q):
    b,c=map(int,input().split())
    print(int(a[c-1]-a[b-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):
l = input().split()
N,Q = int(l[0]),int(l[1])
S = input()
blue = [0] * N
for k in range(1,N):
  if S[k-1] == 'A' and S[k] == 'C':
    blue[k] = blue[k-1] + 1
  else:
    blue[k] = blue[k-1]
for i in range(1,Q+1):
  rl = input().split()
  r = int(rl[0])
  l = int(rl[1])
  print(
    blue[l-1] - blue[r-1])

Solution (Python):
N, Q = [int(x) for x in 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 = [int(x) for x in input().split()]
    print(t[r-1] - t[l-1])

Solution (Python):
def main():
    n, q = map(int, input().split())
    s = input()
    p = prepare(s)
    for _ in range(q):
        l, r = map(int, input().split())
        print(query(p, l, r))

def prepare(s):
    p = [0]
    for i in range(len(s) - 1):
        if s[i:].startswith('AC'):
            p.append(p[-1] + 1)
        else:
            p.append(p[-1])
    return p

def query(p, l, r):
    return p[r - 1] - p[l - 1]

main()

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

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


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

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

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

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

for i in range(Q):
    if LR[i][0] == 1:
        l = 0
    else:
        l = num_list[LR[i][0]-2]
    if LR[i][1] == N:
        r = num_list[N-2]
    else:
        r = num_list[LR[i][1]-2]
    print(r-l)

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

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

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

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

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

for i in range(Q):
    print(ac_place_list[tmp_list[i][1]-1]-ac_place_list[tmp_list[i][0]-1])

Solution (Python):
n,q = map(int,input().split())
s = input()
x = []
y = []
for i in range(q):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1) 

t = [0]*n

for i in range(n-1):
    if s[i+1] == "C" and s[i] == "A":
        t[i+1] = t[i]+1
    else:
        t[i+1] = t[i]
for i in range(q):
    ans = t[y[i]-1] - t[x[i]-1]
    print(ans)

Solution (Python):
n,q = map(int,input().split())
s = input()
x = []
y = []
for i in range(q):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1) 

t = [0]*n

for i in range(n-1):
    if s[i+1] == "C" and s[i] == "A":
        t[i+1] = t[i]+1
    else:
        t[i+1] = t[i]
for i in range(q):
    ans = t[y[i]-1] - t[x[i]-1]
    print(ans)

Solution (Python):


def solve():
    N, Q = list(map(int, input().split(" ")))
    S = input()
    L, R = [], []
    for i in range(Q):
        l, r = list(map(int, input().split(" ")))
        L.append(l)
        R.append(r)
    
    
    accumulations = [0] * N

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

    for i in range(Q):
        if L[i]-1 == 0:
            print(accumulations[R[i]-1])
            continue
        else:
            print(accumulations[R[i]-1] - accumulations[L[i]-1])
            continue


if __name__ == "__main__":
    solve()

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

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

Solution (Python):
import numpy as np

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

line = np.zeros([n,])
count = 0
for i in range(1,n):
    if (s[i-1:i+1]=="AC"): 
        count += 1
    line[i]=count 
        
for i in range(q):
    l,r = map(int,input().split())
    target = line[r-1] - line[l-1]
    print(int(target))

Solution (Python):
import itertools
n,q = map(int,input().split())
s = input()
lr = []
for i in range(q): lr.append(list(map(int, input().split())))
ac = [1 if i!=0 and 'AC'==s[i-1:i+1] else 0 for i in range(0,len(s))]
acc = list(itertools.accumulate(ac))
for i in lr: print(acc[i[1]-1]-acc[i[0]-1])

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

for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        counter += 1
    countlist += [counter]

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

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

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

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

Solution (Python):
N, Q = list(map(int, input().split()))
S = input()
c = 0
cl = [0 for i in range(N)]
cr = [0 for i in range(N)]
for i in range(0, N-1):
  cl[i+1] = cl[i]
  if S[i:i+2]=="AC":
    c += 1
    cl[i+1] += 1
for i in range(N-1, 0, -1):
  cr[i-1] = cr[i]
  if S[i-1:i+1]=="AC":
    cr[i-1] += 1
for i in range(Q):
  li, ri = list(map(int, input().split()))
  print(c-cl[li-1]-cr[ri-1])

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

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


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

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

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

ruisekiwa += [ ruisekiwa[-1] ]

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

Solution (Python):
from sys import stdin
n, q = [int(_) for _ in stdin.readline().rstrip().split()]
s = list(stdin.readline().rstrip())
data = [list(map(int, stdin.readline().rstrip().split())) for _ in range(q)]
l = [0]
for i in range(n):
    l.append(l[i]+1 if i+1 < n and s[i] == 'A' and s[i+1] == 'C' else l[i])
for d in data:
    print(l[d[1]-1]-l[d[0]-1])

Solution (Python):
N,Q=map(int,(input()).split())
S=input()
l_list=[]
r_list=[]
for i in range(Q):
  l,r=input().split()
  l_list.append(int(l))
  r_list.append(int(r))
count=0
AC_count=[0]
for i in range(1,N+2):
  if S[i-1:i+1]=="AC":
    count+=1
  AC_count.append(count)
k=0
for j in range(Q):
  k=AC_count[r_list[j]-1]-AC_count[l_list[j]-1]
  print(k)

Solution (Python):
N,Q=map(int,(input()).split())
S=input()
l_list=[]
r_list=[]
for i in range(Q):
  l,r=input().split()
  l_list.append(int(l))
  r_list.append(int(r))
count=0
AC_count=[0]
for i in range(1,N+2):
  if S[i-1:i+1]=="AC":
    count+=1
  AC_count.append(count)
AC_count.append(count)
k=0
for j in range(Q):
  k=AC_count[r_list[j]-1]-AC_count[l_list[j]-1]
  print(k)

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

for i in range(q):
  print(l[x[i][1]-1]-l[x[i][0]-1])

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

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

cnt = 0
before = [0] * len(s)

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

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

Solution (Python):
from sys import stdin

n, q = map(int, stdin.readline().split())
s = stdin.readline().strip()
counts = [0 for i in range(n)]
count = 0
for i in range(1, n):
    if s[i-1:i+1] == 'AC':
        count += 1
    counts[i] = count

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

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

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

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

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

for lr in lrs:
    print(total[lr[1] - 1] - total[lr[0] - 1])

Solution (Python):
N, Q = map(int, raw_input().split())
string = raw_input()
cnt = [0]
for i in range(N):





    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    
    pare = map(int, raw_input().split())
    print(cnt[pare[1]] - cnt[pare[0]])

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

dp = [0 for column in range(n)]

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

for _ in range(q):
    i, j =  map(int, input().split())
    print(dp[j-1] - dp[i-1])

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

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

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

Solution (Python):
N,Q = map(int,input().split())
s = str(input())
data = [0]
cnt = 0
for i in range(1,N):
    if s[i-1] == 'A' and s[i] == 'C':
        cnt += 1
        data.append(cnt)
    else :
        data.append(cnt)
for i in range(Q):
    l,r = map(int,input().split())
    r -= 1
    l -= 1
    ans = data[r] - data[l]
    print(ans)

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

accum = [0 for _ in range(n + 1)]

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

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

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

li = [0]*N
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        li[i+1] = 1
ans = list(itertools.accumulate(li))
k = []
for j in range(Q):
    a,b = [int(i) for i in input().split()]
    k.append(ans[b-1]-ans[a-1])

[print(i) for i in k]

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

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

data=[0]
count=0
for i in range(1,len(s)):
    if s[i-1]=="A" and s[i]=="C":
        count+=1
    data.append(count)

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

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

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


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

Solution (Python):

import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    mem = [0 for i in range(N)]
    for i in range(1,len(S)):
        if S[i] == "C" and S[i - 1] == "A":
            mem[i] = mem[i-1]+1
        else:
            mem[i] = mem[i-1]
    for i in range(Q):
        start = l[i] - 1
        end = r[i] - 1
        print(mem[end] - mem[start])
    return



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):
import sys
input = sys.stdin.readline

n, q = map(int, input().split())
s = input()
ac_list = [0]

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

for _ in range(q):
  first, last = map(int, input().split())
  print(ac_list[last-1] - ac_list[first-1])

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




c = 0
ac_list = []
for i in range(len(S)) :
    
    if (S[i] == "C" and i > 0 and S[i-1] == "A") :
        c += 1
        ac_list.append(c)
    else :
        ac_list.append(c)

for item in q_list :
    
    ac_count = ac_list[item[1]-1] - ac_list[item[0]-1]
    print(ac_count)

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

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

Solution (Python):
N, Q = map(int, input().split())
S = input()
a = [0]
total = 0
for k in range(1,N, 1):
	if S[k - 1] == 'A':
		if S[k] == 'C':
			total = total + 1
	a.append(total)
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()
memo = [0]*(N+1)
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        memo[i+1] = memo[i]+1
    else:
        memo[i+1] = memo[i]
ans = []
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(memo[r-1]-memo[l-1])

print('\n'.join(map(str, ans)))

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

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 = str(input())
SD = {}

cnt = 0
for n in range(1, N):
    if S[n-1] + S[n] == "AC":
        cnt += 1
    SD[n] = cnt

for q in range(1, Q+1):
    l, r = map(int, input().split())
    print(SD.get(r-1, 0)-SD.get(l-1, 0))

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

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

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

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

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

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

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

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

Solution (Python):
N,Q = map(int,input().split())
S = input()
Slist = [0 for x in range(0,N)]
L = list()
R = list()
number = 0

for x in range(0,N-1):
    if S[x] is 'A' and S[x+1] is 'C':
        number += 1
    Slist[x+1] = number

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

for x in range(0,Q):
    answer = Slist[R[x]-1] - Slist[L[x]-1]
    print(answer)

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

Solution (Python):

"""
Created on Mon Apr  8 10:49:27 2019

@author: adachi-lab
"""


input_1 = input()
S = input()
l = []
r = []

N = input_1.split()[0]
Q = input_1.split()[1]

for i in range(int(Q)):
    input_3 = input()
    l.append(int(input_3.split()[0]))
    r.append(int(input_3.split()[1]))
    
s_1 = []
x = 0
for w in range(len(S)-1):
    if S[w] == 'A' and S[w+1] == 'C':
        x += 1
        s_1.append(x)
    else:
        s_1.append(x)
        
s_1.insert(0,0)
w = []

for j in range(len(l)):
    p = s_1[r[j]-1]-s_1[l[j]-1]
    w.append(p)
    
for t in range(len(w)):
    print(w[t])

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

rightmax = [0 for i in range(N+1)]
before = S[0]
nowAC = 0
for i, c in enumerate(S):
    if before == "A" and c == "C":
        nowAC += 1
    before = c
    rightmax[i+1] = nowAC
for query in LR:
    l, r = map(int, query.split(" "))
    print(rightmax[r] - rightmax[l])

Solution (Python):
n, q = map(int, input().split())
s = input()
t = [0] * (n + 1)
nl = set(range(n))
for i in nl:
    t[i + 1] = t[i] + (1 if s[i:i + 2] == 'AC' else 0)
ql = set(range(q))
for i in ql:
    l1, l2 = map(int, input().split())
    ans = t[l2-1] - t[l1-1]
    print(ans)

Solution (Python):
n, q = map(int, input().strip().split(' '))
s = input()
ac = []
kazu = 0
for i in range(n-1):
    if s[i:i+2] == 'AC':
        kazu = kazu + 1
        ac.append(kazu)
    else:
        ac.append(kazu)
ac.append(0)
for i in range(q):
    num = 0
    l, r = map(int, input().strip().split(' '))
    print(ac[r-2]-ac[l-2])

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

Solution (Python):
import sys
N,Q = map(int,sys.stdin.readline().rstrip().split())
S = sys.stdin.readline().rstrip()
D = [0]
DD = 0
for i in range(1,len(S)):
  if S[i-1] + S[i] == "AC":
    DD += 1
  D.append(DD)
for _ in range(Q):
  l,r  = map(int,sys.stdin.readline().rstrip().split())
  print(D[r-1]- D[l-1])
  del l
  del r

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

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

for l,r in qs:
    print(cums[r] - cums[l])

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

Solution (Python):

N,Q = list(map(int,input().split()))
S = input()
L = []
R = []
for i in range(Q):
    a = list(map(int,input().split()))
    L.append(a[0])
    R.append(a[1])

S_count = []
count = 0
A_flag = False

for i in range(len(S)):
    if A_flag == True:
        if S[i] == "C" :
            count += 1
   
    if S[i] == "A" :
        A_flag = True
    else:
        A_flag = False
    S_count.append(count)

for i in range(Q):
    print(S_count[R[i] - 1] - S_count[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
for i in range(n-1):
    if s[i]=='A' and s[i+1]=='C':
        a[i]=1
        a[i+1]=1
S=[0]*n
S[0]=a[0]
for i in range(1, n):
    S[i]=S[i-1]+a[i]
S=[0]+S
for l, r in lr:
    print(S[r]//2-(S[l-1]+1)//2)

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

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

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

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

Solution (Python):
N, Q = map(int, input().split())
L, R = [None] * Q, [None] * Q

S = input()

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

counts = [0] * N
count_tmp = 0
is_before_char_A = False

for i in range(N):
    if S[i] == 'A':
        is_before_char_A = True
        counts[i] = count_tmp
        continue
    if S[i] == 'C' and is_before_char_A:
        count_tmp += 1

    counts[i] = count_tmp
    is_before_char_A = False
    
    



for i in range(Q):
    print(counts[R[i] - 1] - counts[L[i] - 1])

Solution (Python):
N, Q = map(int, input().split())
L, R = [None] * Q, [None] * Q

S = input()

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

counts = [0] * N
count_tmp = 0
is_before_char_A = False

for i in range(N):
    if S[i] == 'A':
        is_before_char_A = True
        counts[i] = count_tmp
        continue
    if S[i] == 'C' and is_before_char_A:
        count_tmp += 1

    counts[i] = count_tmp
    is_before_char_A = False
    
    



for i in range(Q):
    print(counts[R[i] - 1] - counts[L[i] - 1])

Solution (Python):
N, Q = map(int, input().split())
L, R = [None] * Q, [None] * Q

S = input()

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

counts = [0] * N
count_tmp = 0

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



for i in range(Q):
    print(counts[R[i] - 1] - counts[L[i] - 1])

Solution (Python):
length, quests = map(int, input().rstrip().split())
string = input()
totals = [0]

count = 0
for i in range(1, len(string)):
    if string[i-1] == "A" and string[i] == "C":
        count += 1
    totals.append(count)

for i in range(quests):
    left, right = map(int, input().rstrip().split())
    print(totals[right-1] - totals[left-1])

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

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

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

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

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

t = [0]
ct = 0
for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        ct += 1
    t.append(ct)

for i in list_lr:
    l, r = i[0], i[1]
    print(t[r-1]-t[l-1])

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

Solution (Python):


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

    
    count = [0] * len(S)

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

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

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


if __name__ == '__main__':
    main()

Solution (Python):
nq = list(map(int,input().split()))
q=nq[1]
s=list(input())
lr=[0 for i in range(q)]
for i in range(q):
    lr[i]=list(map(int,input().split()))
c=[0 for i in range(len(s))]
for i in range(len(s)):
    if i ==0:
        c[i]=0
    else:
        if s[i-1]=='A' and s[i]=='C':
            c[i] = c[i-1]+1
        else:
            c[i] = c[i-1]
for i in range(q):
    print(c[lr[i][1]-1]-c[lr[i][0]-1])