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):
import re

def solve1():
    N, Q = map(int, input().split())
    
    acgt_string = input()
    sub_str_ith = []
    for _ in range(Q):
        start, end = map(int, input().split())
        sub_str_ith.append((start, end))

    t = [0] * (N+1)
    for i in range(N):
        t[i+1] = t[i] + (1 if acgt_string[i:i+2] == "AC" else 0)

    for start, end in sub_str_ith:
        print(t[end-1] - t[start-1])

def my_solve1():
    N, Q = map(int, input().split())
    
    acgt_string = input()
    sub_str_ith = []
    for _ in range(Q):
        start, end = map(int, input().split())
        sub_str_ith.append((start, end))
    

    
    a_iths = [m.span() for m in re.finditer('AC', acgt_string)]
    

    for start, end in sub_str_ith:
        
        num = 0
        for ac_start, ac_end in a_iths:
            if ac_start >= start-1 and ac_end <= end:
                num += 1
        print(num)


solve1()

Solution (Python):
import numpy as np

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()
dp = [0 for _ in range(len(s))]

for i in range(1, len(s)):
    if(s[i-1: i+1] == 'AC'): dp[i] = dp[i-1] + 1
    else: dp[i] = dp[i-1]

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

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

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

Solution (Python):
def solve():
    N, Q = map(int, input().split())
    S = input()
    l = [0 for _ in range(Q)]
    r = l[:]
    for i in range(Q):
        l[i], r[i] = map(int, input().split())
    
    ac_head = [0 for _ in range(N+1)]
    for i, char in enumerate(S[:-1]):
        if char == 'A' and S[i+1] == 'C':
            ac_head[i+1] = 1 + ac_head[i]
        else:
            ac_head[i+1] = ac_head[i]
    
    for a, b in zip(l, r):
        print(ac_head[b-1] - ac_head[a-1])


if __name__ == '__main__':
    solve()

Solution (Python):

import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    table = [0] * (N + 1)

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

    for i in range(Q):
        print(table[r[i] - 1] - table[l[i] - 1])


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

aclist = [0,0]
acsum = 0

for i in range(1,n):
    if s[i-1] == "A" and s[i] == "C":
        acsum += 1
    aclist.append(acsum)

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

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

aclist = [0,0]
acsum = 0

for i in range(1,n):
    if s[i-1] == "A" and s[i] == "C":
        acsum += 1
    aclist.append(acsum)

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

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

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

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

Solution (Python):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

length, N=two_int()

S=one_str()

ac_list = [0]

hoge = 0
for i in range(length-1):
    if S[i:i+2]=="AC":
        hoge += 1
    ac_list.append(hoge)

for i in range(N):
    l, r = two_int()
    print(ac_list[r-1] - ac_list[l-1])

Solution (Python):
n,q = list(map(int, input().split()))
s = input()
question = [list(map(int, input().split())) for _ in range(q)]
ac = []
amount = 0
for i in range(len(s)):
  if(i == 0):
    ac.append(0)
    continue
  if(s[i-1] == "A" and s[i] == "C"):
    amount +=1
  ac.append(amount)
for r, l in question:
  print(ac[l-1] - ac[r-1])

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

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

Solution (Python):

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

A = []

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

A.insert(0, 0)

for i in range(Q):
  x, y = map(int, input().split())
  print(A[y] - A[x])

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

    AC_cnt = 0
    ll = [0]
    for i in range(1, len(S)):
        if S[i - 1:i + 1] == "AC":
            AC_cnt += 1
        ll.append(AC_cnt)

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


main()

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

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

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


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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N, Q = LI()
    s = S()
    L, R = [], []
    for _ in range(Q):
        l, r = LI_()
        L.append(l)
        R.append(r)
    num_ac = [0] * len(s)
    for i in range(len(s) - 1):
        if s[i] == 'A' and s[i+1] == 'C':
            num_ac[i+1] += 1
    for i in range(1, len(s)):
        num_ac[i] += num_ac[i-1]
    for i in range(Q):
        print(num_ac[R[i]] - num_ac[L[i]])

main()

Solution (Python):

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

for j in range(q):
    ans=m[l[j][1]-1]-m[l[j][0]-1]
    print(ans)

Solution (Python):
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]
t = [0]
count = 0
for i in range(1, n):
    if s[i-1] + s[i] == 'AC':
        count += 1
    t.append(count)
for le, ri in lr:
    print(t[ri-1] - t[le-1])

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

flg = False
acm = []
cnt = 0
for a in s:
    if a == 'A':
        flg = True
    elif a == 'C' and flg:
        cnt += 1

    if a != 'A':
        flg = False
    acm.append(cnt)

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

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

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

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

Solution (Python):
N, Q = list(map(int, input().split()))
S = list(str(input()))
questions = [tuple(map(int, input().split())) for _ in range(Q)]
ACs = [0] * N

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

