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 = list(map(int, input().split()))
s =  input()
a = [0]*n

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

  
  
  
  
  


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

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

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

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

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

a = [0 for i in range(N)]
b = [0 for i in range(N)]

for i in range(N-1):
  if S[i] == "A" and S[i+1] == "C":
    a[i] = 1
    b[i+1] = 1
    
def cumsum(xs):
  result = [xs[0]]
  for x in xs[1:]:
    result.append(result[-1] + x)
  result.append(0)
  result.sort()
  return result

A = cumsum(a)
B = cumsum(b)

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

Solution (Python):
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))

def main(n,q,s,l):
    lst_ac = [0]*(len(s))
    for i in range(len(s)-1):
        if s[i]+s[i+1] == "AC":
            lst_ac[i+1] = lst_ac[i]+1
        else:
            lst_ac[i+1] = lst_ac[i]
    for item in l:
        print(lst_ac[item[1]-1] - lst_ac[item[0]-1])

def resolve():
    n,q = mi()
    s = input()
    l = mix(q)
    main(n,q,s,l)

if __name__ == "__main__":
    resolve()

Solution (Python):
import sys
from collections import deque

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N,Q = LI()
str = S()



sum = list(range(N+1))
for i in range(N):
    if i+1<N and str[i] == 'A' and str[i+1] == 'C':
        sum[i+1] = sum[i] + 1
    else:
         sum[i+1] = sum[i]



for q in range(Q):
    l,r = LI()
    l -= 1
    r -= 1
    print(sum[r]-sum[l])

Solution (Python):

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

s=list(input())



count=[0]*n

for i in range(1,n):
    st=s[i-1:i+1]
    if st==["A","C"]:
        count[i]=count[i-1]+1
    else:
        count[i]=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 = list(map(int, input().split()))
s = list(input())
ans = [0, ]
count = 0
for i in range(1, n):
    if s[i - 1] == 'A' and s[i] == 'C':
        count += 1
    ans.append(count)
for _ in range(q):
    l, r = list(map(int, input().split()))
    print(ans[r - 1] - ans[l - 1])

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

dp = [0]*n
for i in range(1,n):
    dp[i]+=dp[i-1]
    if s[i-1:i+1]=='AC':
        dp[i]+=1
for i in range(q):
    print(dp[R[i]-1]-dp[L[i]-1])

Solution (Python):
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

def main():
    import sys
    input=sys.stdin.readline
    n,q=L()
    s=S().rstrip()
    
    a=[0]*n
    tmp=0
    for i in range(n-1):
        if s[i:i+2]=='AC':
            tmp+=1
        a[i+1]=tmp
    for i in range(q):
        li,ri=L()
        print(a[ri-1]-a[li-1])

if __name__ == '__main__':
    main()

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):
import bisect
n,q = map(int,input().split())
s = input()
data = []
for i in range(n-1):
    if s[i:i+2] == "AC":
        data.append(i)
for i in range(q):
    l,r = map(int,input().split())
    l -= 1
    r -= 1
    j = bisect.bisect_left(data,l)
    k = bisect.bisect_left(data,r)
    print(k-j)

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

mat = [list(map(int, input().split())) for _ in range(q)]
for l, r in mat:
    ans = cumsum[r] - cumsum[l]
    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)]
cnt = [0]*N
is_a = False
for i in range(N-1):
  if S[i] + S[i+1] == 'AC':
    cnt[i+1] = 1
for i in range(1, N):
  cnt[i] += cnt[i-1]

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

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






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






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n = n//a
    count += 1
  if a**count == n:
    return count
  else:
    return count+1





N,Q = IL()
S = S()

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

for _ in range(Q):
  L,R = IL()
  P(l[R-1]-l[L-1])

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

a = [0] * N
c = [False] * N
for i in range(1, N):
    if S[i - 1:i + 1] == "AC":
        a[i] = a[i - 1] + 1
        c[i] = True
    else:
        a[i] = a[i - 1]

for i in range(Q):
    l, r = map(int, input().split())
    if l - 1 == 0:
        print(a[r - 1])
    elif c[l - 1] is True:
        print(a[r - 1] - a[l - 1])
    else:
        print(a[r - 1] - a[l - 1])

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

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

for l,r in LR:
    print(sum_ac[r-1] - sum_ac[l-1])

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

Solution (Python):
import bisect

def solve():
    N, Q = map(int, input().split())
    S = input()
    
    index = []
    for i in range(N-1):
        if S[i:i+2] == 'AC':
            index.append(i+1)
    for _ in range(Q):
        l, r = map(int, input().split())
        print(bisect.bisect_left(index, r) - bisect.bisect_left(index, l))
        
solve()

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

