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()
lr = [list(map(int, input().split())) for _ in range(Q)]
t = [0]*N
count = 0

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

Solution (Python):
def main():
    n, q  = list(map(int, input().split()))
    s = list(input())
    queries = [list(map(int, input().split())) for _ in range(q)]
    
    dp = [0 for _ in range(n)] 

    for i in range(n - 1):
    	dp[i + 1] = dp[i] + ((s[i] + s[i + 1]) == "AC")
    
    for query in queries:
    	print(dp[query[1] - 1] - dp[query[0] - 1])

if __name__ == '__main__':
    main()

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

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

Solution (Python):
n,q = map(int,input().split())
S = list(input())
a = [0]*n

for i in range(1,n):
    a[i] = a[i-1]
    if (S[i-1]=='A')and(S[i]=='C'):
        a[i] += 1 
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()
LR = [[int(i) for i in input().split()] for i in range(Q)]
pre = [0]*(N+1)
for i in range(N):
  pre[i+1] = pre[i] + (1 if S[i:i+2] == 'AC' else 0)
for a in LR:
  print(pre[a[1]-1] - pre[a[0]-1])

Solution (Python):

import copy
import numpy as np
import random































N,Q = map(int,input().split())
S = input()
t = [0 for i in range(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()
my_list = []
for i in range(Q):
    (l, r) = map(int, input().split())
    my_list.append((l, r))





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


for i in range(Q):
    (l, r ) = my_list[i]

    ret = my_str_list[r-1] - my_str_list[l-1]
    if (S[l-2] == 'A'):

        ret = 0 if ret < 0 else ret
    print(ret)

Solution (Python):
N, Q = map(int, input().split(" "))
S = input()
st, en = [], []
for i in range(Q) :
    _st, _en = map(int, input().split(" "))
    st.append(_st)
    en.append(_en)
    
prev_char = ''
cnt = 0
cum_list = []
for c in S :
    if prev_char == 'A' and c == 'C' :
        cnt += 1
    cum_list.append(cnt)
    prev_char = c
    
for s, e in zip(st, en) :
    print(cum_list[e - 1] - cum_list[s - 1])

Solution (Python):

import copy
import numpy as np
import random

n,q = map(int,input().split())
s = list(str(input()))
L = []
for i in range(q):
    l,r = map(int,input().split())
    L.append([l,r])


count_ac = []
count = 0
i = 0
while i < n-1:
    if s[i] == "A" and s[i+1] == "C":
        count_ac.append(count)
        count += 1
        count_ac.append(count)
        i += 2
    else:
        count_ac.append(count)
        i += 1

count_ac.append(count)



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

Solution (Python):
n,m=map(int,input().split())
l=list(input())
l1=[0]
p=0
for i in range(n-1):
  if l[i]=="A" and l[i+1]=="C":
    p+=1
    l1.append(p)
  else:
    l1.append(p)
for t in range(m):
  i,j=map(int,input().split())
  print(l1[j-1]-l1[i-1])

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

tmp = [0 for _ in range(N)]

for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        tmp[i+1] = tmp[i] + 1
    else:
        tmp[i+1] = tmp[i]
        
for l in L:
    print(tmp[l[1]-1] - tmp[l[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):
import numpy as np
N, Q = map(int, raw_input().split())
S = raw_input()
L = np.zeros(Q)
R = np.zeros(Q)
for i in range(Q):
    L[i], R[i] = map(int, raw_input().split())
num = np.zeros(N)
num_tmp = 0
for i in range(1,N):
    if S[i-1:i+1] == "AC":
        num_tmp += 1
    num[i] = num_tmp
for i in range(Q):
    print int(num[int(R[i]-1)] - num[int(L[i]-1)])

Solution (Python):
import numpy as np

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

dp = [0] * N
i = 0
flg = False
for str in S:
    if str == "C" and flg == True:
        dp[i] = dp[i - 1] + 1
        flg = False
    elif str == "A":
        flg = True
        dp[i] = dp[i-1]
    else:
        flg = False
        dp[i] = dp[i-1]
    i += 1

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

Solution (Python):
ache = None                                                         
                                                                     
def make_cache(string):                                              
    global cache                                                     
                                                                     
    n = len(string)                                                  
    cache = [-2] * n                                                 
                                                                     
    prev = None                                                      
    count = 0                                                        
                                                                     
    for i, c in enumerate(string):                                   
        if c == 'C' and prev == 'A':                                 
            count += 1                                               
                                                                     
        cache[i] = count                                             
        prev = c                                                     
                                                                     
                                                                     
if __name__ == "__main__":                                           
    N, Q = map(int, input().split())                                 
    string = input()                                                 
    make_cache(string)                                               
                                                                     
    for _ in range(Q):                                               
        l, r = map(int, input().split())                             
        print(cache[r-1] - cache[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):
  start,end=map(int,input().split())
  print(t[end-1]-t[start-1])

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

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

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

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

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

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

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

for l, r in lrs:
    print(cs[r-1] - cs[l-1])

Solution (Python):
import numpy as np

def count(s):
    prev = ""
    cnt = 0
    dp = np.zeros(len(s)+1, dtype=int)
    for i, c in enumerate(s):
        if (prev == "A") and (c == "C"):
            cnt += 1
        prev = c
        dp[i+1] = cnt
    return dp

def solve(n, q, s, l, r):
    dp = count(s)
    for i in range(q):
        print(dp[r[i]] - dp[l[i]])

n, q = map(int, input().split())
s = input()
l = np.zeros(q, dtype=int)
r = np.zeros(q, dtype=int)
for i in range(q):
    l[i], r[i] = map(int, input().split())
solve(n, q, s, l, r)

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

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

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

T = "AC"
t = [0] * (N+1)

for val in range(N):
	if S[val:val+2] == "AC":
		t[val + 1] = t[val] + 1
	else:
		t[val + 1] = t[val]

for val in range(Q):

	print(t[lr[val][1]-1] - t[lr[val][0]-1])

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

Solution (Python):
n,q = map(int,input().split())
s = input()
lr = [[int(i) for i in input().split()]for _ in range(q)]
dp = [0]*n
f,c = 0,0
for i,j in enumerate(s):
  if f==1 and j=='C':
    c+=1
    f =0
  elif j=='A':
    f = 1
  else:
    f = 0
  dp[i]=c
for i in lr:
  print(dp[i[1]-1]-dp[i[0]-1])

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

t = [0 for i in range(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(s) for s 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())
    ans = t[r-1] - t[l-1]
    print(ans)

Solution (Python):
import numpy as np

a,b = list(map(int,input().split()))
S = input()
sub= "AC"
l = np.zeros(len(S)+1)
for i in range(len(S)):
  l[i+1] = l[i] + (1 if S[i:i+2]=="AC" else 0)

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

Solution (Python):
round = lambda x:(x*2+1)//2
a,b = list(map(int,input().split()))
S = input()
sub= "AC"
l = [0]*(len(S)+1)
for i in range(len(S)):
  l[i+1] = l[i] + (1 if S[i:i+2]=="AC" else 0)

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

Solution (Python):
N, Q = map(int, input().split())
S = input()
L = [0]*Q 
R = [0]*Q
for q in range(Q):
    l, r = map(int, input().split())
    L[q] = l
    R[q] = r
ans = [0]*Q 
accumulative_count = [0]*(N) 
accumulative_count[0] = 0 
for i in range(1, N, 1): 
    accumulative_count[i] = accumulative_count[i-1]
    if (S[i-1:i] == 'A') & (S[i:i+1] == 'C'):
        accumulative_count[i] = accumulative_count[i-1] + 1
for q in range(Q):
    print(accumulative_count[R[q]-1] - accumulative_count[L[q]-1])

Solution (Python):
import numpy as np
from collections import Counter
import collections
import numpy as np 
from scipy import sqrt, power, exp, log10
from scipy.fftpack import fft, ifft, fftfreq
import tarfile
import re
import os
import glob
from datetime import datetime
import time
import numpy.linalg as LA

round = lambda x:(x*2+1)//2
a,b = list(map(int,input().split()))
S = input()
sub= "AC"
l = np.zeros(len(S)+1)
for i in range(len(S)):
  l[i+1] = l[i] + (1 if S[i:i+2]=="AC" else 0)

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

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

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

Solution (Python):

"""
C - GeT AC
https://atcoder.jp/contests/abc122/tasks/abc122_c
AC
"""
import sys


def main(args):
    N, Q = map(int, input().split())
    S = input()
    ans = [0] * (N + 1)
    for i, a, c in zip(range(2, N), S, S[1:]):
        ans[i] = ans[i-1] + (a == 'A' and c == 'C')
    ans[-1] = ans[-2] + (S[-2:] == 'AC')

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


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):

"""
C - GeT AC
https://atcoder.jp/contests/abc122/tasks/abc122_c
WA
"""
import sys


def main(args):
    N, Q = map(int, input().split())
    S = input()
    ans = [0] * (N + 1)
    for i, a, c in zip(range(2, N), S, S[1:]):
        ans[i] = ans[i-1] + (a == 'A' and c == 'C')
    ans[-1] = ans[-2] + (S[-2:] == 'AC')

    ans_d = {i:n for i, n in enumerate(ans)}
    for _ in range(Q):
        l, r = map(int, input().split())
        print(ans_d[r] - ans_d[l])


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
N, Q = map(int, input().split())
S = input()
L = [0]*Q 
R = [0]*Q
for q in range(Q):
    l, r = map(int, input().split())
    L[q] = l
    R[q] = r
ans = [0]*Q 
accumulative_count = [0]*(N) 
accumulative_count[0] = 0 
for i in range(1, N, 1): 
    accumulative_count[i] = accumulative_count[i-1]
    if (S[i-1:i] == 'A') & (S[i:i+1] == 'C'):
        accumulative_count[i] = accumulative_count[i-1] + 1
for q in range(Q):
    print(accumulative_count[R[q]-1] - accumulative_count[L[q]-1])

Solution (Python):
N,Q=map(int,input().split())
S=input()
t=[0,0]
for i in range(2,N+1):
    t.append(t[-1]+(S[i-2:i]=='AC'))
for _ in range(Q):
    l,r=map(int,input().split())
    print(t[r]-t[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()

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()
num = [list(map(int, input().split())) for i in range(q)]
arr = [0]
tmp = 0
for i in range(n):
    if s[i:i+2] == 'AC':
        tmp += 1
    arr.append(tmp)

for left, right in num:
    ans = arr[right - 1] - arr[left - 1]
    print(ans)

Solution (Python):
N, Q = list(map(int, input().split()))
S = input()
l = [0] * Q
r = [0] * Q
for x in range(Q):
    l[x], r[x] = list(map(int, input().split()))

countAC = [0] * len(S)
for x in range(len(S) - 1):
    countAC[x + 1] = countAC[x]
    if S[x] == "A" and S[x + 1] == "C":
        countAC[x + 1] += 1
for x in range(Q):
    print(countAC[r[x] - 1] - countAC[l[x] - 1])

Solution (Python):









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

cumsum = [0] * N




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

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

Solution (Python):









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

cumsum = []




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

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

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

Solution (Python):
import bisect

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

start = []


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


length = len(start)
for _ in range(Q):
	left, right = map(int, input().split())
	left -= 1
	right -= 1

	if length == 0:
		print(0)
	else:
		

		l1 = bisect.bisect_left(start, left)

		r1 = bisect.bisect_right(start, right-1) - 1

		print (r1-l1+1)

'''

	r = length
	l = 0
	c = int((r+l)//2)
	while(l<r):

		if start[c] >= left:
			r = c
			c = int((r+l)//2)
		else:
			l = c
			c = int((r+l)//2)

	X1 = c

	
	r = length
	l = 0
	c = int((r+l)//2)
	while(l<r):

		if end[c] > right:
			r = c
			c = int((r+l)//2)
		else:
			l = c
			c = int((r+l)//2)

	X2 = c

	print(X2-X1+1)
'''

Solution (Python):
n, q = map(int, input().split())
s = str(input())
ls = [list(map(int, input().split())) for i in range(q)]
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 = ls[i][0], ls[i][1]
    ans = t[r - 1] - t[l - 1]
    print(ans)

Solution (Python):
n, q = map(int, input().split())
s = str(input())
ls = [list(map(int, input().split())) for i in range(q)]
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 = ls[i][0], ls[i][1]
    ans = t[r - 1] - t[l - 1]
    print(ans)

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

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

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

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

fromtos = []
for i in range(Q):
  fromtos.append(list(map(int, input().split())))

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

for fromto in fromtos:
  print(counts[fromto[1]-1] - counts[fromto[0]-1])

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,q = li()
s = lc()

cnt = [0]*(n)

for i in range(1,n):
    if s[i-1] == "A" and s[i] == "C":
        cnt[i] = cnt[i-1] + 1
    else:
        cnt[i] = cnt[i-1]
        
for _ in range(q):
    l,r = li_()
    print(cnt[r]-cnt[l])

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

Solution (Python):


N, Q = [int(x) for x in input().split()]
S = input().strip()
m = [0] * N
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        m[i] = m[i-1] + 1
    else:
        m[i] = m[i-1]

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

Solution (Python):
word_number, questions_number = map(int, input().split())

words = input()
questions = []
for question in range(questions_number):
    a,b = map(int, input().split())
    questions.append([a-1, b-1])










hasAC = [0] * word_number
for i in range(word_number-1):
    if words[i: i+2] == "AC":
        hasAC[i+1] = hasAC[i] + 1
    else:
        hasAC[i+1] = hasAC[i]

for i in range(questions_number):
    print(hasAC[questions[i][1]] - hasAC[questions[i][0]])

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


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

for j in range(Q):
  num_r = total_list[r[j]-1]
  num_l = total_list[l[j]-1]
  num = num_r - num_l
  print(num)

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

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

Solution (Python):

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

S = str(input())  

starts_ends = []

for _ in range(Q):
    starts_ends.append(list(map(int, input().split())))








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

for i in range(Q):
    start, end = starts_ends[i]
    print(cumulative_sum[end] - cumulative_sum[start])

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


cnts = [0]*N

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



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

Solution (Python):
N, Q = map(int, raw_input().split())
S = raw_input()
count = 0
ac_list = list()
ac_list.append(0)
for idx in range(1, N):
    if S[idx-1] == 'A' and S[idx] == 'C': count += 1
    ac_list.append(count)
for i in xrange(Q):
    left, right = map(int, raw_input().split())
    print (ac_list[right-1] - ac_list[left-1])

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

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

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

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

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

Solution (Python):
import bisect

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

index = []
for i in range(len(s)-1):
    if s[i:i+2] == 'AC':
        index.append(i)

for i in range(q):
    l, r = [int(x) for x in input().split()]
    print(bisect.bisect_right(index, r-2) - bisect.bisect_left(index, l-1))

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, Q = map(int, input().split())
s = input()[:-1]
acc = [0]*(N+1)
prev = ""
for i, c in enumerate(s):
    if c == "C" and prev == "A":
        prev = c
        acc[i+1] = 1
    else:
        prev = c
for i in range(len(acc)-1):
    acc[i+1] += acc[i]
ans = []
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(acc[r]-acc[l])
for a in ans:
    print(a)

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

ruisekiwa_tabun_rikaidekita = [0,0]

for i in range(q):
    num_list.append(list(map(int,input().split())))

for i in range(n-1):
    if s[i:i+2] == "AC":
        ruisekiwa_tabun_rikaidekita.append(ruisekiwa_tabun_rikaidekita[-1] + 1)
    else:
        ruisekiwa_tabun_rikaidekita.append(ruisekiwa_tabun_rikaidekita[-1])
        
for left,right in num_list:
    print(ruisekiwa_tabun_rikaidekita[right] - ruisekiwa_tabun_rikaidekita[left])

Solution (Python):


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

t = [0] * (n + 1)

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

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

counter = 0
lis = [0]*len(s)
for i in range(len(s)-1):
    if s[i:i+2] == 'AC':
        counter+=1
    lis[i+1]=counter
for b,e in zip(l,r):
    print(lis[e-1]-lis[b-1])

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

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

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

Solution (Python):
n,q = [int(i) for i in input().split()]
s = input()
l = []
r = []
for i in range(q):
  l_tmp, r_tmp = [int(j) for j in input().split()]
  l.append(l_tmp-1)
  r.append(r_tmp-1)
  
r_cnt = [0]
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    r_cnt.append(r_cnt[i-1]+1)
  else:
    r_cnt.append(r_cnt[i-1])
    
for i in range(q):
  ans = r_cnt[r[i]] - r_cnt[l[i]]
  print(ans)

Solution (Python):
Q=input()
S=input()
N,Q_num = int(Q.split(" ")[0]),int(Q.split(" ")[1])
AC=[0]
count = 0
for i in range(N-1):
  if S[i]=="A" and S[i+1]=="C":
    count = 1+count
  AC.append(count)
for q in range(int(Q_num)):
  qu = input().split(" ")
  print(AC[int(qu[1])-1]-AC[int(qu[0])-1])

Solution (Python):
n,q = [int(i) for i in input().split()]
s = input()
l = []
r = []
for i in range(q):
  l_tmp, r_tmp = [int(j) for j in input().split()]
  l.append(l_tmp-1)
  r.append(r_tmp-1)
  
ac_cnt = s.count('AC')
r_cnt = [ac_cnt]
l_cnt = [0]
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    r_cnt.append(r_cnt[i-1]-1)
    l_cnt.append(l_cnt[i-1]+1)
  else:
    r_cnt.append(r_cnt[i-1])
    l_cnt.append(l_cnt[i-1])
    
for i in range(q):
  ans = r_cnt[l[i]] + l_cnt[r[i]] - ac_cnt
  print(ans)

Solution (Python):
n,q = map(int,input().split())
S = input()
ac_list = [0,0]
question_list = []
for i in range(len(S)-1):
    if S[i:i+2] == "AC":
        ac_sum = ac_list[i+1] + 1
        ac_list.append(ac_sum)
    else:
        ac_list.append(ac_list[-1])
for _ in range(q):
    l, r = map(int,input().split())
    question_list.append([l,r])
for l,r in question_list:
    print(ac_list[r]-ac_list[l])

Solution (Python):



def main():
    n, q = map(int, input().split())
    s = input()
    m = len(s)
    ac = [0 for _ in range(m)]

    for k in range(m - 1):
        if s[k] == 'A' and s[k + 1] == 'C':
            ac[k + 1] = ac[k] + 1
        else:
            ac[k + 1] = ac[k]

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


if __name__ == '__main__':
    main()

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


def solve(n: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    count = [0] * (n + 1)
    tmp = 0
    for idx in range(n - 1):
        if S[idx:idx + 2] == 'AC':
            tmp += 1
        count[idx + 1] = tmp
    
    for i in range(Q):
        ret = count[r[i] - 1] - count[max(0, l[i] - 2)]
        if l[i] > 1 and S[l[i] - 2:l[i]] == 'AC':
            ret -= 1
        print(ret)

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

Solution (Python):
N, Q = map(int, input().split())
in_str = input()
AC_count = []
r = [0]*(N+1)
for i in range(N):
    r[i+1] = r[i] + (1 if in_str[i:i+2] == "AC" else 0) 
    
    
for i in range(Q):
    in1, in2 = map(int, input().split())
    print(r[in2-1]-r[in1-1])

Solution (Python):
N, Q = map(int, input().split())
S = input()
t=[0]*(N+1)
ans = [0] * Q
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())
	ans[i] = t[r-1] - t[l-1]
for i in range(Q):
    print(ans[i])

Solution (Python):
N, Q = map(int, input().split())
S = input()
lr = [0] * Q
for i in range(Q):
  lr[i] = list(map(lambda x: int(x) - 1, input().split()))

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

Solution (Python):
N, Q = map(int, input().split())
S = input()
lr = [0] * Q
for i in range(Q):
  lr[i] = list(map(lambda x: int(x) - 1, input().split()))
 
b, t = 0, [0]*N
for i in range(1, N):
  if S[i-1] == 'A' and S[i] == 'C':
    t[i] = t[i-1] + 1
  else: t[i] = t[i-1]
 
for i in range(Q):
  print(t[lr[i][1]] - t[lr[i][0]])

Solution (Python):
import re

NQ = [int(i) for i in input().split()]
N = NQ[0]
Q = NQ[1]
S = input()
LR = [[int(i) for i in input().split()] for j in range(Q)]
check = [0] * N
for i in range(N - 1):
    check[i + 1] = check[i] + (1 if S[i:i + 2] == "AC" else 0)


for j in range(Q):
    print((check[LR[j][1] - 1]) - (check[LR[j][0] - 1]))

Solution (Python):

import re
import bisect
from datetime import datetime as dt

N, Q = map(int, raw_input().split())
S = raw_input()
S += ' '
l = []
r = []
for i in range(Q):
    a = map(int, raw_input().split())
    l.append(a[0])
    r.append(a[1])

count = 0
d = [0 for i in range(N+1)]
for i in range(N):
    if S[i]+S[i+1] == 'AC':
        count += 1
    d[i + 1] = count

for i in range(Q):
    print '{}'.format(d[r[i]-1] - d[l[i]-1])