AtCoder Beginner Contest 122 - GeT AC

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-----
8 3
ACACTACG
3 7
2 3
1 8

-----Sample Output-----
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.

Difficulty: EASY

Starter code:

Solutions:
(N, Q) = list(map(int, input().split()))
S = input()
cnt = [0, 0]
for i in range(1, N):
	cnt.append(cnt[-1] + S[i - 1:i + 1].count('AC'))
for _ in range(Q):
	(l, r) = list(map(int, input().split()))
	print(cnt[r] - cnt[l])


(N, Q) = map(int, input().split())
S = input()
c = []
count = 0
for i in range(N - 1):
	if S[i] == 'A' and S[i + 1] == 'C':
		count += 1
	c.append(count)
for i in range(Q):
	(l, r) = map(int, input().split())
	if l == 1:
		print(c[r - 2] - 0)
	else:
		print(c[r - 2] - c[l - 2])


(n, q) = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]
cnt = 0
lst = []
for i in range(n):
	if s[i - 1:i + 1] == 'AC':
		cnt += 1
	lst.append(cnt)
for i in range(q):
	print(lst[lr[i][1] - 1] - lst[lr[i][0] - 1])


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


import numpy as np
(n, q) = map(int, input().split())
s = input()
qs = []
for i in range(q):
	qs.append(list(map(int, input().split())))
ls = [0]
count = 0
for i in range(1, n):
	if s[i - 1:i + 1] == 'AC':
		count += 1
	ls.append(count)
for ques in qs:
	print(ls[ques[1] - 1] - ls[ques[0] - 1])


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


import numpy as np
(N, Q) = list(map(int, input().split()))
S = input()
s_l = np.zeros(N + 1)
for (i, s) in enumerate(S):
	if i + 1 < N and s == 'A' and (S[i + 1] == 'C'):
		s_l[i + 1] = s_l[i] + 1
	else:
		s_l[i + 1] = s_l[i]
for _ in range(Q):
	(l, r) = list(map(int, input().split()))
	print(int(s_l[r - 1] - s_l[l - 1]))


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


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


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


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


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


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


(N, Q) = map(int, input().split())
S = input()
cnt = [0] * (N + 1)
for i in range(1, N):
	if S[i - 1] == 'A' and S[i] == 'C':
		cnt[i + 1] = cnt[i] + 1
	else:
		cnt[i + 1] = cnt[i]
for i in range(Q):
	(L, R) = map(int, input().split())
	print(cnt[R] - cnt[L])


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


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


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


(N, Q) = list(map(int, input().split()))
S = input()
total = [0] * N
for i in range(1, N):
	total[i] = total[i - 1]
	if S[i - 1] == 'A' and S[i] == 'C':
		total[i] += 1
for q in range(Q):
	(L, R) = list(map(int, input().split()))
	L -= 1
	R -= 1
	count = total[R] - total[L]
	print(count)


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


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


def main():
	(N, Q) = map(int, input().split())
	S = str(input())
	sum_array = [0] * 100000
	i = 0
	while i < len(S):
		if S[i] == 'A' and i + 1 < len(S) and (S[i + 1] == 'C'):
			sum_array[i] = 1
			i += 2
		else:
			i += 1
	sum = 0
	for i in range(N):
		sum += sum_array[i]
		sum_array[i] = sum
	ans_array = [0] * Q
	for q in range(Q):
		(l, r) = map(int, input().split())
		l_sum = sum_array[l - 1]
		if l == 1:
			l_sum = 0
		elif sum_array[l - 2] != l_sum:
			l_sum = sum_array[l - 2]
		r_sum = sum_array[r - 1]
		if sum_array[r - 2] != r_sum:
			r_sum = sum_array[r - 2]
		ans_array[q] = r_sum - l_sum
	for ans in ans_array:
		print(ans)

def __starting_point():
	main()
__starting_point()


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