ns = [None] * n
ns[0] = 0
nn = 0
for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        nn += 1
    ns[i + 1] = nn
for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1

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

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

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

d= {}

for k in range(n):
    d[k]=0

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


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

    ans.append(d[r-1] -d[l-1])


for i in ans:
    print(i)

Solution (Python):
x,y= list(map(int, input().split()))
s=input()
anslis=[0]*x
ans=0
for k in range(1,x):
    if s[k-1:k+1]=="AC":
        ans+=1
    anslis[k]+=ans

for k in  range(y):
    i,j= list(map(int, input().split()))
    i-=1
    j-=1
    print(anslis[j]-anslis[i])

Solution (Python):
N, Q = map(int, input().split())
S = input()
acList = [0 for n in range(N+1)]
for i in range(N):
    if("AC" == S[i:i+2]):
        acList[i+1] += acList[i] + 1
    else:
        acList[i+1] += acList[i]
for q in range(Q):
    left, right = map(int, input().split())
    print (acList[right-1] - acList[left-1])

Solution (Python):
import itertools
n, q = map(int, input().split())
s = input()
cnt = [0] * n
for i in range(1, n):
    if s[i] == 'C' and s[i - 1] == 'A':
        cnt[i] = 1
cnt = list(itertools.accumulate(cnt))
for _ 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()
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):
import sys
input = sys.stdin.readline
n,q = map(int,input().split())
s = list(input())
check = [0]*n
const = 0
for i in range(n-1):
    check[i] = const
    if s[i] == 'A' and s[i+1] == 'C':
        check[i+1] = const + 1
        const += 1
        i += 1
check[-1] = const
for i in range(q):
    l,r = map(int,input().split())
    print(check[r-1]-check[l-1])

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

Solution (Python):
from bisect import bisect_left, bisect_right
N, Q = map(int, input().split())
S = input()
def int_(num_str):
    return int(num_str) - 1

ans = 0
ACleft = []
ACright = []
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ACleft.append(i)
        ACright.append(i+1)
for _ in range(Q):
    l, r = map(int_, input().split())
    ans = bisect_left(ACleft, r) - bisect_left(ACleft, l)
    print(ans)

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

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

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

Solution (Python):
n, q = (int(x) for x in 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 = (int(x) for x in 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):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right


from functools import reduce
from pprint import pprint

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n,q = MI()
S = S()
lr = LI(q)

ls = [0]*n
count = 0
for i in range(1,n):
    if S[i]!="C":
        ls[i] = count
    else:
        if S[i-1]=="A":
            count += 1
            ls[i] = count
        else:
            ls[i] = count


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

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

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

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

Solution (Python):
N, Q = map(int, input().split(' '))
S = input()
queries = tuple(tuple(map(int, input().split(' '))) for _ in range(Q))

cumsum = [0] * (N + 1)
for i in range(N):
    cumsum[i + 1] = cumsum[i]
    if S[i:i + 2] == 'AC':
        cumsum[i + 1] += 1

for left, right in queries:
    print(cumsum[right - 1] - cumsum[left - 1])

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

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

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

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

Solution (Python):
import itertools
import math
import fractions
import functools
import copy
n, q = map(int, input().split())
s = input()
l = []
r = []
for i in range(q):
    li, ri = map(int, input().split())
    li -= 1
    ri -= 1
    l.append(li)
    r.append(ri)

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


count = 0


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

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

def main():
    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])

main()

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

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

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

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

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

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

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

ansLis = [0]
tmp = 0
flgA = False
for i in range(N):
    if flgA and S[i]=="C":
        tmp += 1
    ansLis.append(tmp)
    flgA = (S[i] == "A")


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

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

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

Solution (Python):
n, q = map(int, input().split())
s = input()
lis=[]
for i in range(q):
    lis.append(list(map(int, input().split())))
idx=0
acs=[0]*n
for _ in s:
    if s[idx]=="A" and s[idx+1]=="C":
        acs[idx+1] = 1
        idx+=1
    idx+=1
    if idx>=(len(s)-1):
        break
cnt=0

for i,el in enumerate(acs):
    if el!=0:
        cnt+=el
        acs[i]=cnt
    else:
        acs[i]=cnt

for i in lis:
    print(acs[i[1]-1]-acs[i[0]-1])

Solution (Python):
import sys











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

def main():
    
    
    n,q = map(int, stdin.readline().rstrip().split())
    s = str(stdin.readline().rstrip())
    
    
    
    cum = [0]*(n)
    cum[0] = 0
    for i in range(1,n):
        if s[i-1:i+1] == "AC":
            cum[i] = cum[i-1] + 1
        else:
            cum[i] = cum[i-1]
    for i in range(q):
        l,r = map(int, stdin.readline().rstrip().split())
        print(cum[r-1] - cum[l-1])

