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

AC_list = [0] * N

for i in range(Q):
    l, r = (int(_) for _ in input().split())
    partial_S = S[l-1: r]
    counter = 0
    
    for j in range(r-l):
        if(partial_S[j]=="A"):
            if(partial_S[j+1]=="C"):
                counter+=1
    print(counter)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
N,Q=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
for i in range(Q):
    n1,n2=[int(x) for x in stdin.readline().rstrip().split()]
    print(S[n1-1:n2].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())
  A=S[l-1:r]
  print(A.count("AC"))

Submission status: Time Limit Exceeded

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

for i in range(q):
    cnt = 0
    start = int(lr[i][0])-1
    end = int(lr[i][1])-1

    for j in range(start, end):
        if s[j] == 'A' and s[j+1] == 'C':
                cnt += 1

    print(cnt)

Submission status: Time Limit Exceeded

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

li = []

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

AC = [0 for i in range(N)]
A = []


for k in range(N-1):
    if (S[k] in "A") and (S[k+1] in "C"):
        AC[k] = 1


for i in range(Q):
    score = sum(AC[l[i]-1:r[i]-1])
    print(score)

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
Ss=[i for i in input()]
#S = input()
for i in range(Q):
    l,r = map(int,input().split())
    count = 0
    Sscopy = Ss[l-1:r]
    for j in range(len(Sscopy)-1):
        if Sscopy[j]=="A"and Sscopy[j+1]=="C":
            count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
def solve(lr,N,Q,S):
    answer = []
    for i in range(Q):
        answer.append(S[int(lr[i][0])-1:int(lr[i][1])].count('AC'))
    for i in range(Q):
        print(answer[i])

 
def main():
    N,Q= map(int,input().split())
    S = input()
    lr = [0]*Q
    for i in range(Q):
        lr[i]=input().rstrip().split()
    # S = 'ACACTACG'
    # N = 8
    # Q = 3
    # lr = [['3', '7'], ['2', '3'], ['1', '8']]
    solve(lr,N,Q,S)
 
 
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
AC = [False] * (N-1)
buffer = []
lr =[]
for i in range(Q):
  buffer = list(map(int,input().split()))
  lr.append(buffer)
for i in range(N-1):
  if S[i:i+2] == "AC":
    AC[i] =  True
for q in range(Q):
  sums = 0
  #print(S[lr[q][0]-1:lr[q][1]])
  for i in range(lr[q][1]-lr[q][0]):
    #print(S[(lr[q][0])+i-1])
    if AC[(lr[q][0])+i-1] == True:
      sums +=1
  print(sums)

Submission status: Time Limit Exceeded

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

for i in range(Q):
  l, r = map(int,input().split())
  Si = S[l-1:r]
  
  len_Si = len(Si)
  for i in range(len_Si-1):
    if Si[i] == 'A':
      if Si[i+1] == 'C':
        count += 1
  print(count)
  count = 0

Submission status: Time Limit Exceeded

Solution code:
import re

N, Q = [int(item) for item in re.split(r"\s", input())]
S = input()

l = []
r = []
for i in range(Q):
    l_i, r_i = [int(item) for item in re.split(r"\s", input())]
    l.append(l_i)
    r.append(r_i)

# ACの場所を探す
p_list = []
i = 0
while i < N - 1:
    if S[i:i + 2] == "AC":
        p_list.append(1)
        p_list.append(0)
        i += 2
    else:
        p_list.append(0)
        i += 1

out_list = []
for q in range(Q):
    # qに答える
    l_i = l[q] - 1
    r_i = r[q] - 1
    out_list.append(str(sum(p_list[l_i:r_i])))

print("\n".join(out_list))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

starts = [0 for k in range(q)]
ends = [0 for k in range(q)]
for i in range(q):
    starts[i], ends[i] = map(int, input().split())

answers = [0 for k in range(q)]
for i in range(q):
    tmpStr = s[starts[i]-1:ends[i]]
    print(tmpStr.count("AC"))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=str(input())
data=[]
for i in range(Q):
    data.append([int(j) for j in input().split()])
import re

for i in range(Q):
    print(len(re.findall('AC',S[data[i][0]-1:data[i][1]])))

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())
  deleted = S[l-1:r]
  print(len(deleted.split('AC'))-1)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