(N, Q) = map(int, input().split())
S = ' ' + input()
l = []
r = []
for _ in range(Q):
	(_l, _r) = map(int, input().split())
	l.append(_l)
	r.append(_r)
dp = [0] * (N + 2)
cnt = 0
for i in range(1, N):
	if S[-i] == 'C' and S[-i - 1] == 'A':
		cnt += 1
	dp[N - i] = cnt
ans = 0
for q in range(Q):
	ans = dp[l[q]] - dp[r[q] + 1]
	if r[q] < N:
		if S[r[q]] == 'A' and S[r[q] + 1] == 'C':
			ans -= 1
	print(ans)


(n, q) = map(int, input().split())
s = list(input())
a = [0] * n
r = 0
for ii in range(n - 1):
	if s[ii] == 'A' and s[ii + 1] == 'C':
		r += 1
	a[ii] = r
for _ in range(q):
	(l, r) = map(int, input().split())
	print(a[r - 2] - a[l - 2])


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


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


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


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


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


(n, k) = map(int, input().split())
s = input()
L = [0] * len(s)
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'C':
		L[i + 1] = 1
L = [0] + L
for i in range(1, len(s) + 1):
	L[i] += L[i - 1]
for i in range(k):
	(a, b) = map(int, input().split())
	print(L[b] - L[a])


(n, q) = map(int, input().split())
s = input()
l = [list(map(int, input().split())) for i in range(q)]
L = [0]
ct = 0
for i in range(n - 1):
	if s[i:i + 2] == 'AC':
		ct += 1
	L.append(ct)
for j in range(q):
	print(L[l[j][1] - 1] - L[l[j][0] - 1])


f = lambda : map(int, input().split())
(n, q) = f()
s = input()
cnt = 0
ln = [0] * n
for i in range(1, n):
	if s[i - 1:i + 1] == 'AC':
		cnt += 1
	ln[i] = cnt
for _ in range(q):
	(l, r) = f()
	print(ln[r - 1] - ln[l - 1])


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


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


(n, q) = map(int, input().split())
s = input()
l = [0] * n
tmp = 0
for i in range(n - 2, -1, -1):
	if s[i:i + 2] == 'AC':
		tmp += 1
	l[i] += tmp
for i in range(q):
	(L, R) = map(int, input().split())
	print(l[L - 1] - l[R - 1])


(n, q) = map(int, input().split())
S = input()
flag = False
L = [0 for _ in range(n)]
cnt = 0
for (i, s) in enumerate(S):
	if flag:
		if s == 'C':
			cnt += 1
		flag = False
	if s == 'A':
		flag = True
	L[i] = cnt
for _ in range(q):
	(l, r) = map(lambda x: int(x) - 1, input().split())
	print(L[r] - L[l])


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


import sys
(N, Q) = map(int, input().split())
S = input()
ls = [0]
for i in range(N):
	if i == 0:
		ls.append(0)
	elif S[i - 1:i + 1] == 'AC':
		ls.append(ls[-1] + 1)
	else:
		ls.append(ls[-1])
for q in range(Q):
	(l, r) = map(int, input().split())
	print(ls[r] - ls[l])


(N, Q) = list(map(int, input().split()))
S = input()
c = [0 for _ in range(N + 1)]
for i in range(1, N):
	a = 0
	if S[i - 1:i + 1] == 'AC':
		a = 1
	c[i + 1] = c[i] + a
for _ in range(Q):
	(l, r) = list(map(int, input().split()))
	l -= 1
	result = c[r] - c[l]
	if l > 0 and S[l - 1:l + 1] == 'AC':
		result -= 1
	print(result)


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


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


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


def MAP():
	return map(int, input().split())
(n, q) = MAP()
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()
	print(t[r - 1] - t[l - 1])


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


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


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


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


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


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


(n, q) = map(int, input().split())
s = input()
a = [0]
p = ''
for c in s:
	a.append(a[-1] + (1 if p == 'A' and c == 'C' else 0))
	p = c
