Problem:
 Score : 300 points    Problem Statement You are given a string S of length N consisting of A , C , G and T . Answer the following Q queries:   Query i ( 1 \leq i \leq Q ): You will be given integers l_i and r_i ( 1 \leq l_i < r_i \leq N ). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does AC occurs as a substring?       Notes A substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T .  For example, the substrings of ATCODER include TCO , AT , CODER , ATCODER and (the empty string), but not AC .      Constraints  2 \leq N \leq 10^5  1 \leq Q \leq 10^5  S is a string of length N .  Each character in S is A , C , G or T .  1 \leq l_i < r_i \leq N         Input Input is given from Standard Input in the following format:  N  Q  S  l_1  r_1  :  l_Q  r_Q       Output Print Q lines. The i -th line should contain the answer to the i -th query.        Sample Input 1 8 3
ACACTACG
3 7
2 3
1 8      Sample Output 1 2
0
3   Query 1 : the substring of S starting at index 3 and ending at index 7 is ACTAC . In this string, AC occurs twice as a substring.  Query 2 : the substring of S starting at index 2 and ending at index 3 is CA . In this string, AC occurs zero times as a substring.  Query 3 : the substring of S starting at index 1 and ending at index 8 is ACACTACG . In this string, AC occurs three times as a substring.

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

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








wa = [0]

for index in range(1, len(s)):

    if s[index - 1] == 'A' and s[index] == 'C':
        wa.append(wa[index - 1] + 1)
    else:
        wa.append(wa[index - 1])

for row in lr:
    start = row[0] - 1
    end = row[1] - 1

    diff = wa[end] - wa[start]
    print(diff)

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

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

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

"""

for i in range(int(Q)):
	count = 0
	l,r = map(int, input().split(" "))
	for j in range(r-l):
		if sentence[l-1+j:l+j+1] == "AC":
			count += 1
	print(count)

"""





AC_list = [0]*(N)
count = 0
for i in range(N-1):
	if sentence[i : i+2] == "AC":
		count += 1
	AC_list[i+1] = count

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

Solution (Python):
def resolve():
    
    N, Q = map(int, input().split())
    S = 'X' + input()
    l = [0]
    r = [0]
    for i in range(Q):
        ll, rr = map(int, input().split())
        l.append(ll)
        r.append(rr)
    
    
    c = [0] * (N + 1)
    for i in range(2, N + 1):
        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(1, Q+1):
        cr = c[r[i]]
        cl = c[l[i]]

        print(cr - cl)
        
resolve()

Solution (Python):
import collections
import itertools

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

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

A = list(itertools.accumulate(A))
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()
 
ACDP=[0]*N
Aflag=0
ACcount=0
for i in range(len(S)):
  if S[i]=='C' and Aflag==1:
    ACcount+=1
  if S[i]=='A':
    Aflag=1
  else:
    Aflag=0
  ACDP[i]=ACcount

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

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

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

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

cnt, buf = [0] * (N + 1), None
for i in range(N):
    s = S[i]
    cnt[i + 1] = cnt[i]
    if buf == 'A' and s == 'C':
        cnt[i + 1] += 1
    buf = s

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

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

Solution (Python):
import math
N,Q = list(map(int,input().split(" ")))
S = input()
nums = [0] * len(S)
for i,(s1,s2) in enumerate(zip(S[:-1],S[1:])):
    if s1 == "A" and s2 == "C":
        nums[i+1] += nums[i] + 1
    else:
        nums[i+1] += nums[i]
ls = []
rs = []
for i in range(Q):
    l,r = list(map(int,input().split(" ")))
    l -= 1
    r -= 1
    ls.append(l)
    rs.append(r)
for l,r in zip(ls,rs):
    print(nums[r]-nums[l])

Solution (Python):
from itertools import accumulate

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

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

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    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):
        start, end = map(int, input().split())
        print(t[end - 1] - t[start - 1])
    
    
if __name__ == '__main__':
    main()

Solution (Python):
def solve(string):
    n, q, s, *lr = string.split()
    n = int(n)
    c = [0] * n
    count = 0
    for i in range(n):
        if i == 0:
            continue
        if s[i - 1:i + 1] == "AC":
            count += 1
        c[i] = count

    lr = list(map(int, lr))
    return "\n".join([str(c[r - 1] - c[l - 1]) for l, r in zip(lr[::2], lr[1::2])])


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(m + 1)])))

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