for lz in range(Q):
  l1,l2=map(int,input().split())
  print(S[l1-1:l2].count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = str(input())
for i in range(Q):
  l, r = map(int, input().split())
  count = 0
  a = False
  for s in S[l-1:r]:
    if s == 'A':
      a = True
    elif s == 'C' and a == True:
      count += 1
  print(count)

Submission status: Time Limit Exceeded

Solution code:

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

l = [0]*Q
r = [0]*Q
a = ['']*Q

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

for i in range(Q):
    partS = S[l[i]-1:r[i]]
    print(partS.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
s =input()
A = [[int(j) for j in input().split()] for i in range(q)]
ls = [0] * (n+1)
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        ls[i]= 1

for k in range(q):
    print(sum(ls[A[k][0]-1:A[k][1]-1]))

Submission status: Time Limit Exceeded

Solution code:
import re

a, i = [int(n) for n in input().split()]
s = input()
k = 0
result = []

while k < i:
    ft, et = [int(n) for n in input().split()]
    result.append(len(re.findall("AC", s[ft - 1:et])))
    k += 1

for kekka in result:
    print(kekka)

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:
from collections import Counter
N, Q = map(int, input().split())
S = list(input())
qs = [list(map(int, input().split())) for _ in range(Q)]
for q in qs:
    string = S[q[0]-1:q[1]]
    print((''.join(string)).count('AC'))

Submission status: Time Limit Exceeded

Solution code:
# 2019/03/24
# AtCoder Beginner Contest 122 - C

# Input
n, q = map(int,input().split())
s = input()
sab = list()
aclist = list()

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

for k in range(q):
    l, r = map(int,input().split())
    ans = 0
    for i in range(len(aclist)):
        if aclist[i] >= l:
            if aclist[i] < r:
                ans += 1
            else:
                break
        else:
            continue

    # Output
    print(ans)

Submission status: Time Limit Exceeded

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

for i in range(q):
        t1,t2 = map(int,input().split())
        r1 = "".join(s[t1-1:t2])
        print(r1.count("AC"))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[32]:


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

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

for i in range(Q):
    t=S[lr[i][0]-1:lr[i][1]]
   # t=[S for j in range(lr[i][0],lr[i][1])]
   # print(t)
    print(t.count('AC'))


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
import re
N,Q = input().split()
S = input()
for _ in range(int(Q)):
    l,r = input().split()
    print(len(re.findall(r'AC', S[int(l)-1:int(r)])))

Submission status: Time Limit Exceeded

Solution code:
#c
n, q = list(map(int, input().split()))
s = input()
for x in range(q):
    l, r = list(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()
for i in range(Q):
    start,end = map(int, input().split())
    print(S[start-1:end].count("AC"))

Submission status: Time Limit Exceeded

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

S=input()

cnt=[0 for _ in range(len(S))]

prev=""

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

for q in range(Q):
 	L,R=map(int,input().split())
 	ans = 0
 	# 本当は、L-1からだが、
 	# "AC"のCの部分をカウントしているので、
 	# 最初の文字がその"C"だったら集計してはいけない
 	for i in range(L,R):
 		ans += cnt[i]
 	print(ans)

Submission status: Time Limit Exceeded

Solution code:
#C問題
N,Q=map(int,input().split())
S=str(input())
Slist=list(S)
LR=[list(map(int,input().split())) for i in range(Q)]
for i in range(Q):
    karis=Slist[LR[i][0]-1:LR[i][1]]
    karistr="".join(karis)
    ans=karistr.count("AC")
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int, input().split())
S = list(input())
list = []
for i in range(Q):
    count = 0
    start,end = map(int, input().split())
    mozi = S[start-1:end]

    for j in range(len(mozi)-1):
        if mozi[j] == "A" and mozi[j+1] == "C":
            count += 1
    list.append(count)
for i in range(Q):
    print(list[i])

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())
  deleted = S[l-1:r]
  
  print(len(''.join(deleted).split('AC'))-1)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
acpoint = []
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        acpoint.append(i+1)
sum = [0]*q
for i in range(q):
    l,r = map(int,input().split())
    sum[i] = len([i for i in acpoint if i >= l and i < r])
for i in sum:
    print(i)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, q = list(map(int,input().split()))
s = input()
ka = []
for i in range(q) :
    ka.append(list(map(int,input().split())))
for i in ka :
    ss = s[i[0] - 1 :i[1]]
    print(ss.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())
    s=S[l-1:r]
    print(s.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, q = na()
s = input()
for i in range(q):
    l, r = na()
    ct = 0
    frg = s[l-1:r]
    for j in range(len(frg)-1):
        if frg[j:j+2] == "AC":
            ct += 1
    print(ct)

Submission status: Time Limit Exceeded

Solution code:
import re

N, Q = map(int, input().split())
S = input()
for x in range(Q):
    a, b = map(int, input().split())
    s = S[a-1:b]
    print(len(re.findall('AC', s)))

Submission status: Time Limit Exceeded

Solution code:
a = input().split(" ")
q = int(a[1])
s = input()
for i in range(q):
    l =input().split(" ")
    first = int(l[0])
    last = int(l[1])
    print(s[first-1:last].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
l = [0 for i in range(Q)]
r = [0 for j in range(Q)]
for i in range(Q):
    l[i], r[i] = map(int, input().split())

AC = [0 for i in range(N)]
A = []


for k in range(N-1):
    if (S[k] in "A") and (S[k+1] in "C"):
        AC[k] = 1


for i in range(Q):
    score = sum(AC[l[i]-1:r[i]-1])
    A.append(score)

print(*A,sep="\n")

Submission status: Time Limit Exceeded

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

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

for _ in range(Q):
  l, r = map(int, input().split())
  i = l - 1
  cnt = 0
  while i < r - 1:
    if S[i] == "A" and S[i + 1] == "C":
      cnt += 1
      i += 2
    elif S[i + 1] == "A":
      i += 1
    else:
      i += 2
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import re

a, i = [int(n) for n in input().split()]
s = input()
k = 0
f = []
e = []
result = []

while k < i:
    ft, et = [int(n) for n in input().split()]
    f.append(ft)
    e.append(et)
    result.append(len(re.findall("AC", s[ft - 1:et])))
    k += 1

for kekka in result:
    print(kekka)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from collections import deque

N, Q = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
lr_list = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]


for l, r in lr_list:
    stack = deque([])
    S2 = S[l-1:r]
    count = 0
    #print(S2)
    for s in S2:
        # スタックが空なら
        if not stack:
            stack.append(s)
        # スタックの一番上がAなら
        elif stack[-1] == "A" and s == "C":
            stack.pop()
            count += 1
        else:
            stack.append(s)
    print(count)

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'))
print('\n'.join(map(str, ans)))

Submission status: Time Limit Exceeded

Solution code:
import re

hajime = input().split(" ")
num = int(hajime[1])
word = input()

for i in range(num):
  wakeru = input().split(" ")
  a = int(wakeru[0])
  b = int(wakeru[1])
  tmp = word[a-1:b]
  print(tmp.count("AC"))

Submission status: Time Limit Exceeded

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

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

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

lrCut = []
for i in range(0,q):
    lrCut.append(s[int(lr[i][0]) - 1:int(lr[i][1])])

for i in range(0,q):
    sum = 0
    for index, j in enumerate(lrCut[i]):
        if index == len(lrCut[i]) - 1:
            break
        if lrCut[i][index] == "Q" and lrCut[i][index + 1] == "P":
            sum += 1
    print(sum)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, Q = map(int, input().split())
    S = input()
    s_list = [str(c) for c in S]
    q_list = [list(map(int, input().split())) for i in range(Q)]

    ac_list = list()
    # get AC start point
    for i, n in enumerate(s_list):
        if n == "A" and i != (len(s_list) - 1):
            if s_list[i + 1] == "C":
                ac_list.append(i + 1)

    # answer Q
    for qs in q_list:
        counter = 0
        for start in ac_list:
            if qs[0] <= start and start < qs[1]:
                counter += 1
        print(counter)


if __name__ == '__main__':
    main()

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())
  strin = S[l - 1:r]
  print(strin.count("AC"))

Submission status: Time Limit Exceeded

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

indexList = []
index = -1
while True:
	index = S.find("AC", index+1)

	if index == -1:
		break
	
	indexList.append(index)

# print(indexList)

for (l, r) in data:
	ls = filter(lambda i: i >= l-1, indexList)
	rs = filter(lambda i: i+1 < r, ls)
	# print(list(rs))
	print(len(list(rs)))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
S=input()
l=[]
r=[]
for i in range(q):
  li,ri=map(int,input().split())
  l.append(li)
  r.append(ri)
ans=[]
for i in range(q):
  s=S[l[i]-1:r[i]]
  cnt=s.count('AC')
  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()
count = 0
for i in range(q):
  l,r = map(int,input().split())
  t = s[l-1:r]
  count = t.count("AC")
  print(count)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, raw_input().split())