for _ in range(q):
	(l, r) = map(int, input().split())
	print(a[r] - a[l])


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


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


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


(n, q) = list(map(int, input().split()))
s = input()
con = [0]
c = False
for i in range(n):
	if s[i] == 'A':
		c = True
		con.append(con[-1])
		continue
	if c:
		if s[i] == 'C':
			con.append(con[-1] + 1)
			c = False
			continue
		else:
			con.append(con[-1])
			c = False
			continue
	con.append(con[-1])
for j in range(q):
	(l, r) = list(map(int, input().split()))
	print(max(0, con[r] - con[l]))


(n, q) = map(int, input().split())
s = input()
count = [0]
for i in range(n - 1):
	count.append(count[i] + (s[i:i + 2] == 'AC'))
for i in range(q):
	(a, b) = map(int, input().split())
	print(count[b - 1] - count[a - 1])


from bisect import bisect_left
from bisect import bisect_right
(n, q) = list(map(int, input().split()))
s = input()
lr = [tuple(map(int, input().split())) for _ in range(q)]
ac = []
for i in range(n - 1):
	if s[i] == 'A' and s[i + 1] == 'C':
		ac.append(i)
if ac == []:
	for i in range(q):
		print(0)
	return
for (l, r) in lr:
	l -= 1
	r -= 1
	li = bisect_left(ac, l)
	ri = bisect_right(ac, r)
	if li == ri:
		print(0)
	elif r > ac[ri - 1]:
		print(ri - li)
	else:
		print(ri - li - 1)


(n, m) = map(int, input().split())
s = input()
l = [0]
(x, y) = (0, 0)
for i in range(n - 1):
	if s[i] == 'A' and s[i + 1] == 'C':
		x += 1
	l.append(x)
l.append(x)
for i in range(m):
	(a, b) = map(int, input().split())
	print(l[b - 1] - l[a - 1])


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


import sys
input = sys.stdin.readline
(n, q) = map(int, input().split())
S = input()
S = S.replace('\n', '')
s_list = list(S)
l = [0 for i in range(q)]
r = [0 for i in range(q)]
for i in range(q):
	(l[i], r[i]) = map(int, input().split())
ac_sum_list = [0 for i in range(len(s_list))]
tmp = ''
ac_sum = 0
for (i, s) in enumerate(s_list):
	if tmp + s == 'AC':
		ac_sum += 1
	ac_sum_list[i] = ac_sum
	tmp = s
for i in range(q):
	l_index = l[i]
	r_index = r[i]
	l_ac = ac_sum_list[l_index - 1]
	r_ac = ac_sum_list[r_index - 1]
	print(r_ac - l_ac)


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


(N, Q) = map(int, input().split())
S = input()
L = [0]
T = 0
for i in range(N - 1):
	T += S.count('AC', i, i + 2)
	L.append(T)
for j in range(Q):
	(l, r) = map(int, input().split())
	print(L[r - 1] - L[l - 1])


(N, Q) = map(int, input().split())
S = input()
dl = []
dr = []
for i in range(Q):
	line = list(map(int, input().split()))
	dl.append(line[0])
	dr.append(line[1])
a = []
for i in range(N - 1):
	tmp_S = S[i:i + 2]
	if tmp_S == 'AC':
		a.append(1)
	else:
		a.append(0)
s = [0]
for i in range(len(a)):
	s.append(s[i] + a[i])
ans = []
for (l, r) in zip(dl, dr):
	ans.append(s[r - 1] - s[l - 1])
for i in range(Q):
	print(ans[i])


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


(n, k) = map(int, input().split())
s = input()
l = [0]
c = 0
for i in range(1, n):
	if s[i] == 'C':
		if s[i - 1] == 'A':
			c += 1
	l.append(c)
for q in range(k):
	(x, y) = map(int, input().split())
	print(l[y - 1] - l[x - 1])


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


(n, q) = map(int, input().split())
s = input()
lr = [0] * (n + 1)
for i in range(n):
	lr[i + 1] = lr[i] + (1 if s[i:i + 2] == 'AC' else 0)