main()

Solution (Python):


import sys

















from bisect import bisect_left, bisect_right 




def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, q = mi()
    s = input()
    query = [lmi() for _ in range(q)]
    AC_A_memo = []
    for i in range(n - 1):
        if s[i] == 'A' and s[i + 1] == 'C':
            AC_A_memo.append(i)

    for l, r in query:
        
        
        print(bisect_right(AC_A_memo, r-2) - bisect_left(AC_A_memo, l-1))


if __name__ == "__main__":
    main()

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

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

for v in lr:
    print(L[v[1]-1] - L[v[0]-1])

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

Solution (Python):

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

A = [0]

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

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

Solution (Python):

import collections
import itertools as it
import math

 

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





nac = []
c = 0
for i, s_ in enumerate(s):
    if s[i] == 'C':
        if s[i-1] == 'A':
            c += 1

    nac.append(c)



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

Solution (Python):
import bisect

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

AC_l_list = []
AC_r_list = []

for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        AC_l_list.append(i)
        AC_r_list.append(i + 1)
        
        
for l, r in lr_list:
    i = bisect.bisect_left(AC_l_list, l - 1)
    j = bisect.bisect_right(AC_r_list, r - 1)
    print(j - i)

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

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

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


if __name__ == '__main__':
    main()

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

Solution (Python):
N, Q = map(int, input().split())
S = input()
cnt = [0]*(N+1)
for i in range(N):
    cnt[i+1] = cnt[i] + (1 if S[i:i+2] == '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()
lr_list = [list(map(int,input().split())) for nesya in range(q)]
hoge = [0]*(n+1)
for i in range(n):
  hoge[i+1] = hoge[i] + (1 if s[i:i+2] == 'AC' else 0)
for lr in lr_list:
  l = lr[0]
  r = lr[1]
  print(hoge[r-1] - hoge[l-1])

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

from collections import deque
N,Q = (int(x) for x in input().split())
S = list(input())
d = deque(S)
cum = [0] * N
count = 0
t1 = d.popleft()
for i in range(1,N):
    t2 = d.popleft()
    if t1 == 'A' and t2 == 'C':
        count += 1
    cum[i] = count
    t1 = t2
for i in range(Q):
    l,r = (int(x) for x in input().split())
    print(cum[r-1]-cum[l-1])

Solution (Python):
from itertools import accumulate
N, Q = map(int, input().split())
S = input()
counts = [[0] * N for _ in range(2)]
for i, c in enumerate(zip(S[:-1], S[1:])):
    counts[i & 1][i] = int(c == ("A", "C"))
for i in range(2):
    counts[i] = list(accumulate(reversed(counts[i])))[::-1]
for _ in range(Q):
    l, r = map(lambda n: int(n) - 1, input().split())
    print(counts[0][l] - counts[0][r] + counts[1][l] - counts[1][r])

Solution (Python):
import itertools
n,q=map(int,input().split())
s=input()
lr=[list(map(int,input().split())) for i in range(q)]
ans=[0]*(n+1)

for i in range(len(s)-1):
  if s[i]+s[i+1]=="AC":
    ans[i+1]=1
ansr=list(itertools.accumulate(ans))

for i in range(q):
  if ans[lr[i][1]]==1:
    print(ansr[lr[i][1]]-ansr[lr[i][0]-1]-1)
  else:
    print(ansr[lr[i][1]]-ansr[lr[i][0]-1])

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

Solution (Python):








import sys,collections
N,Q = tuple(map(int,sys.stdin.readline().split())) 
S = sys.stdin.readline().rstrip()
se = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(Q)) 

INF = float("inf")
com = [0]*(N+1)

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

for s,e in se:
    print(com[e-1] - com[s-1])

Solution (Python):

import sys

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, Q = map(int, readline().split())
S = readline().decode("utf-8").rstrip()
qs = []
for i in range(Q):
    l, r = map(int, readline().split())
    qs.append((l - 1, r - 1))


def solve():
    acc = [0] * (N + 1)
    for i in range(1, N + 1):
        acc[i] = acc[i - 1]
        if S[i - 1 : i + 1] == "AC":
            acc[i] += 1
    for l, r in qs:
        print(acc[r] - acc[l])


if __name__ == "__main__":
    solve()

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
import re
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n, q = Is()
s = S()
LR = TIR(q)
acc = [0]*(n+1)
tmp = 0
for i in range(1, n):
    if s[i-1] == "A" and s[i] == "C":
        tmp += 1
    acc[i] = tmp
for l, r in LR:
    l -= 1
    r -= 1
    print(acc[r]-acc[l])

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