L = []
for i in range(Q):
  L.append([int(i) for i in input().split()])
  
for i in range(N-1):
  if S[i] == "A" and S[i+1] == "C":
    S = S[:i] + "a" + S[i+1:]

l = []
c = 0
for i in range(N):
  l.append(c)
  if S[i] == "a":
    c += 1
  

for i in range(Q):
  print(l[L[i][1]-1] - l[L[i][0]-1])

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

Solution (Python):
n,q = map(int,input().split())
S = input()
b = [0]*(n+1)
for i in range(n-1):
    if S[i] == 'A' and S[i+1] == 'C':
       b[i+1] += 1
from itertools import accumulate
b = list(accumulate(b))

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

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

Solution (Python):
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, q = read_line(int, int)
s, = read_line(str)

m = [0 for _ in range(len(s) + 1)]

c = 0
for i in range(len(s)):
    if s[i:i+2] == 'AC':
        c += 1
    m[i + 1] = c

for i in range(q):
    l, r = read_line(int, int)

    if c == 0:
        print(0)
        continue
    print(m[r - 1] - m[l - 1])

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

counter = [0]*(n+1)
count=0
for i,s in enumerate(base):
    if i < n-1 and s=="A" and base[i+1]=="C":
        count+=1
    counter[i+1]=count

ans=[]
for i in range(q):
    l,r = map(int,input().split())
    ans.append(str(counter[r-1]-counter[l-1]))
print('\n'.join(ans))

Solution (Python):
N,Q = map(int,input().split())
S = list(input())
AC_list=[]
sum_AC=0
sum_list=[]
Ans=[]

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

    sum_AC = sum_AC+int(AC_list[i])
    sum_list.append(sum_AC)

for j in range(Q):

    l,r=map(int,input().split())
    if l == 1 :
        Ans.append(sum_list[r-2])
    else:
        Ans.append(sum_list[r-2]-sum_list[l-2])

for k in range(Q):
    print(Ans[k])

Solution (Python):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, Q = MAP()
S = list(input())
lr = [LIST() for _ in range(Q)]

lis = [0]*N

for i, x in enumerate(S):
    if (i == N-1):
        break
    else:
        if x == 'A' and S[i + 1] == 'C':
            lis[i+1] = lis[i]+1
        else:
            lis[i+1] = lis[i]


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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, Q = MAP()
S = input()
lr = [LIST() for _ in range(Q)]

accum = []
count = 0

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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
S = input()
dp = [0]*(N+1)
cnt = 0
for i in range(2,N+1):
    if S[i-1] == "C" and S[i-2] == "A":
        cnt += 1
    dp[i] = cnt
ans = []
for _ in [0]*Q:
    l, r = map(int, input().split())
    ans.append(dp[r] - dp[l])
print(*ans, sep="\n")

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

lis = [0] * len(S)
for i in range(len(S)):

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


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

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

lis = [0] * len(S)
for i in range(len(S)):

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


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

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

lis = [0] * len(S)
for i in range(len(S)):

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


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

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

lis = [0] * len(S)
for i in range(len(S)):

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


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

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

lis = [0] * len(S)
for i in range(len(S)):

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


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

Solution (Python):
import bisect

n, q = [int(i) for i in input().split()]
s = input()
positions = []

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

for i in range(q):
    l, r = [int(i) for i in input().split()]
    l_index = bisect.bisect_left(positions, l)
    r_index = bisect.bisect_left(positions, r)
    print(r_index - l_index)

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

for i in range(1,n):
    if (s[i]=="C") & (s[i-1]=="A"):
        counter = counter + 1
    ac_num.append(counter)

rng = [0,0]
result = []

for i in range(q):
    rng[0],rng[1] = map(int,input().split(" "))
    result.append(ac_num[rng[1]-1]-ac_num[rng[0]-1])

for i in result:
    print(i)

Solution (Python):
from itertools import*
n,q=map(int,input().split())
s=input()
dp=[0]*n
for i in range(n-1):
    if s[i:i+2]=="AC":
        dp[i+1]=1
x=list(accumulate(dp))
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()

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

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

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

for i in range(Q):
	f,t = list(map(int,input().split()))
	print(sums[t-1]-sums[f-1])

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

count = 0
cum_sum = []
for i in range(N):
    if i > 0 and S[i - 1] == 'A' and S[i] == 'C':
        count += 1
    cum_sum.append(count)

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