for i in range(q):
	(st, fn) = map(int, input().split())
	print(lr[fn - 1] - lr[st - 1])


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


from itertools import accumulate
(n, q) = list(map(int, input().split()))
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]
ac_list = [0] * n
for i in range(n - 1):
	if s[i] == 'A' and s[i + 1] == 'C':
		ac_list[i] = 1
ac_sum = list(accumulate(ac_list))
for (l, r) in lr:
	l -= 1
	r -= 1
	if l == 0:
		print(ac_sum[r - 1])
		continue
	print(ac_sum[r - 1] - ac_sum[l - 1])


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


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


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


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


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


(n, q) = list(map(int, input().split()))
s = input()
d = [0] * 100100
e = [0] * 100100
for i in range(0, n - 1):
	if s[i] == 'A' and s[i + 1] == 'C':
		d[i + 1] = 1
for i in range(0, n + 1):
	d[i + 1] += d[i]
for i in range(0, q):
	(l, r) = list(map(int, input().split()))
	l -= 1
	lefNum = d[l]
	rigNum = d[r]
	if r < n and s[r - 1] == 'A' and (s[r] == 'C'):
		rigNum -= 1
	ans = rigNum - lefNum
	print(ans)


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


(N, Q) = map(int, input().split())
S = input()
L = [0] * N
p = S[0]
for i in range(1, N):
	L[i] += L[i - 1]
	if p + S[i] == 'AC':
		L[i] += 1
	p = S[i]
for _ in range(Q):
	(i, j) = map(int, input().split())
	print(L[j - 1] - L[i - 1])


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


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


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


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


(n, q) = map(int, input().split())
s = input()
num_list = [list(map(int, input().split())) for _ in range(q)]
cnt = 0
cnt_list = [0]
for i in range(n - 1):
	if s[i] == 'A' and s[i + 1] == 'C':
		cnt += 1
		cnt_list.append(cnt)
	else:
		cnt_list.append(cnt)
for i in range(q):
	print(cnt_list[num_list[i][1] - 1] - cnt_list[num_list[i][0] - 1])


import sys
(n, q) = input().split()
s = input()
a = [0] * 2
for i in range(2, int(n) + 1):
	a += [a[i - 1] + s[i - 2:i].count('AC')]
for e in sys.stdin:
	(l, r) = map(int, e.split())
	print(a[r] - a[l])


(N, Q) = map(int, input().split())
S = input()
cnt = [0] * N
for i in range(N - 1):
	T = S[i:i + 2]
	if T == 'AC':
		cnt[i + 1] = cnt[i] + 1
	else:
		cnt[i + 1] = cnt[i]
for i in range(Q):
	(x, y) = map(int, input().split())
	ans = cnt[y - 1] - cnt[x - 1]
	print(ans)


(n, q) = map(int, input().split())
s = input()
l_list = []
r_list = []
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])


import numpy as np
(N, Q) = map(int, input().split())
S = input()
X = np.zeros(N + 1, dtype='int64')
tmp = 1
while S.find('AC') >= 0 and tmp < N:
	i = S.find('AC')
	X[tmp + i] += 1
	S = S[i + 2:]
	tmp += i + 2
SUM = X.cumsum()
for _ in range(Q):
	(l, r) = map(int, input().split())
	print(SUM[r - 1] - SUM[l - 1])


(N, Q) = map(int, input().split())
S = input()
LR = [tuple(map(int, input().split())) for _ in range(Q)]
cum = [0] * (N + 1)
cnt = 0
for i in range(1, N):
	if S[i - 1] == 'A' and S[i] == 'C':
		cnt += 1
	cum[i] = cnt
ans = []
for (l, r) in LR:
	result = cum[r - 1] - cum[l - 1]
	ans.append(result)
print(*ans, sep='\n')


