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.



Sample input:
8 3
ACACTACG
3 7
2 3
1 8


Sample output:
2
0
3

Submission status: Time Limit Exceeded

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

count_ac_list = [s[:i+1].count('AC') for i in range(n)]
count_list = [str(count_ac_list[r-1] - count_ac_list[l-1]) for l, r in lr_list]

print('\n'.join(count_list))

Submission status: Time Limit Exceeded

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

count_ac_list = [s[:i+1].count('AC') for i in range(n)]

count_list = [str(count_ac_list[r-1] - count_ac_list[l-1])
    if l > 1 else str(count_ac_list[r-1])
    for l, r in lr_list]

print('\n'.join(count_list))

Submission status: Time Limit Exceeded

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

count_ac_list = []
for i in range(n):
    count_ac_list.append(s[:i+1].count('AC'))

# print(count_ac_list)
count_list = [str(count_ac_list[r-1] - count_ac_list[l-1])
    if l > 1 else str(count_ac_list[r-1])
    for l, r in lr_list]

print('\n'.join(count_list))

Submission status: Time Limit Exceeded

Solution code:
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = []

for _ in range(q):
    l, r = list(map(int, input().split()))
    lr_list.append((l, r))

count_ac_list = []
for i in range(n):
    count_ac_list.append(s[:i+1].count('AC'))

# print(count_ac_list)
count_list = [str(count_ac_list[r-1] - count_ac_list[l-1])
    if l > 1 else str(count_ac_list[r-1])
    for l, r in lr_list]

print('\n'.join(count_list))

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc122/tasks/abc122_c
# C - GeT AC

n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = []

for _ in range(q):
    l, r = list(map(int, input().split()))
    lr_list.append((l, r))

count_ac_list = []
for i in range(n):
    count_ac_list.append(s[:i+1].count('AC'))

# print(count_ac_list)
count_list = []

for l, r in lr_list:
    if l > 1:
        count = count_ac_list[r-1] - count_ac_list[l-1]
    else:
        count = count_ac_list[r-1]
    count_list.append(str(count))

print('\n'.join(count_list))

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc122/tasks/abc122_c
# C - GeT AC

n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = []

for _ in range(q):
    l, r = list(map(int, input().split()))
    lr_list.append((l, r))

count_ac_list = []
for i in range(n):
    count_ac_list.append(s[:i+1].count('AC'))

# print(count_ac_list)

for l, r in lr_list:
    if l > 1:
        count = count_ac_list[r-1] - count_ac_list[l-1]
    else:
        count = count_ac_list[r-1]
    print(count)

Submission status: Time Limit Exceeded

Solution code:
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = []

for _ in range(q):
    l, r = list(map(int, input().split()))
    lr_list.append((l, r))

# あらかじめACがある位置を検索した方が良いのかもしれない
work_s = s.replace('AC', '*_')
matched_index_list = [i for i, x in enumerate(work_s) if x == '*']

for l, r in lr_list:
    # count = len([x for x in matched_index_list if l-1 <= x < r-1])
    count = 0
    for x in matched_index_list:
        if l-1 <= x < r-1:
            count += 1
        elif x >= r-1:
            break
    print(count)

Submission status: Time Limit Exceeded

Solution code:
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = []

for _ in range(q):
    l, r = list(map(int, input().split()))
    lr_list.append((l, r))

# あらかじめACがある位置を検索した方が良いのかもしれない
work_s = s.replace('AC', '*_')
matched_index_list = [i for i, x in enumerate(work_s) if x == '*']

for l, r in lr_list:
    count = len([x for x in matched_index_list if l-1 <= x < r-1])
    print(count)

Submission status: Time Limit Exceeded

Solution code:
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = []

for _ in range(q):
    l, r = list(map(int, input().split()))
    lr_list.append((l, r))

for l, r in lr_list:
    sub_s = s[l-1:r]
    count = sub_s.count('AC')
    print(count)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
s = input()
anss = list()
for i in range(q):
    ans = 0
    ss = list()
    l,r = map(int, input().split())
    ss = s[l-1:r]
    for j in range(r-l):
        if ''.join(ss[j]+ss[j+1]) == 'AC':
            ans += 1
    anss.append(ans)
for i in range(q):
    print(anss[i])

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int, input().split())
S = input()
count = S.count("AC")
index = []
for i in range(count):
    if i == 0:
        index.append(S.find("AC"))
    else:
        index.append(S.find("AC", i + 1))

for i in range(Q):
    num = 0
    l, r = map(int, input().split())
    for j in index:
        if l-1 <= j <= r - 2:#indexnumberに揃えて, かつACの1番目のindex番号で判定
            num += 1
    print(num)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int, input().split())