Solution (Python):


N,Q = map(int, input().split())
S = input()
cnt_list = [0]

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

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

list = [0]*N

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

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

Solution (Python):
import sys


def inp():
    return sys.stdin.readline().strip()


n, q = map(int, inp().split())
s = inp()
a = [0] * n

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

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

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

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


        
for i in range(Q):
    l = ls[i]
    r = rs[i]
    print(count[r] - count[l])

Solution (Python):
N, Q = [int(i) for i in input().split()]
S = list(input())
term = [[int(i) for i in input().split()] for x in range(Q)]
ACs = [0 for i in range(N)] 
ans = []

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

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

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

acc[N-1] = acc[N-2]
for i in range(Q):
    l,r = map(int,input().split(" "))
    if l > 1:
        ans = acc[r-1] - acc[l-2]
    else:
        ans = acc[r-1]
    if a[r-1] == 1:
        ans -= 1
    
    print(ans)

Solution (Python):
N, Q = [int(i) for i in input().split()]
S = input()
lr = []
for i in range(Q):
    l, r = input().split(" ")
    lr.append((int(l)-1, int(r)-1))
    

c = [0 for _ in range(N)]
for i in range(N-1)[::-1]:
    if S[i] == "A" and S[i+1] == "C":
        c[i] = c[i+1] + 1
    else:
        c[i] = c[i+1]
        
for i in range(Q):
    l, r = lr[i]
    a = c[l] - c[r]
    print(a)

Solution (Python):
N, Q = [int(i) for i in input().split()]
S = input()
lr = []
for i in range(Q):
    l, r = input().split(" ")
    lr.append((int(l)-1, int(r)-1))
    

c = [0 for _ in range(N)]
for i in range(N-1)[::-1]:
    if S[i] == "A" and S[i+1] == "C":
        c[i] = c[i+1] + 1
    else:
        c[i] = c[i+1]
        
for i in range(Q):
    l, r = lr[i]
    a = c[l] - c[r]
    if r < len(S) - 1 and c[r] == "A" and c[r] == "C":
        a -= 1
    print(a)

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

for q in range(Q):
    l, r = map(int, input().split())
    if S[l - 1] != 'C':
        l -= 1
    print(asum[r] - asum[l])

Solution (Python):
n,m=map(int,input().split())
s=input()
ans=[0]*n
count=0
for i in range(n-1):
  ans[i]=count
  if s[i]=='A' and s[i+1]=='C':
    count+=1
ans[n-1]=count
for i in range(m):
  a,b=map(int,input().split())
  print(ans[b-1]-ans[a-1])

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

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

def isAC(i):
    return s[i:i + 2] == "AC"

cs = [0] * n
for i, v in enumerate(s[:-1]):
    if isAC(i):
        cs[i] = 1

cs.insert(0, 0)
for i in range(1, len(cs)):
    cs[i] += cs[i - 1]

for query in range(q):
    left, right = map(int, input().split())
    result = cs[right] - cs[left - 1]
    if right < n and isAC(right - 1):
        result -= 1
    print(result)

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

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

AC = [S[i : i + 2] == 'AC' for i in range(len(S) - 1)]

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

def solve(l, r):
    return nAC[r - 1] - nAC[l - 1]

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

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

Solution (Python):
N,Q = list(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+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):
    print(t[y[i]-1]-t[x[i]-1])

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

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()
target = 'AC'
shiftID = len(target) - 1

found_id = []

for i in range(N-shiftID):
    if S[i:i+len(target)] == target:
        found_id.append(i)

found_count = [0 for _ in range(N+1)]

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

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

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

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

Solution (Python):
n,q=map(int,input().split())
s=input()
list_ac=[]
number=0
state=0
for i in range(0,len(s)):
    if s[i]=='A':
        state=1
        list_ac.append(number)
    elif s[i]=='C':
        if state==1:
            number=number+1   
        list_ac.append(number)
        state=0
    else:
        state=0
        list_ac.append(number)
for i in range(0,q):
    l,r=map(int,input().split())
    print(list_ac[r-1]-list_ac[l-1])

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

Solution (Python):
n,q=map(int,input().split())
s=input()
list_ac=[0]
number=0
for i in range(0,n):
    if s[i:i+2]=='AC':
        number=number+1
        list_ac.append(number)
    else:
        list_ac.append(number)