(N, Q) = (int(X) for X in input().split())
S = input()
T = [0] * (N + 1)
for I in range(0, N):
	T[I + 1] = T[I] + (S[I:I + 2] == 'AC')
for J in range(0, Q):
	(L, R) = (int(X) - 1 for X in input().split())
	print(T[R] - T[L])


(n, k) = map(int, input().split())
a = input()
ac = [0] * n
x = 0
for i in range(n - 1):
	if a[i] == 'A' and a[i + 1] == 'C':
		x += 1
	ac[i + 1] = x
ac[-1] = x
for i in range(k):
	(l, r) = map(int, input().split())
	print(ac[r - 1] - ac[l - 1])


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


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


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


(n, q) = map(int, input().split())
S = input()
(*LR,) = (map(int, input().split()) for _ in range(q))
A = [0] * n
for i in range(1, n):
	A[i] = A[i - 1] + (S[i - 1:i + 1] == 'AC')
for (l, r) in LR:
	print(A[r - 1] - A[l - 1])


(n, m) = map(int, input().split())
s = input()
ACsuu = [0 for i in range(n)]
for i in range(1, n):
	ACsuu[i] = ACsuu[i - 1] + (1 if s[i - 1:i + 1] == 'AC' else 0)
for i in range(m):
	(a, b) = map(int, input().split())
	print(ACsuu[b - 1] - ACsuu[a - 1])


(n, q) = map(int, input().split())
s = input()
a = [0, 0]
for l in range(1, n):
	if s[l - 1] == 'A' and s[l] == 'C':
		a.append(a[l] + 1)
	else:
		a.append(a[l])
for k in range(q):
	(x, y) = map(int, input().split())
	print(a[y] - a[x])


import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	(N, Q) = list(map(int, readline().split()))
	S = readline().strip()
	(*LR,) = list(map(int, read().split()))
	vec = [0] * (N + 1)
	for i in range(N - 1):
		vec[i + 1] = vec[i]
		if S[i] == 'A' and S[i + 1] == 'C':
			vec[i + 1] += 1
	ans = [0] * Q
	for (i, (l, r)) in enumerate(zip(*[iter(LR)] * 2)):
		l -= 1
		r -= 1
		ans[i] = vec[r] - vec[l]
	print('\n'.join(map(str, ans)))
	return

def __starting_point():
	main()
__starting_point()


(N, Q) = map(int, input().split())
S = input()
A = [0]
j = 0
for i in range(N - 1):
	if S[i:i + 2] == 'AC':
		j += 1
	A.append(j)
for i in range(Q):
	q = list(map(int, input().split()))
	print(A[q[1] - 1] - A[q[0] - 1])


(n, m) = map(int, input().split())
a = 'AC'
arr = [0] * (n + 1)
s = input()
for i in range(1, n + 1):
	arr[i] = arr[i - 1] + s[i - 1:i + 1].count(a)
for _ in range(m):
	(x, y) = map(int, input().split())
	print(arr[y - 1] - arr[x - 1])


(n, k) = map(int, input().split())
s = input()
s = 'x' + s
l = [0] * n
for i in range(n):
	if s[i:i + 2] == 'AC':
		l[i] = l[i - 1] + 1
	else:
		l[i] = l[i - 1]
for i in range(k):
	(a, b) = map(int, input().split())
	print(l[b - 1] - l[a - 1])


(a, b) = map(int, input().split())
a = input()
c = [0] * len(a)
for i in range(len(a) - 1):
	if a[i] + a[i + 1] == 'AC':
		c[i + 1] = c[i] + 1
	else:
		c[i + 1] = c[i]
for i in range(b):
	(d, e) = map(int, input().split())
	print(c[e - 1] - c[d - 1])


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

def input_array():
	return list(map(int, input().split()))
(n, q) = input2()
B = str(input())
LR = [input_array() for _ in range(q)]
T = [0] * (n + 1)
for i in range(n):
	if B[i:i + 2] == 'AC':
		T[i + 1] = T[i] + 1
	else:
		T[i + 1] = T[i]