S = input()
def judge_letter(letter, r, l):
    j_letter = letter[r-1 : l]
    return j_letter.count("AC")
num = []
for i in range(Q):
    l, r = map(int, input().split())
    num.append(judge_letter(S, l,r))
for j in num:
    print(j)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int, input().split())
S = input()
def judge_letter(letter, r, l):
    j_letter = letter[r-1 : l]
    return j_letter.count("AC")


for i in range(Q):
    l, r = map(int, input().split())
    print(judge_letter(S, l,r))

Submission status: Time Limit Exceeded

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

ans = []
for i,j in lr:
  ans.append(S[i-1:j].count('AC'))
  
for i in ans:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
A = [list(map(int, input().split())) for _ in range(q)]
for l,r in A:
    print(s[l-1:r].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
for i in range(q):
    l,r=map(int,input().split())
    print(s[l-1:r].count("AC"))

Submission status: Time Limit Exceeded

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

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

for i in range(q):
    if lr[i][1] - lr[i][0] < 2:
        print(0)
    else:
        print(sum(exist[lr[i][0]-1:lr[i][1]]))

Submission status: Time Limit Exceeded

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

for i in range(q):
    cnt = 0
    for j in range(lr[i][0], lr[i][1]):
        if s[j-1:j+1] == 'AC':
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
for i in range(Q):
  l, r = map(int, input().split())
  print (S[l-1:r].count("AC"))

Submission status: Time Limit Exceeded

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

lr = []
for i in range(q):
	l,r = map(int,input().split())
	chkword = s[l-1:r]
	print(chkword.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n,q=map(int,input().split())
s=input()
l = [stdin.readline().rstrip().split() for _ in range(q)]

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

for j,k in l:
    ans=0
    for x in range(int(j)-1,int(k)-1):
        ans+=t[x]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n,q=map(int,input().split())
s=list(input())
l = [stdin.readline().rstrip().split() for _ in range(q)]

for i,j in l:
    ans=0
    for k in range(int(i)-1,int(j)-1):
        if s[k]=="A" and s[k+1]=="C":
            ans+=1
    print(ans)

Submission status: Time Limit Exceeded

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

for i,j in l:
    ans=0
    for k in range(i-1,j-1):
        if s[k]=="A" and s[k+1]=="C":
            ans+=1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    n, q = map(int, input().split())
    s = input()
    lrs = list(list(map(int, input().split())) for _ in range(q))
    ans = [s[l - 1:r].count("AC") for l, r in lrs]
    print(*ans, sep="\n")


if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

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

for i in range(q):
    a = l[i][0]
    b = l[i][1]
    moji = s[a-1:b]
    ans = moji.count('AC')
    print(ans)

Submission status: Time Limit Exceeded

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

l = []

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

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

for i in range(q):
    count = 0
    for j in num_list:
        if l[i][0]-1 <= j < l[i][1]-1:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
L=[]
for i in range(N-1):
    if S[i]=="A" and S[i+1]=="C":
        L.append(i+1)
n=len(L)
for i in range(Q):
    l,r=map(int,input().split())
    a=0
    for j in range(n):
        if l<=L[j]<r:
            a+=1
    print(a)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split()) 
S = list(input()) 
count = 0 
ans = [] 
for i in range(Q): 
  r,l = map(int,input().split()) 
  for k in range(r-1,l-1): 
     if S[k] == 'A' and S[k+1] == 'C': 
        count += 1 
  ans.append(count) 
  count = 0 
for j in range(len(ans)): 
  print(ans[j])

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = list(input())
count = 0
ans = []
for i in range(Q):
  r,l = map(int,input().split())
  S_parted = S[r-1:l]
  for k in range(len(S_parted)-1):
    if S_parted[k] == 'A' and S_parted[k+1] == 'C':
      count += 1
  ans.append(count)
  count = 0
for j in range(len(ans)):
  print(ans[j])

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

# s = "AACACTTTTAC"
# print(s.count("AC"))#3

lr=[]
s2 = ""
n, q = map(int, input().split())
s = input()
for i in range(q):
        l,r = map(int, input().split())
        lr.append([l,r])

for i in range(q):
        s2 = s[lr[i][0] - 1:lr[i][1]]
        # print(s2)
        print(s2.count("AC"))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split(' '))
