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

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


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

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


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

Solution (Python):
first_input = input().split(' ')

s_length = int(first_input[0])
num_of_Q = int(first_input[1])

input_string = input()

seq = [0]*s_length
count = 0

for s in range(s_length):
    if s > 0 and input_string[s-1:s+1] == 'AC':
        count += 1
    seq[s] = count

for q in range(num_of_Q):
    l_r = input().split(' ')
    l = int(l_r[0])
    r = int(l_r[1])

    print(seq[r-1] - seq[l-1])

Solution (Python):

import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    ac = [0]*N
    for i in range(1,N):
        if(S[i-1:i+1] == 'AC'):
            ac[i] = ac[i-1]+1
        else:
            ac[i] = ac[i-1]

    ans = [0]*Q
    for i in range(Q):
        ans[i] = ac[r[i]-1] - ac[l[i]-1]

    for i in ans:
        print(i)
    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())
string = input()
 
counter = [0]*(N+1)

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

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

Solution (Python):
from itertools import accumulate

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

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

flg2 = list(accumulate([0]+flg))

for a in A:
    print (flg2[a[1]-1]-flg2[a[0]-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()
acl=[]
for i in range(n-1):
    if s[i:i+2]=='AC':acl.append(i)
import bisect
for i in range(q):
    l,r=map(int, input().split())
    
    
    print(bisect.bisect_right(acl,r-2)-bisect.bisect_left(acl,l-1))

Solution (Python):
from sys import stdin
N,Q=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
acc=[0]*N
cnt=0
flag=0
for index,i in enumerate(list(S)):
    if i == "C" and flag == 1:
        cnt+=1
        flag=0
    if i != "C":
        flag=0
    if i == "A":
        flag=1
    acc[index]=cnt
for j in range(Q):
    n1,n2=[int(x) for x in stdin.readline().rstrip().split()]
    print(acc[n2-1]-acc[n1-1])

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

t=[0]*n

s=s.replace("AC", "Ac")

for i in range(n):
  if s[i] == "c":
    if i !=0:
      t[i]=1+t[i-1]
    else:
      t[i]=1
  else:
    t[i]=t[i-1]


for _ 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())
S = input()
QS = []

l = [0, 0]
last = S[0]
for i in range(1, len(S)):
    if last == 'A' and S[i] == 'C':
        l.append(l[-1] + 1)
    else:
        l.append(l[-1])
    last = S[i]

for _ in range(Q):
    left, right = map(int, input().split())
    QS.append((left, right))


for left, right in QS:
    ans = l[right] - l[left]
    print(ans)

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 itertools
import collections
import bisect

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

    counter = [0] * N
    for i in range(N-1):
        if "{}{}".format(S[i], S[i+1]) == 'AC':
            counter[i] = 1 + (counter[i - 1] if i > 0 else 0)
        else:
            counter[i] = counter[i - 1] if i > 0 else 0
    

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

if __name__ == '__main__':
    main()

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

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

m = []
total = 0
b = False

for c in s:
    if c == 'A':
        b = True
    elif c == 'C' and b:
        total += 1
        b = False
    else:
        b = False
    m.append(total)

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

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

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

list = [0]*(N+1)

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

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

Solution (Python):
import sys

input = sys.stdin.readline

n, q = map(int, input().split(" "))
s = input()
cnt = 0
place_of_AC = [0] * n

for i in range(len(s) - 1):
  place_of_AC[i]=cnt
  if s[i:i+2] == "AC":
    cnt += 1



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

Solution (Python):
n, q = map(int, input().split())
s = input()
flag = False
count = 0
li = []

for i in range(n):
    if s[i] == "A":
        flag = True
    elif s[i] == "C" and flag is True:
        count += 1
        flag = False
    else:
        flag = False
    li.append(count)

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

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

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


if __name__ == "__main__":
    main()

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

Solution (Python):


N,Q=map(int, raw_input().split())
S=raw_input()
P=[0]*(N+1)
for i in range(N):
    if i==0:
        P[0]=0
        continue
    if S[i-1:i+1]=="AC":
        P[i]=P[i-1]+1
    else:
        P[i]=P[i-1]
for _ in range(Q):
    l,r=map(int, raw_input().split())
    print(P[r-1]-P[l-1])

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

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

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

N,Q = (int(i) for i in input().split())
S = input()
acl = [0 for i in range(N)]
cnt = 0
for j in range(1,N):
  if S[j-1] == 'A' and S[j] == 'C':
    cnt += 1
  acl[j] = cnt
      
for k in range(Q):
  x,y = map(int, input().split())
  print(acl[y-1]-acl[x-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 = (int(i) for i in input().split())
S = input()
acl = [0 for i in range(N)]
cnt = 0
for j in range(1,N):
  if S[j-1] == 'A' and S[j] == 'C':
    cnt += 1
  acl[j] = cnt
      
for k in range(Q):
  x,y = map(int, input().split())
  print(acl[y-1]-acl[x-1])

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

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

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

c = [0]
for j in range(1, N):
    if S[j - 1] == 'A' and S[j] == 'C':
        c.append(c[-1] + 1)
    else:
        c.append(c[-1])




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

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

acl = [0]*(N+1)

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

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

Solution (Python):
N,Q = map(int,input().split())
S = input()
l,r = [],[]
index = []
for i in range(Q):
    tmp1,tmp2 = map(int,input().split())
    l.append(tmp1)
    r.append(tmp2)
counter = 0
index.append(counter)
for i in range(1,len(S)):
    if(S[i-1] == 'A' and S[i] == 'C'):
        counter += 1
    index.append(counter)
def f(l,r):
    return index[r-1] - index[l-1]
for i in range(Q):
    print(f(l[i],r[i]))

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

c = [0 for _ in range(len(s))]
count = 0

for i in range(len(s)):
    if s[i:i+2] == ["A", "C"]:
        count += 1
        c[i:i+2] = [count-1, count]
    else:
        c[i:i+2] = [count, count]

for i in range(q):
    start = b[i][0]-1
    end = b[i][1]-1
    ans = c[end] - c[start]
    print(ans)

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

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

Solution (Python):
import bisect

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

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

for _ in range(q):
    l, r = map(int, input().split())
    L = bisect.bisect_left(ans, l)
    R = bisect.bisect_right(ans, r-1)
    print(R-L)

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

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

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

Solution (Python):
from itertools import accumulate

N,Q=map(int,input().split())
S=input()
res=[0 for i in range(N)]
for i in range(1,N):
    if S[i] == "C" and S[i-1] == "A":
        res[i]=1
res=list(accumulate(res))

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

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

for j in range(1,N):
  if S[j-1] == 'A' and S[j] == 'C':
    cnt += 1
  acl[j] = cnt
      
for k in range(Q):
  x,y = (int(i)-1 for i in input().split())
  print(acl[y]-acl[x])

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

for j in range(1,N):
  if S[j-1] == 'A' and S[j] == 'C':
    cnt += 1
  acl[j] = cnt
      
for k in range(Q):
  x,y = (int(i)-1 for i in input().split())
  print(acl[y]-acl[x])

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


a = [0]*n

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

for i in range(q):
    L,R = map(int,input().split())
    L,R = L-1,R-1
    if L == 0:
        print(a[R])
    else:
        if end[L]:
            print(a[R]-a[L-1]-1)
        else:
            print(a[R]-a[L-1])

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

flag = False
for i in range(N):
    if S[i] == "A":
        flag = True
        Sum[i+1] = Sum[i]
    else:
        if S[i] == "C":
            if flag:
                Sum[i+1] = Sum[i] + 1
            else:
                Sum[i+1] = Sum[i]
        else: Sum[i+1] = Sum[i]
        flag = False

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

Solution (Python):
import sys
input=sys.stdin.readline
n,q=map(int,input().split())
s=input();a=[0]*2
for i in range(2,n+1):
 a+=[a[i-1]+s[i-2:i].count("AC")]
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()

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

for i in range(n):
    a[i+1] += a[i]

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

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

Solution (Python):



get = lambda: int(raw_input().strip())
gets = lambda: [int(i) for i in raw_input().strip().split()]
getss = lambda n: [gets() for _ in xrange(n)]

import bisect


N, Q = gets()
S = raw_input()
query = getss(Q)


AC = []
for i in xrange(N):
    if S[i:i + 2] == "AC":
        AC.append(i)



for i, j in query:
    i, j = i - 1, j - 1
    x = bisect.bisect_left(AC, i)
    y = bisect.bisect(AC, j - 1)
    print y - x

Solution (Python):
n,q = map(int,input().split())
s = input()
l = [list(map(int,input().split())) for _ in range(q)]
sum = [0]*(n+1)
for i in range(len(s)-1):
    if s[i:i+2]=='AC':
        sum[i+2] = sum[i+1]+1
    else:
        sum[i+2] = sum[i+1]
for l_ in l:
    print(sum[l_[1]]-sum[l_[0]])

Solution (Python):
import bisect

N, Q = list(map(int, input().split()))
S = list(input())
S2 = []
for i in range(N - 1):
    if S[i] == "A" and S[i + 1] == "C":
        S2.append(i)
for i in range(Q):
    l, r = list(map(int, input().split()))
    L = bisect.bisect_left(S2, l - 1)
    R = bisect.bisect_right(S2, r - 2)
    print(R - L)

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

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


for i in range(Q):
  l,r = map(int, input().split())
  l,r = l-1, r-1
  if l > 0 and X[l] != X[l-1]:
    print(max(X[r] - X[l-1] - 1,0))
  elif l > 0:
    print(X[r] - X[l-1])
  else:
    print(X[r])

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

Solution (Python):



def start_process(length, q_num, char):
    data = [0 for i in range(length + 1)]
    char = list(char)

    for i in range(1, length):
        if char[i] == 'C' and char[i - 1] == 'A':
            data[i] = data[i - 1] + 1
        else:
            data[i] = data[i - 1]

    for i in range(q_num):
        start_ind, fin_ind = map(int, input().split())
        print(data[fin_ind - 1] - data[start_ind - 1])


def main():
    length, q_num = map(int, input().split())
    char = input()
    start_process(length, q_num, char)

if __name__ == '__main__':
    main()

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

n = len(s)
ary = [0 for i in range(len(s)+1)]

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

for i in range(q):
    ans = ary[int(lr[i][1])] - ary[int(lr[i][0])]
    print(ans)

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

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

L = [0]*N

for i in range(len(S)-1):
  if S[i:i+2] == "AC":
    L[i+1] = L[i] + 1
  else:
    L[i+1] = L[i]

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

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

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

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


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

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

t=[0 for i in s]

for i in range(len(t)-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):
  print(t[int(r[i])-1]-t[int(l[i])-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+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())
L = [0, 0]
l = 0
for i in range(1, n):
    a = S[i-1]
    c = S[i]
    if a == "A" and c == "C":
        l += 1
    L.append(l)

for _ in range(q):
    l, r = map(int, input().split())
    re = 0
    if L[l] != L[l-1]:
        re = 1
    print(L[r] - L[l-1] - re)

Solution (Python):
N,Q = (int(i) for i in input().split())
S = input()
acl = [0 for i in range(N+1)]

for j in range(N):
  acl[j+1] = acl[j] +(1 if S[j:j+2] == 'AC' else 0)
      
for k in range(Q):
  x,y = (int(i)-1 for i in input().split())
  print(acl[y]-acl[x])

Solution (Python):






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

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

cnt_list = [0]*n
judge = 0

for i in range(n):
    if s[i] == "A":
        judge = 1
        cnt_list[i] = cnt_list[i-1]
    elif judge == 1 and s[i] == "C":
        judge = 0
        cnt_list[i] = cnt_list[i-1] + 1
    else:
        judge = 0
        cnt_list[i] = cnt_list[i-1]

for i in range(q):
    print(cnt_list[quiz[i][1] - 1] - cnt_list[quiz[i][0]-1])

Solution (Python):
from itertools import accumulate
n, q = map(int, input().split())
s = input()
L = [0]*n
for i in range(1, n):
    if(s[i-1:i+1] == 'AC'):
        L[i] = 1
c = list(accumulate(L))
for i in range(q):
    l, r = map(int, input().split())
    print(c[r-1]-c[l-1])

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

alst,clst=[],[]
for i in range(N-1):
    if S[i]=="A" and S[i+1]=="C":
        alst.append(i)
        clst.append(i+1)


for j in range(Q):
    l,r = lr[j][0]-1, lr[j][1]-1
    ans = bisect.bisect_right(clst,r) - bisect.bisect_left(alst,l)
    print(ans)

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

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):
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())



N, Q = mi()

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

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

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

L=[]

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


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

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

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

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

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


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

ans=[]
for i in range(Q):
    first,last=map(int,input().split())
    ans.append(l[last-1]-l[first-1])

for i in ans:
    print(i)

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

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

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



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

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

for q in query:
	print(sumlist[q["r"]] - sumlist[q["l"]])

Solution (Python):
N,Q = map(int,input().split())
S = input()
cnt = [0] * (N + 1)
lrs = []
for i in range(Q):
        lrs.append(list(map(int,input().split())))

for i in range(N):
        cnt[i+1] = cnt[i] + (1 if S[i:i+2] == "AC" else 0)
for lr in lrs:
        print(cnt[lr[1] - 1] - cnt[lr[0] - 1])

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


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

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

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

part = [0]*n
al = [0]*n
for i in range(len(s)):
	if i == 0:
		continue
	if s[i-1:i+1]=='AC':
		al[i] = al[i-1]+1
		if i>1:
			part[i-1] = part[i-2] + 1
		else:
			part[i-1] = 1
	else:
		al[i] = al[i-1]
		if i>1:
			part[i-1] = part[i-2]
		else:
			part[i-1] = 0

for question in questions:
	l, r = question
	l -= 1
	r -= 1
	print(al[r]-part[l-1])

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
from itertools import accumulate
n,q=map(int,input().split())
S=input()
A=[0]*(n-1)
for i in range(len(S)-1):
    if S[i]=='A' and S[i+1]=='C':
        A[i]=1
B=[0]+list(accumulate(A))
for _ in range(q):
    l,r=map(int,input().split())
    print(B[r-1]-B[l-1])

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

dp = [0] * (n + 1)

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

for L, R in LR:
    print(dp[R] - dp[L])

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

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

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

for l, r in questions:
    print(ac_sum[r-1] - ac_sum[l-1])

Solution (Python):
from itertools import*
a,b=map(int,input().split())
s=input()
table=[0]*(a-1)
for i in range(a-1):
    if s[i:i+2]=="AC":
        table[i]=1
x=[0]+list(accumulate(table))
for i in range(b):
    c,d=map(int,input().split())
    print(x[d-1]-x[c-1])

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

dp = [0] * (N + 1)
for i in range(N):
    if S[i : i + 2] == 'AC':
        dp[i + 1] += 1
        
for i in range(1, N + 1):
    dp[i] += dp[i - 1]
    
for i in range(Q):
    l, r = map(int, input().split())
    print(dp[r - 1] - dp[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()
a=[0]*(n+10)
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 i in range(q):
    l,r=map(int,input().split())
    print(a[r-1]-a[l-1])

Solution (Python):
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
S = input()
lr = [[int(i) for i in input().split()] for i in range(Q)]
C = [0]*(N+1)
terget = "AC"
index = -1
for i in range(N):
    C[i+1] = C[i] + (S[i:i+2] == "AC")
for l,r in lr:
    print(C[r-1] - C[l-1])

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

ac = [0]
for c, d in zip(s[0:], s[1:]):
    if c == 'A' and d == 'C':
        ac.append(ac[-1] + 1)
    else:
        ac.append(ac[-1])

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

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

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

Solution (Python):
from itertools import accumulate
import sys
N, Q = map(int, input().split())
S = input()
rs = [0] * N

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

rm = [0] + list(accumulate(rs))

for i in range(Q):
    ans = 0
    l, r = map(int, sys.stdin.readline().split())
    if S[l] == "C":
        ans -= 1
    ans = rm[r] - rm[l]
    print(ans)

Solution (Python):
from itertools import accumulate
import sys
N, Q = map(int, input().split())
S = input()
rs = [0] * N

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

rm = [0] + list(accumulate(rs))

for i in range(Q):
    ans = 0
    l, r = map(int, sys.stdin.readline().split())
    if S[l] == "C":
        ans -= 1
    ans = rm[r] - rm[l]
    print(ans)

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

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