for lr in LR:
	st = lr[0] - 1
	fi = lr[1] - 1
	print(T[fi] - T[st])


(N, K) = list(map(int, input().split()))
moji = str(input())
ans = [0]
for i in range(N - 1):
	if moji[i] == 'A' and moji[i + 1] == 'C':
		ans.append(ans[i] + 1)
	else:
		ans.append(ans[i])
for i in range(K):
	(st, sp) = list(map(int, input().split()))
	print(ans[sp - 1] - ans[st - 1])


import sys
(N, Q) = map(int, input().split())
S = input()
cnt = [0] * (N + 1)
wasA = False
for i in range(0, N):
	if wasA and S[i] == 'C':
		cnt[i + 1] = cnt[i] + 1
		wasA = False
	elif S[i] == 'A':
		cnt[i + 1] = cnt[i]
		wasA = True
	else:
		cnt[i + 1] = cnt[i]
		wasA = False
for i in range(0, Q):
	(l, r) = map(int, input().split())
	print(cnt[r] - cnt[l])


(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')]
ans = []
for _ in range(q):
	(l, r) = map(int, input().split())
	ans.append(a[r] - a[l])
print(*ans, sep='\n')


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


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


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


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


def solve(N, Q, S, LRi):
	cumulative_sum = [0, 0]
	for i in range(1, N):
		tmp = cumulative_sum[-1]
		if S[i - 1:i + 1] == 'AC':
			tmp += 1
		cumulative_sum.append(tmp)
	for (l, r) in LRi:
		print(cumulative_sum[r] - cumulative_sum[l])

def __starting_point():
	(N, Q) = list(map(int, input().split()))
	S = input()
	LRi = [[int(i) for i in input().split()] for _ in range(Q)]
	solve(N, Q, S, LRi)
__starting_point()


from bisect import bisect_left, bisect_right

def main():
	(N, Q) = list(map(int, input().split()))
	S = input()
	s = []
	for i in range(N - 1):
		if S[i] + S[i + 1] == 'AC':
			s.append(i)
	for q in range(Q):
		(l, r) = list(map(int, input().split()))
		ans = bisect_left(s, r - 1) - bisect_left(s, l - 1)
		print(ans)

def __starting_point():
	main()
__starting_point()


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


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


(N, Q) = map(int, input().rstrip().split())
S = input().rstrip()
a = [0] * N
for i in range(N):
	if i > 1:
		a[i] = a[i - 1]
	if i != 0 and S[i - 1] == 'A' and (S[i] == 'C'):
		a[i] += 1
for _ in range(Q):
	(l, r) = map(int, input().rstrip().split())
	print(a[r - 1] - a[l - 1])


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


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


(n, q) = map(int, input().split())
l = [0 for i in range(n)]
for (i, v) in enumerate(list(input().replace('AC', 'X!'))):
	l[i] = l[i - 1] + (v == '!')
for c in range(q):
	(h, m) = map(int, input().split())
	print(l[m - 1] - l[h - 1])


(n, q) = map(int, input().split())
s = input()
ans = []
a = [0] * (10 ** 5 + 1)
add = 0
check = False
for i in range(n):
	if check and s[i] == 'C':
		add += 1
	if s[i] == 'A':
		check = True
	else:
		check = False
	a[i] += add
for i in range(q):
	(b, c) = map(int, input().split())
	ans.append(a[c - 1] - a[b - 1])
for i in range(q):
	print(ans[i])


(n, q) = map(int, input().split())
S = input()
L = []
L = [list(map(int, input().split())) for _ in range(q)]
A = [0, 0]
for i in range(n - 1):
	A += (A[-1] + (S[i:i + 2] == 'AC'),)
for (l, r) in L:
	print(A[r] - A[l])


(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_i, r_i) = map(int, input().split())
	print(t[r_i - 1] - t[l_i - 1])


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


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


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


import bisect
(n, q) = map(int, input().split())
s = input()
a = []
for i in range(n - 1):
	if s[i:i + 2] == 'AC':
		a.append(i)
for _ in range(q):
	(l, r) = map(int, input().split())
	print(bisect.bisect(a, r - 1.5) - bisect.bisect(a, l - 1.5))


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


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


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


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


import sys
_ = input()
S = input().strip()
ps = [0] * (len(S) + 1)
for i in range(2, len(S) + 1):
	ps[i] = ps[i - 1] + int(S[i - 2:i] == 'AC')
for line in sys.stdin:
	(l, r) = map(int, line.strip().split(' '))
	print(ps[r] - ps[l])


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


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


(n, q) = map(int, input().split())
s = input()
b = [0] * n
c = 0
for i in range(1, n):
	if s[i - 1] == 'A' and s[i] == 'C':
		c += 1
	b[i] = c
for i in range(q):
	(x, y) = map(int, input().split())
	print(b[y - 1] - b[x - 1])


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


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


(a, b) = map(int, input().split())
s = input()
l = [0] * a
c = 0
for x in range(a - 1):
	if s[x:x + 2] == 'AC':
		c += 1
	l[x] = c
for x in range(b):
	(i, j) = map(int, input().split())
	print(l[j - 2] - l[i - 2])


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


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


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


(n, q) = map(int, input().split())
s = input()
a = [0, 0]
for i in range(2, n + 1):
	a.append(a[i - 1] + (s[i - 2:i] == 'AC'))
for _ in range(q):
	(li, ri) = map(int, input().split())
	print(a[ri] - a[li])


import bisect
(n, q) = map(int, input().split(' '))
s = input()
lr = [list(map(int, input().split(' '))) for i in range(q)]
a = []
for i in range(n - 1):
	if s[i] + s[i + 1] == 'AC':
		a.append(i + 1)
for (l, r) in lr:
	print(bisect.bisect(a, r - 1) - bisect.bisect(a, l - 0.1))


(N, Q) = [int(i) for i in input().split()]
S = input()
lst = [0]
for x in range(1, len(S)):
	if S[x - 1:x + 1] == 'AC':
		lst.append(lst[x - 1] + 1)
	else:
		lst.append(lst[x - 1])
for q in range(Q):
	(l, r) = [int(i) for i in input().split()]
	print(lst[r - 1] - lst[l - 1])


(n, q) = list(map(int, input().split()))
b = input()
k = [0] * n
ac = 0
for i in range(n - 1):
	ac += 1 if b[i:i + 2] == 'AC' else 0
	k[i] = ac
for i in range(q):
	(l, r) = list(map(int, input().split()))
	print(k[r - 2] - k[l - 2])


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


(n, q) = map(int, input().split())
S = input()
L = [0]
c = 0
for i in range(n - 1):
	if S[i:i + 2] == 'AC':
		c += 1
	L.append(c)
for j in range(q):
	(s, e) = map(int, input().split())
	print(L[e - 1] - L[s - 1])


(n, q) = map(int, input().split())
s = input()
ac = {1: 0}
k = 0
for i in range(1, n):
	if s[i - 1:i + 1] == 'AC':
		k += 1
	ac[i + 1] = k
ans = []
for i in range(q):
	(l, r) = map(int, input().split())
	ans.append(ac[r] - ac[l])
for e in ans:
	print(e)


(n, q) = map(int, input().split())
s = list(map(str, input()))
arr = [list(map(int, input().split())) for j in range(q)]
result = [0]
cnt = 0
for i in range(1, len(s)):
	if s[i - 1] + s[i] == 'AC':
		cnt += 1
		result.append(cnt)
	elif s[i - 1] + s[i] != 'AC':
		result.append(cnt)
for (a, b) in arr:
	print(result[b - 1] - result[a - 1])


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


from bisect import bisect_left
(n, q) = map(int, input().split())
s = list(input())
L = []
for i in range(n - 1):
	if s[i] == 'A' and s[i + 1] == 'C':
		L.append(i)
ans = []
for i in range(q):
	(l, r) = map(int, input().split())
	(l, r) = (l - 1, r - 1)
	st = bisect_left(L, l)
	fi = bisect_left(L, r)
	ans.append(fi - st)
for i in ans:
	print(i)


R = lambda : map(int, input().split())
(n, q) = R()
s = input()
a = [0] * n
c = 0
for i in range(1, n):
	if s[i - 1:i + 1] == 'AC':
		c += 1
	a[i] = c
for _ in range(q):
	(l, r) = R()
	print(a[r - 1] - a[l - 1])


(n, q) = map(int, input().split())
s = input()
a = [list(map(int, input().split())) for i in range(q)]
c = [0] * n
for i in range(1, n):
	c[i] = c[i - 1] + (s[i - 1] + s[i] == 'AC')
for x in a:
	print(c[x[1] - 1] - c[x[0] - 1])


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


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


(N, Q) = list(map(int, input().split()))
S = input()
li = [0]
A = False
ans = 0
import copy
for i in range(N):
	if A == True:
		if S[i] == 'C':
			ans += 1
		A = False
	if S[i] == 'A':
		A = True
	li.append(copy.copy(ans))
for j in range(Q):
	(a, b) = list(map(int, input().split()))
	print(li[b] - li[a])


(n, q) = list(map(int, input().split()))
s = input()
ls = [list(map(int, input().split())) for i in range(q)]
d = [0]
pre = 0
c = 0
for i in range(len(s) - 1):
	if s[i:i + 2] == 'AC':
		d.append(d[i] + 1)
	else:
		d.append(d[i])
for (start, end) in ls:
	print(d[end - 1] - d[start - 1])


import sys
input = sys.stdin.readline
f = lambda : map(int, input().split())
(n, q) = f()
s = input()
ln = [0]
for i in range(n):
	ln += [ln[i] + (s[i - 1:i + 1] == 'AC')]
for _ in range(q):
	(l, r) = f()
	print(ln[r] - ln[l])


(N, Q) = [int(x) for x in input().split(' ')]
s = input()
AinAC = [0]
CinAC = [0]
c = 0
for i in range(len(s) - 1):
	if s[i] == 'A' and s[i + 1] == 'C':
		CinAC.append(c)
		c += 1
		AinAC.append(c)
	else:
		AinAC.append(c)
		CinAC.append(c)
else:
	AinAC.append(c)
	CinAC.append(c)
ans = []
for i in range(Q):
	(l, r) = [int(x) for x in input().split(' ')]
	right = min([AinAC[r], CinAC[r]])
	left = max([AinAC[l - 1], CinAC[l - 1]])
	ans.append(str(right - left))
print('\n'.join(ans))


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


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


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

class bit:

	def __init__(self, N):
		self.__N = N
		self.__a = [0] * N

	def add_(self, x, v):
		x += 1
		while x < self.__N:
			self.__a[x] += v
			x += x & -x

	def show_(self):
		print(self.__a[1:])

	def sum_(self, x):
		ans = 0
		while x > 0:
			ans += self.__a[x]
			x -= x & -x
		return ans

	def sub_sum_(self, x, y):
		return self.sum_(y) - self.sum_(x)
prev = '0'
BIT = bit(N)
for (i, val) in enumerate(S):
	if prev == 'A' and val == 'C':
		BIT.add_(i - 1, 1)
	prev = val
for i in range(Q):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	print(BIT.sub_sum_(x, y))


(N, Q) = map(int, input().split())
S = list(input())
lsline = []
for i in range(Q):
	lsline.append(list(map(int, input().split())))
lsAC = [0, 0]
AC = 0
for i in range(N - 1):
	if S[i] == 'A' and S[i + 1] == 'C':
		AC += 1
	lsAC.append(AC)
for i in range(Q):
	print(lsAC[lsline[i][1]] - lsAC[lsline[i][0]])