s = input()
for _ in range(q):
    l, r = map(int, input().split(' '))
    print(s[l-1:r].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
a=list(map(int,input().split()))
n,q,b,c=a[0]-1,a[1],[],[]
s=input()
for i in range(q):
    b.append(list(map(int,input().split())))
for i in range(n):
    if s[i]=='A' and s[i+1]=='C':
        c.append(1)
    else:
        c.append(0)
for i in range(q):
    print(sum(c[b[i][0]-1:b[i][1]-1]))

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
a=list(map(int,input().split()))
n,q,b,c=a[0]-1,a[1],[],[]
s=input()
for i in range(q):
    b.append(list(map(int,input().split())))
for i in range(n):
    if s[i]=='A' and s[i+1]=='C':
        c.append(1)
    else:
        c.append(0)
for i in range(q):
    print(sum(c[b[i][0]-1:b[i][1]-1]))

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline

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

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

Submission status: Time Limit Exceeded

Solution code:

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

Submission status: Time Limit Exceeded

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

for i in l:
    l = int(i[0])
    r = int(i[1])
    print(s[l-1:r].count('AC'))

Submission status: Time Limit Exceeded

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

for i in l:
    l = i[0]
    r = i[1]
    print(s[l-1:r].count('AC'))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
l = []
r = []

for i in range(q):
    temp1, temp2 = map(int, input().split())
    l.append(temp1)
    r.append(temp2)

# print("s: " + s)
# print("l: " + str(l))
# print("r: " + str(r))

for i in range(q):
    part = s[l[i]-1:r[i]]
    print(part.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
leng, n = [int(i) for i in input().split()]

s = input()

for i in range(n):
  start, end = [int(i) for i in input().split()]
  part = s[start-1:end]
  unko = part.replace("AC","Q")
  ans = len(part)-len(unko)
  
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
ans = []
for i in range(q):
  l,r = map(int, input().split())
  flg = False
  cnt = 0
  for j in range(l-1,r):
    if flg and s[j] == 'C':
      cnt += 1
      flg = False
    elif s[j] == 'A':
      flg = True
    else:
      flg = False
  ans.append(cnt)
for i in range(len(ans)):
  print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
mylist = []
for i in range(n-1):
    if s[i] + s[i+1] == "AC":
        mylist.append(i)
for i in range(q):
    cnt = 0
    l,r = map(int,input().split())
    for j in range(len(mylist)):
        if l-1<=mylist[j]<r-1:
              cnt +=1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
for i in range(q):
  l,r = map(int,input().split())
  ss = s[l-1:r]
  print(ss.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())
l=[0]*q
r=[0]*q
for i in range(q):
        l[i],r[i]=map(int,input().split())

t=s.replace('A'+'C','*_')
a=[0]
for i in range(n):
        if t[i]=='*':
                a.append(i+1)
a.append(len(s))
for i in range(q):
        count=0
        for j in range(len(a)):
                if l[i]<=a[j]<=r[i]-1:
                        count+=1
                elif a[j]<l[i]:
                        continue
                else:
                        break
        print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())
l=[0]*q
r=[0]*q
for i in range(q):
        l[i],r[i]=map(int,input().split())

t=s.replace('A'+'C','*_')
a=[0]
for i in range(n):
        if t[i]=='*':
                a.append(i+1)
a.append(len(s))
for i in range(q):
        count=0
        for j in range(len(a)):
                if l[i]<=a[j]<=r[i]-1:
                        count+=1
        print(count)

Submission status: Time Limit Exceeded

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

t=s.replace('A'+'C','*_')
a=[0]
for i in range(n):
        if t[i]=='*':
                a.append(i+1)
a.append(len(s))
for i in range(q):
        count=0
        for j in range(len(a)):
                if l[i]<=a[j]<=r[i]-1:
                        count+=1
        print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())
t=s
l=[0]*q
r=[0]*q
for i in range(q):
        l[i],r[i]=map(int,input().split())
for j in range(q):
        s=t
        print(s[l[j]-1:r[j]].count('A'+'C'))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())
t=s
l=[0]*q
r=[0]*q
for i in range(q):
        l[i],r[i]=map(int,input().split())
for j in range(q):
        s=t
        c=s[l[j]-1:r[j]].replace('A'+'C','__')
        print(c.count('__'))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=str(input())
t=s
l=[0]*q
r=[0]*q
for i in range(q):
        l[i],r[i]=map(int,input().split())
for j in range(q):
        s=t
        c=s[l[j]-1:r[j]].replace('A'+'C','__')
        print(c.count('__'))

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int,input().split())
l=input()