S = raw_input()
ac_counter = [0] * N
for i in range(N - 1):
  if S[i:i + 2] == 'AC':
    ac_counter[i] += 1
for _ in range(Q):
  l, r = map(int, raw_input().split())
  print sum(ac_counter[l - 1: r]) - ac_counter[r - 1]

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(q):
        t1,t2 = map(int,input().split())
        r = s[t1-1:t2]
        r1 = ''.join(r)
        print(r1.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,Q = map(int,input().split())
s = str(input())
S = []
for c in s:
    S.append(c)
l = np.zeros(Q)
r = np.zeros(Q)
for i in range(Q):
    l[i], r[i] = map(int, input().split())

for i in range(Q):
    lst = S[int(l[i]-1):int(r[i])]
    count = 0
    for i in range(len(lst)-1):
        if (lst[i] == "A")and(lst[i+1] == "C"):
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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

for i in range(Q):
  start, end  = map(int,input().split())
  s = S[start-1:end]
  out = s.count('AC')
  print(out)

Submission status: Time Limit Exceeded

Solution code:
from sys import exit

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

S = input()

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

ans = []

for i in range(Q):
    li, ri = map(int, input().split())

    count = 0
    for ac in AC:
        if ac < li - 1 or ri - 1 < ac + 1:
            count += 1
    ans.append(len(AC) - count)

for a in ans:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
QS = []

# ACがある場所の添字（エンド）
pos = []
last = "x"
for i, si in enumerate(S):
    if last == "A" and si == "C":
        pos.append(i)
    last = si
# print(pos)

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

for l, r in QS:
    start = l - 1
    end = r - 1
    # print(start, end)
    count = 0
    for p in pos:
        if start <= (p - 1) and end >= p:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import re
N, Q = input().split()
N = int(N)
Q = int(Q)
S=str(input())

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

  AA = False
  cnt = 0
  for j in s:
    if AA:
      if j=="C": cnt += 1
      AA = False
    else:
      if j=="A": AA = True
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

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

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

count_question()

Submission status: Time Limit Exceeded

Solution code:
import re
import numpy as np
_, q = input().split()
s = input()
qs = [list(map(int, input().split())) for _ in range(int(q))]

def get_num_AC(s):
    count = len(re.split(r'AC', s)) - 1
    return count

def get_substr(s, smaller, larger):
    s1 = s[smaller-1:larger]
    return s1

for smaller, larger in qs:
    substr = get_substr(s, smaller, larger)
    count = get_num_AC(substr)
    print(count)

Submission status: Time Limit Exceeded

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

for l,r in lr_list:
    count = 0
    tmp_list = []
    for i in range(len(s[l-1:r])):
        if i+1 == len(s[l-1:r]):
            break
        tmp_list.append(s[l-1:r][i]+s[l-1:r][i+1])
    for p in tmp_list:
        if 'AC' == p:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import re

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

Submission status: Time Limit Exceeded

Solution code:
N,Q = list(map(int,input().split()))
S = str(input())
l = []
r = []
for i in range(Q):
    tl,tr = list(map(int,input().split()))
    l.append(tl)
    r.append(tr)

for i in range(Q):
    temp = S[l[i]-1:r[i]]
    print(len(temp.split("AC"))-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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



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

Submission status: Time Limit Exceeded

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

for l, r in lrs:
    s = S[l-1:r]
    length = len(s)
    count = 0
    for i in range(length - 1):
        if s[i] == 'A' and s[i+1] == 'C':
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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

for i in range(Q):
    s = lr[i][0] - 1
    l = lr[i][1]
    tempS = S[s:l]
    result = re.findall(r'AC', tempS)
    print(len(result))

Submission status: Time Limit Exceeded

Solution code:
import re

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

ans = []
for li in l:
    ps = S[li[0]-1:li[1]]
    acs = re.findall('AC', ps)
    print(len(acs))

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
L = [list(map(int,input().split())) for i in range(Q)]
P=[]
for k, j in enumerate(S[:-1]):
        if j=="A" and S[k+1]=="C":
            P.append(k+1)
for i in L:
    flag=0
    res=0
    for j in P:
        if(j>=i[0] and j<i[1]):
            flag=1
            res+=1
        else:
            if(flag==1):
                break
    print(res)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
ac_list = [0]*len(s)
i = 0
while True:
    ac_index = s[i:].find("AC")
    if ac_index == -1:
        break
    else:
        ac_list[ac_index+i] = 1
        i = ac_index + i + 2

for _ in range(q):
    lr = tuple(map(int, input().split()))
    print(sum(ac_list[lr[0]-1:lr[1]-1]))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int, input().split())
S = input()
q_list = list()
for i in range(Q):
  l, r = map(int, input().split())
  q_list.append([l, r])

for i in range(Q):
  l = q_list[i][0]
  r = q_list[i][1]
  s = S[l-1:r]
  s_list= s.split('AC')
  print(len(s_list)-1)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
info=[]
    
def count_ac(l):
    return l.count("AC")

for i in range(q):
    info.append(list(map(int,input().split())))
    print(count_ac(s[info[i][0]-1:info[i][1]]))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
L = []
R = []
# ans = []
for _ in range(Q):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)
flag = []
for i in range(N-1):
	if S[i] == 'A' and S[i+1] == 'C':
		flag.append(1)
		i += 1
	else:
		flag.append(0)