for q in questions:
    print(ACs[q[1]-1] - ACs[q[0]-1])

Solution (Python):

import sys
from bisect import bisect_left

def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    A_index = []
    
    for i in range(N-1):
        if S[i] == 'A' and S[i+1] == 'C':
            A_index.append(i)
    
    for j in range(Q):
        if r[j] <= 1:
            print(0)
            continue

        left_index = bisect_left(A_index,l[j]-1)
        right_index = bisect_left(A_index,r[j]-1)
        print(right_index-left_index)
    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):
n,q=map(int,input().split())
s=input()
lis=[list(map(int,input().split())) for i in range(q)]
g=[0]*n
cnt=0
for i in range(n-1):
  if s[i]=='A' and s[i+1]=='C':
    cnt+=1
    g[i+1]=cnt
  else:
    g[i+1]=cnt

for i in range(q):
  print(g[lis[i][1]-1]-g[lis[i][0]-1])

Solution (Python):
import sys
import bisect
input=sys.stdin.readline
n,q=map(int,input().split())
s=input()
ac=[]
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    ac.append(i+1)
for i in range(q):
  a,b=map(int,input().split())
  print(bisect.bisect_right(ac,b-1)-bisect.bisect_left(ac,a))

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

Solution (Python):
import sys


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


if __name__ == '__main__':
    solve()

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

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

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

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

Solution (Python):
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n, q = ril()
s = rs()
ls = rils(q)
acc = [0] * n
for i in range(1, n):
    if s[i - 1:i + 1] == 'AC':
        acc[i] = acc[i - 1] + 1
    else:
        acc[i] = acc[i - 1]
for l, r in ls:
    print(acc[r - 1] - acc[l - 1])

Solution (Python):
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n, q = ril()
s = rs()
acc = [0] * n
for i in range(1, n):
    if s[i - 1:i + 1] == 'AC':
        acc[i] = acc[i - 1] + 1
    else:
        acc[i] = acc[i - 1]
for _ in range(q):
    l, r = ril()
    print(acc[r - 1] - acc[l - 1])

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

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

Acc = [0]*(N+1)
for i in range(N):
    Acc[i+1] = Acc[i]+Data[i]


for q in QList:
    l = q[0]
    r = q[1]
    ans = Acc[r]-Acc[l-1]
    if l >= 2:
        if S[l-1] == 'C' and S[l-2] == 'A':
            ans -= 1
    print(ans)

Solution (Python):

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

for i in l:
    print(m[i[1]-1]-m[i[0]-1])

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

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

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

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

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

Solution (Python):
import sys
if sys.platform =='ios':
	sys.stdin=open('input.txt')

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

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


from bisect import bisect_right as br
from bisect import bisect_left as bl
for i in range(q):
    a=bl(AC,lr[i][0]-1)
    
    b=br(AC,lr[i][1]-2)
    
    print(b-a)

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

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

Solution (Python):
import re
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=input()
a=[0]*(n+1)
tmp=0
for i in range(n-1):
  if s[i:i+2]=="AC":
    tmp+=1
  a[i+2]=tmp

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

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

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

from bisect import bisect_right as br
from bisect import bisect_left as bl
for i in range(q):
    a=bl(AC,lr[i][0]-1)
    b=br(AC,lr[i][1]-2)
    
    print(b-a)

Solution (Python):

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

LL=[0]*n
for i in range(1,n):
      if s[i-1:i+1]=="AC":
            LL[i]+=LL[i-1]+1
      else:
            LL[i]+=LL[i-1]
for i in range(q):
      print(LL[L[i][1]-1]-LL[L[i][0]-1])

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

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

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

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

Solution (Python):
from sys import stdin


def main():
    N, Q = map(int, input().split())
    S = input()
    LR = [int(x) - 1 for x in stdin.read().split()]
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in zip(*[iter(LR)] * 2):
        print(AC[r] - AC[l])
    return


main()

Solution (Python):
from sys import stdin


def main():
    N, Q = map(int, input().split())
    S = input().strip()
    LR = [int(x) - 1 for x in  stdin.read().split()]
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in zip(*[iter(LR)] * 2):
        print(AC[r] - AC[l])
    return


main()

Solution (Python):
from sys import stdin


def main():
    read = stdin.read
    N, Q = map(int, input().split())
    S = input().strip()
    LR = [int(x) - 1 for x in  read().split()]
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in zip(*[iter(LR)] * 2):
        print(AC[r] - AC[l])
    return


main()

Solution (Python):
from sys import stdin


def main():
    readline = stdin.readline
    read = stdin.read
    N, Q = map(int, readline().split())
    S = readline().strip()
    LR = [int(x) - 1 for x in  read().split()]
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in zip(*[iter(LR)] * 2):
        print(AC[r] - AC[l])
    return


main()

Solution (Python):
from sys import stdin