for i in range(0,q):
    l,r=map(int,input().split())
    print(list_ac[r-1]-list_ac[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()


t = [0] * n
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        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 = str(input())
position = [0] * N
count = 0
for i in range(N-1):
    if S[i] == "A" and S[i + 1] == "C":
        count += 1
    position[i+1] = count
answers = []
for i in range(Q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    answer = position[r] - position[l]
    answers.append(answer)
for i in range(Q):
    print(answers[i])

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

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

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


for i in range(q):
    st, en = qs[i]
    print(counts[en] - counts[st])

Solution (Python):
I=lambda:map(int,input().split());n,q=I();s=input();a=[0]
for i in range(n):a+=a[i]+(s[i-1:i+1]=='AC'),
while q:l,r=I();print(a[r]-a[l]);q-=1

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

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

for i in range(q):
    st, en = qs[i]
    print(counts[en] - counts[st])

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

Solution (Python):
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
s = input()
rr = (list(map(int, input().split())) for _ in range(k))

from collections import Counter

dc = [0, 0]
c = 0
for i in range(1, len(s)):
  if s[i-1]+s[i] == 'AC':
    c += 1
  dc.append(c)
for a, b in rr:
  print(dc[b] - dc[a])

Solution (Python):



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

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

for s_id in range(len(S)):
    cnt[s_id + 1] = cnt[s_id]
    if S[s_id] == 'C' and S[s_id - 1] == 'A':
        cnt[s_id + 1] += 1

for _ in range(Q):
    l, r = map(int, raw_input().split())
    print '{}'.format(cnt[r] - cnt[l])

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, r])

pair = [0] * len(S)
for i in range(len(S)-1):
    if S[i] is 'A' and S[i+1] is 'C':
        pair[i+1] = pair[i] + 1
    else:
        pair[i+1] = pair[i]

for i in range(Q):
    ans = 0
    l = lr[i][0]-1
    r = lr[i][1]-1
    print(pair[r]-pair[l])

Solution (Python):
from __future__ import print_function
import sys
import numpy as np

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

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

cnt=np.zeros(100000,dtype='int')
now_x=0
for i in range(1,N):
    if S[i-1]=='A' and S[i]=='C':
        cnt[i]=now_x+1
        now_x=cnt[i]
    else:
        cnt[i]=now_x

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

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

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



for _ 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()
num = {}
n = 0

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

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

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

Solution (Python):
gene = ['A','C','G','T']

n,q = map(int,input().split())
s = input()
l_r = []
for _ in range(q):
    l_r.append(list(map(int,input().split())))
imos = [0]*n
csum = [0]*n

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

for i in range(1,n):
    csum[i] = csum[i-1] + imos[i]

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

s = input()
plc = [0] * n

for i in range(len(s)-1):
  if s[i] == 'A' and s[i + 1] == 'C':
    plc[i+1] = 1
  else:
    plc[i+1] = 0
    
for i in range(len(s)-1):
  plc[i+1] = plc[i] + plc[i+1]
    
for _ in range(q):
  l, r = list(map(int, input().split()))
  
  print(plc[r-1] - plc[l-1])

Solution (Python):


n,q=map(int,raw_input().split())
s=raw_input()
t=[0]*(n+1)
for i in xrange(n):
 if s[i:i+2]=='AC':
  t[i+1]=t[i]+1
 else:
  t[i+1]=t[i]
for i in xrange(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()

t = [0] * (N)
for i in range(N-1):
    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):
if __name__ == '__main__':
    length, question_count = map(int, input().split())

    string = input()
    ac_sums = [0]
    for i in range(1, len(string) + 1):
        if i > 1 and string[i - 2] == 'A' and string[i - 1] == 'C':
            ac_sums.append(ac_sums[i - 1] + 1)
        else:
            ac_sums.append(ac_sums[i - 1])

    for i in range(question_count):
        l, r = map(int, input().split())
        ans = ac_sums[r] - ac_sums[l - 1]
        if l > 1 and string[l - 1] == 'C' and string[l - 2] == 'A':
            ans -= 1
        print(ans)

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 = [list(map(int, input().split())) for i in range(q)]


for i in range(q):
    for j in range(2):
        lr[i][j] -= 1


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

for i in range(q):
    print(ac_cnt[lr[i][1]] - ac_cnt[lr[i][0]])

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