# print(flag)


for i in range(Q):
	print(sum(flag[L[i]-1:R[i]-1]))

# for i in range(Q):
# 	print(ans[i])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
count_list=[]

for i in range(Q):
    l,r=map(int,input().split())
    l,r=l-1,r-1 #リストのインデックスとの整合
    print(S[l:r+1].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
N, Q = input().split()
S = input()
for i in range(int(Q)):
    l, r = (int(x) for x in input().split())
    sub_S = S[l-1:r]
    count = 0
    for j in range(len(sub_S)-1):
        if 'AC' == sub_S[j:j+2]:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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

pos = []
for i in range(Q):
    pos.append(list(map(int, input().split())))
    
def countAC(S, r, l):
    data = S[r-1:l]
    cnt = 0
    for i in range(len(data)-1):
        if data[i]=='A':
            if data[i+1] == 'C':
                cnt+=1
    return cnt
  
ret = []
for it in pos:
    cnt = countAC(S, it[0], it[1])
    ret.append(str(cnt))
print('\n'.join(ret))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
ls, rs = [], []
for _ in range(Q):
    l, r = map(int, input().split())
    ls.append(l-1)
    rs.append(r-1)

indices = []
flag = False
for i in range(len(S)):
    if S[i] == 'A':
        flag = True
    elif S[i] == 'C' and flag:
        indices.append(i - 1)
    else:
        flag = False

for l, r in zip(ls, rs):
    print(len(list(filter(lambda idx: idx in range(l, r), indices))))

Submission status: Time Limit Exceeded

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

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

s = input()

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
 
for lr_ in lr:
    l, r = lr_[0], lr_[1]
    
    print(S[l - 1: r].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N, Q = LI()
S = input()
"""
ACのインデックスをすべて記録しておき、始点、終点で区切って出す

"""
ACs = []
for sidx in range(0, len(S)-1):
    if S[sidx]+S[sidx+1] == 'AC':
        ACs.append(sidx)
#  print(ACs)
#  LR = []
#  for i in range(Q):
#      LR.append(LI())
#  N, Q = 10**5, 10**5
#  S = 'ACTCTTCGTG'*10**4
#  LR = []
#  for i in range(Q):
#      LR.append([3,9000])

#  for l, r in LR:
#      tmp = S[l-1:r]
#      print(tmp.count('AC'))

result = []
for _ in range(Q):
    l,r = LI()
    res = len([i for i in ACs if i >= l- 1 and i < r-1])
    result.append(res)
for i in result:
    print(i)

Submission status: Time Limit Exceeded

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

for i in range(q):
    cnt = 0
    start = int(lr[i][0])-1
    end = int(lr[i][1])-1

    for j in range(start, end):
        if s[j] == 'A':
            if s[j+1] == 'C':
                cnt += 1

    print(cnt)