def main():
    readline = stdin.readline
    read = stdin.read
    N, Q = map(int, readline().split())
    S = readline().strip()
    * LR, = map(lambda x: int(x) - 1, read().split())
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in zip(*[iter(LR)] * 2):
        print(AC[r] - AC[l])
    return


main()

Solution (Python):
from sys import stdin


def main():
    readline = stdin.readline
    read = stdin.read
    N, Q = map(int, readline().split())
    S = readline().strip()
    *LR, = map(lambda x: int(x) - 1, read().split())
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in zip(*[iter(LR)] * 2):
        print(AC[r] - AC[l])
    return


main()

Solution (Python):
from sys import stdin


def main():
    readline = stdin.readline
    read = stdin.read
    N, Q = map(int, readline().split())
    S = readline().strip()
    *LR, = map(lambda x: int(x) - 1, read().split())
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in zip(*[iter(LR)] * 2):
        print(AC[r] - AC[l])
    return


main()

Solution (Python):
from sys import stdin


def main():
    readline = stdin.readline
    read = stdin.read
    N, Q = map(int, readline().split())
    S = readline().strip()
    * LR, = map(lambda x: int(x) - 1, read().split())
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in zip(*[iter(LR)] * 2):
        print(AC[r] - AC[l])
    return


main()

Solution (Python):
from sys import stdin


def main():
    readline = stdin.readline
    N, Q = map(int, readline().split())
    S = readline().strip()
    L = []
    R = []
    for i in range(Q):
        *LR, = map(int, readline().split())
        L.append(LR[0] - 1)
        R.append(LR[1] - 1)
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in zip(L, R):
        print(AC[r] - AC[l])
    return


main()

Solution (Python):

n,q = list(map(int,input().split()))
s = input()
s2 = s[1::]
d = [list(map(int,input().split())) for i in range(q)]


ac_idx = []

aci_append = ac_idx.append
for i,v in enumerate(zip(s,s2)):
    if v == ("A","C"):
        aci_append(i)


from bisect import bisect_left

for l,r in d:
    print(bisect_left(ac_idx,r-1) - bisect_left(ac_idx,l-1))

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

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

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

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

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

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

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

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

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

    ans = []
    for i in range(Q):
        l, r = map(int, input().split())
        ans.append(templist[r-1] - templist[l-1])
    for a in ans:
        print(a)
    
if __name__ == '__main__':
    main()

Solution (Python):
import sys, os
import collections

def solve(input_stream):
  n, q = [int(char) for char in input_stream.readline().strip().split()]
  target = input_stream.readline().strip()
  ans = []

  dp = [0 for i in range(len(target) + 1)]
  is_a = False
  for index, char in enumerate(target):
    dp[index + 1] = dp[index]
    if is_a:
      if char == "C":
        dp[index + 1] += 1
      is_a = False
    if char == "A":
      is_a = True
  for index in range(q):
    l, r = [int(char) for char in input_stream.readline().strip().split()]
    ans.append(str( dp[r] - dp[l] ))
  return ans  

if __name__ == "__main__":
    outputs = solve(sys.stdin)
    for line in outputs:
      print(line)

Solution (Python):
import sys
import time
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, Q = MAP()
S = input().rstrip()
LR = [MAP() for _ in range(Q)]

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


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

Solution (Python):
from itertools import accumulate


def solve(n, q, s):
    m = [0]*n
    for i in range(1, n):
        if s[i-1:i+1] == 'AC':
            m[i] = 1

    accm = list(accumulate(m))

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


if __name__ == '__main__':
    n, q = map(int, input().split())
    s = input()
    solve(n, q, s)

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())
AC = [None] * N
flag_A = False
cnt = 0
for i, s in enumerate(input()):
    AC[i] = cnt
    if flag_A:
        if s == 'C':
            cnt += 1
            AC[i] = cnt
        flag_A = False

    if s == 'A':
        flag_A = True

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

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

Solution (Python):
import sys
input=sys.stdin.readline
n,q=map(int,input().split())
s=input().replace("\n","")
cnt=[0 for i in range(n+1)]
for i in range(1,n+1):
    if s[i-1:i+1]=="AC":
        cnt[i]+=1
    cnt[i]+=cnt[i-1]

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

Solution (Python):
N, Q = map(int, input().split())
S = input()
lr_list = [list(map(int, input().split())) for i in range(Q)]
ac_sum = [0]
count = 0
for i, char in enumerate(S):
    if i != 0:
        if char == "C" and buf == "A":
            count += 1
    ac_sum.append(count)
    buf = char

for lr in lr_list:
    print(ac_sum[lr[1]] - ac_sum[lr[0]])

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 = (int(_) for _ in input().split())

s = input()


lr = [[int(i) for i in input().split()] for i in range(q)]



csum = [0 for i in range(n+1)]



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




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

Solution (Python):



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


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


for l, r in ql:
    print(cl[r] - cl[l])

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

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

for l, r in queries:
    print(countl[r] - countl[l])