for i in range(b):
    c,d=map(int,input().split())
    ll=l[c-1:d]
    
    print(ll.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s=input()
for i in range(q):
  l,r = map(int, input().split())
  t=s[l-1:r].count("AC")
  print(t)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,Q = (int(i) for i in input().split()) 
S = input()
ans = 0
ans_list = []

for i in range(Q):
	l, r = (int(i) for i in input().split())
	S_list = list(S[l-1 : r])
	for g in range(len(S_list)-1):
		if S_list[g] == "A" and S_list[g+1] == "C":
			ans += 1
	ans_list.append(ans)
	ans = 0

for i in range(len(ans_list)):
	print(ans_list[i])

Submission status: Time Limit Exceeded

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

for i in range(Q):
	l, r = (int(i) for i in input().split())
	ans.append(S[l-1 : r].count("AC"))

for i in range(len(ans)):
	print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
Is = []
p = 0
while True:
  i = S.find("AC", p)
  if i < 0:
    break
  Is.append(i)
  p = i+2
#print(Is)
for i in range(Q):
  l, r = map(int, input().split())
  l, r = l-1, r-1
  c = 0
  for i in Is:
    if i >= l and i+1 <= r:
      c += 1
  print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for _ in range(Q):
    l,r = map(int, input().split())
    word = "".join(S[l-1:r])
    print(word.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=list(input())
li=[0]*n

for i in range(n):
  if i==0:
    continue
  if s[i-1]=="A" and s[i]=="C":
    li[i]=1
    
for i in range(q):
  l,r=map(int,input().split())
  tmp=li[l:r]
  print(sum(tmp))

Submission status: Time Limit Exceeded

Solution code:
import re

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

print('\n'.join([str(s[q[0]-1:q[1]].count('AC')) for q in questions]))

Submission status: Time Limit Exceeded

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

def get(n):
    ans = 0
    for i in range(n):
        if S[i] =="A" and S[i+1] =="C":
            ans += 1
    return ans

for i in range(len(S)):
    l.append(get(i))
for i in range(Q):
    print(l[X[i][1]-1]-l[X[i][0]-1])

Submission status: Time Limit Exceeded

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

def get(n):
    ans = 0
    for i in range(n-1):
        if S[i] =="A" and S[i+1] =="C":
            ans += 1
    return ans
for i in range(Q):
    print(get(X[i][1])-get(X[i][0]))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
X = [list(map(int, input().split()))for _ in range(Q)]
l =[]
b = [X[i][0] for i in range(Q)]
a = [X[i][1] for i in range(Q)]
for i in range(Q):
    l.append(S[b[i]-1:a[i]].count("AC"))
[print(i)for i in l]

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
X = [list(map(int, input().split()))for _ in range(Q)]
l =[]
for i in range(Q):
    l.append(S[X[i][0]-1:X[i][1]].count("AC"))
[print(i)for i in l]

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
X = [list(map(int, input().split()))for _ in range(Q)]
for i in range(Q):
    print(S[X[i][0]-1:X[i][1]].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
X = [list(map(int, input().split()))for _ in range(Q)]
for i in range(len(X)):
    k = S[X[i][0]-1:X[i][1]]
    print(k.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N, Q = [int(v) for v in input().split()]
S = input()
for i in range(Q):
    l, r = [int(v) for v in input().split()]
    print(S[l - 1: r].count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

a = [0] * len(S)

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

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys


def get_num():
    return int(input())


def get_nums(n):
    res = [0 for _ in range(n)]
    for i in range(n):
        res[i] = int(input())
    return res


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

n, q = get_numbers()
s = input()

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

ans = list()
for i in range(q):
    l, r = get_numbers()
    ans.append(len([idx for idx in ac_idx if idx >= l and idx < r]))

for a in ans:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys


def get_num():
    return int(input())


def get_nums(n):
    res = [0 for _ in range(n)]
    for i in range(n):
        res[i] = int(input())
    return res


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

n, q = get_numbers()
s = input()


ans = list()
for i in range(q):
    l, r = get_numbers()
    ans.append(s[l - 1:r].count('AC'))

for a in ans:
    print(a)

Submission status: Time Limit Exceeded

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

for i in range(q):
  x=0
  x=s[r[i][0]-1:r[i][1]]
  print(x.count('AC'))

Submission status: Time Limit Exceeded

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

x=[]
for i in range(q):
  cnt=0
  x.append(s[r[i][0]-1:r[i][1]])

for i in range(len(x)):
  print(x[i].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
lst = []
ans = []
for i in range(n-1):
    if s[i:i+2] == 'AC':
        lst.append(i+1)

for i in range(q):
    cnt = 0
    l,r = map(int,input().split())
    for j in range(len(lst)):
        if l<=lst[j]<r:
            cnt += 1
    ans.append(cnt)

for i in range(q):
    print(ans[i])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
ans = []
for i in range(q):
    l,r = map(int,input().split())
    txt = s[l-1:r]
    
    cnt = 0
    for j in range(len(txt)-1):
        if txt[j]=='A' and txt[j+1]=='C':
            cnt += 1
    ans.append(cnt)

for i in range(q):
    print(ans[i])

Submission status: Time Limit Exceeded

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

collection = []

for i in range(1, n + 1):
    collection.append(string[0:i].count('AC'))

for i in range(q):
    start, end = [int(i) for i in input().split()]
    print(collection[end-1] - collection[start-1])

Submission status: Time Limit Exceeded

Solution code:
n, q = [int(i) for i in input().split()]
string = list(input())

for i in range(q):
    res = 0
    start, end = [int(i) for i in input().split()]
    start -= 1
    temp = string[start:end]
    for j in range(len(temp) - 1):
        if temp[j] == 'A' and temp[j+1] == 'C':
            res += 1
    print(res)

Submission status: Time Limit Exceeded

Solution code:
import re
n,q = map(int, input().split())
sss = [s for s in input()]
for i in range(q):
  l,r = map(int, input().split())
  s_temp = "".join(sss[l-1:r])
  print(len(re.findall(r"AC", s_temp)))

Submission status: Time Limit Exceeded

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

cnt = [0]*(n-1)

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

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

Submission status: Time Limit Exceeded

Solution code:
def a():
    flag = False    
    a = input()
    N, Q = a.split(" ")
    S = input()
    for i in range(int(Q)):
        count = 0
        b = input()
        l, r = b.split(" ")
        l = int(l)
        r = int(r)
        for s in S[l-1:r]:
            if flag == True:
                if s == "C":
                    count += 1
            if s == "A":
                flag = True
            else:
                flag = False
        print(count)

a()

Submission status: Time Limit Exceeded

Solution code:
import re

def a():
    a = input()
    N, Q = a.split(" ")
    S = input()
    for i in range(int(Q)):
        b = input()
        l, r = b.split(" ")
        l = int(l)
        r = int(r)
        acList = re.findall("AC", S[l-1:r])
        print(len(acList))
a()

Submission status: Time Limit Exceeded

Solution code:
import re
def q51(n, q, s, l, r):
    q = re.compile('AC')
    
    for i, j in zip(l, r):
        print(len(q.findall(s[i-1:j])))


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

l = []
r = []
for _ in range(Q):
    a, b = [int(i) for i in input().split()]
    l.append(a)
    r.append(b)

q51(N, Q, S, l, r)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    N,Q =[int(s) for s in input().split() if s]
    S = input()
    indices = [i for i in range(N-1) if S[i]+S[i+1] == 'AC']
    # print(l)
    for _ in range(Q):
        left, right =[int(s) for s in input().split() if s]
        print(sum(left-1 <= i <= right-2 for i in indices))
solve()

Submission status: Time Limit Exceeded

Solution code:
import re
def q51(n, q, s, l, r):
    
    for i, j in zip(l, r):
        print(len(re.findall('AC', s[i-1:j])))

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

l = []
r = []
for _ in range(Q):
    a, b = [int(i) for i in input().split()]
    l.append(a)
    r.append(b)

q51(N, Q, S, l, r)

Submission status: Time Limit Exceeded

Solution code:
import re

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

for l, r in lr:
  print(len(re.findall(r'AC', S[l-1:r])))

Submission status: Time Limit Exceeded

Solution code:
sn,qn=map(int,input().split())
s=input()
x=list(list(map(int,input().split())) for _ in range(qn))

import math

s2=[0]*(sn+1)

for i in range(sn-1):
	if s[i]=='A' and s[i+1]=='C':
		s2[i]=0.5
		s2[i+1]=0.5

al=sum(s2)

for i in range(qn):
	res=al-math.ceil(sum(s2[:x[i][0]-1]))-math.ceil(sum(s2[x[i][1]:]))
	print(int(res))

Submission status: Time Limit Exceeded

Solution code:
sn,qn=map(int,input().split())
s=input()
x=list(list(map(int,input().split())) for _ in range(qn))

for i in range(qn):
	s2=s[x[i][0]-1:x[i][1]]
	print(s2.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

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

mod = 1000000007

if __name__ == "__main__":
    N,Q= map(int, sys.stdin.readline().split())
    S = sys.stdin.readline().rstrip()
    l= [list(map(int,list(sys.stdin.readline().split()))) for i in range(Q)]
    # print(l[1][0])

    for i in range(Q):
        n0=l[i][0]
        n1=l[i][1]
        s_l=S[n0-1:n1]
        print(s_l.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
for i in range(q):
  a,b=map(int,input().split())
  if b==n:b=-1
  print(s[a-1:b].count("AC"))