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, M = list(map(int, input().split()))
S = input()
n=0
m=0
for i in range(M):
    n,m=list(map(int, input().split()))
    print(S[n-1:m].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N,Q=[int(x) for x in input().split()]
S=input()
Check_list=['A','T','G','C']

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int, input().split())
S=list(input())
A = []
for i in range(Q):
  A.append(list(map(int, input().split())))
flag=0
B = []
for i in range(N):
  if S[i]=="A":
    flag=i
    continue
  if S[i]=="C" and flag==i-1:
    B.append(i)
    flag=False
for i in range(Q):
  print(sum(A[i][0]<=x<A[i][1] for x in B))

Submission status: Time Limit Exceeded

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

L = list(input())
m = [0] * len(L)
cnt = 0
for idx, l in enumerate(L):
    if l == "C":
        if idx != 0 and L[idx-1] == "A":
            cnt += 1
            m[idx] = cnt

for i in range(Q):
    s, e = map(int, input().split())
    cnt_s = max(m[:s])
    cnt_e = max(m[:e])
    print(cnt_e - cnt_s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
N, Q = map(int, input().split())
S = list(input())
qs = [list(map(int, input().split())) for _ in range(Q)]
pattern = 'AC'
for q in qs:
    string = ''.join(S[q[0]-1:q[1]])
    m = re.findall(pattern, string)
    print(len(m))

Submission status: Time Limit Exceeded

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

# print(s)

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

Submission status: Time Limit Exceeded

Solution code:
N,Q = (int(x) for x in input().split())
S = list(input())
for i in range(Q):
    ans = 0
    flag = 0
    l,r = (int(x) for x in input().split())
    for j in range(l-1,r):
        if S[j] == 'A':
            flag = 1
        elif S[j] == 'C':
            if flag == 1:
                ans += 1
        else:
            flag = 0
    print(ans)

Submission status: Time Limit Exceeded

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

# In[3]:


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


# In[17]:


for j in range(Q):
    print(S[data[j][0]-1:data[j][1]].count("AC"))


# In[ ]:

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':
        if S[i + 1] == 'C':
            AC.append(i)

ans = []

for i in range(Q):
    li, ri = map(int, input().split())
    count = 0
    if li - ri > len(S) / 2:
        for ac in AC:
            if ac < li - 1:
                count += 1
            else:
                break
        for ac in reversed(AC):
            if ri - 1 < ac + 1:
                count += 1
            else:
                break
        ans.append(len(AC) - count)
    else:
        for i in range(li - 1, ri - 1):
            if i in AC:
                count += 1
        ans.append(count)

for a in ans:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int,input().split())
S = input()
LRlist = []
for i in range(Q):
    LRlist.append(list(map(int,input().split())))
indexlist = []
for i in range(len(S)-1):
    if S[i] == 'A':
        if S[i+1] == 'C':
            indexlist.append(i)
for LR in LRlist:
    L = LR[0]
    R = LR[1]
    answer = 0
    for i in indexlist:
        if L - 1 <= i and i <= R - 2:
            answer += 1
        elif R - 2 < i:
            break
    print(answer)

Submission status: Time Limit Exceeded

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

for i in range(Q):
    print(f(l[i],r[i]))

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

cntli = []
for i in range(q):
    si = s[lr[i][0]-1:lr[i][1]]
    si.strip("G")
    si.strip("C")
    cnt = 0
    for j in range(len(si)-1):
        if si[j] == "A":
            if si[j+1] == "C":
                cnt += 1
    else:
        cntli.append(cnt)

for p in cntli:
    print(p)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = list(input())
S.append(0)
List = []
tmp_input = []
count = 0
for i in range(Q):
    tmp_input = input().split()
    List.append(tmp_input)

for i in range(Q):
    count = 0
    tmp_x = int(List[i][0])
    tmp_y = int(List[i][1])
    tmp_List = S[tmp_x-1:tmp_y]
    tmp_List.append(0)
    for j in range(len(tmp_List)-1):
        if (tmp_List[j] == 'A') & (tmp_List[j+1] == 'C') ==True:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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

ans = []
for i in range(len(s) - 1):
  if s[i:i + 2] == 'AC':
      ans.append(i)
      
for _ in range(Q):
  l, r = map(int, input().split())
  print(sum([1 for i in ans 
             if l <= i + 1 < r]))

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

counter = [0 for _ in range(Q)]
index = -1
while True:
	index = S.find("AC", index+1)

	if index == -1:
		break
	
	for i, (l, r ) in enumerate(data):
		if l-1 <= index < r-1:
			counter[i] += 1


for res in counter:
	print(res)

Submission status: Time Limit Exceeded

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

for j in range(Q):
    count = 0
    start = qa[j][0]-1
    end = qa[j][1]
    string = S[start:end]
    Re = re.findall("AC", string)
    count += len(Re)
    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())
    s = S[l-1:r]
    ans = ans + str(s.count("AC")) + "\n"

print(ans[:-1])

Submission status: Time Limit Exceeded

Solution code:
NQ = list(map(int, input().split()))
word = input()
word_list = list(word)
for i in range(0, NQ[1]):
    rl = list(map(int, input().split()))
    word = word_list[rl[0]-1:rl[1]]
    word = ''.join(word)
    print(word.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())
    s = S[l-1:r]
    if 'A' in s or 'C' in s:
        print(''.join(s).count('AC'))
    else:
        print(0)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import re
pattern = 'AC'
n, q = map(int, raw_input().split())
s = raw_input()

x = [raw_input() for i in range(q)]

result = re.finditer(pattern, s)

ac = np.zeros(len(s))
count = 0
for match in result:
#    count += 1
    ac[match.span()[0]] = 1

#print ac



for d in x:
    r = d.split(' ')
    start = int(r[0])-1
    end = int(r[1])
    wa = np.sum(ac[start:end] == 1)
#    wa = ac[start:end].count(1)
#    wa = sum(ac[start:end])
    if ac[end-1]==1: wa = wa-1
    print int(wa)

Submission status: Time Limit Exceeded

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

for i in lr:
    print(S[i[0]-1:i[1]].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())
    cnt=0
    while l<r:
        if(s[l-1]=='A' and s[l]=='C'):
            cnt+=1
        l+=1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache

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

hit = [False] * N


@lru_cache(maxsize=None)
def ac_count(start, end):
    return sum(x for x in hit[start-1:end-1])


for i in range(0, N):
    if S[i:i+2] == 'AC':
        hit[i] = True

for _ in range(0, Q):
    l, r = map(int, input().split())
    print(ac_count(l, r))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
p = set()
for n,i in enumerate(S[:-1]):
    if i == "A" and S[n+1]=="C":
        p.add(n)
#print(p)
for i in range(Q):
    a,b = map(int,input().split())
    #tmp = {}
    # tmp = {i for i in range(a-1,b-1)}
    # print(tmp)
    # print(len(tmp&p))
    count=0
    for j in p:
        #print("j",j)
        if a <= j+1 and j+1 < b:
            count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
N,Q = map(int,input().split())
S = input()
input = sys.stdin.readline
lr = [[int(i) for i in input().split()] for i in range(Q)]
C = []
for i in range(N-1):
    if S[i] == "A":
        if S[i+1] == "C":
            C.append(i)
for i in lr:
    AC = 0
    for j in C:
        if j >= i[0]-1:
            if j < i[1]-1:
                AC += 1
            else:
                break
    print(AC)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, Q = map(int, input().split())  # 複数数値入力
S = list(input())  # 一文字ずつ格納
L = []
R = []

for i in range(Q):
    l, r = map(int, input().split())  # 複数数値入力
    L.append(l)
    R.append(r)

list = []
flg = 0
for s in S:
    if s == "A" and flg == 0:
        flg = 1
    elif s == "C" and flg == 1:
        list.append(1)
        list.append(2)
        flg = 0
    elif flg == 1:
        list.append(0)
        list.append(0)
    else:
        list.append(0)

for i in range(Q):
    S = list[L[i] - 1:]
    S = S[:R[i] - L[i] + 1]
    if S[0] == 2:
        S = S[1:]
    if S[-1] == 1:
        S = S[:-2]

    S = np.array(S)
    print(int(np.sum(S)/3))

Submission status: Time Limit Exceeded

Solution code:
ints = input().split()
inp = list(input())
a = []
co = 0
for i in range(int(ints[1])):
    a.append([int(e) for e in input().split()])
for d in a:
    s = inp[d[0]-1:d[1]]
    ind = [s for s,x in enumerate(s) if x == 'A']
    for f in ind:
        if len(s)-1 != f:
            if s[f+1] == 'C':
                co += 1
    print(co)
    co = 0

Submission status: Time Limit Exceeded

Solution code:
N, Q= input().split(" ")
S = input()
index_list_all = []
for i in range(int(Q)):
    lQ, rQ = input().split(" ")
    index_list_all.append([int(lQ), int(rQ)])

for index_list in index_list_all:
    print(len(S[index_list[0] - 1: index_list[1]].split("AC")) - 1)

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()
 
j = 0
while(j < n-1):
    if s[j] == "A":
        if s[j+1] == "C":
            aclist.append(j+1)
            j += 2
        else:
            j += 1
    else:
        j += 1

for k in range(q):
    l, r = map(int,input().split())
    ans = 0
    
    t_idx = len(aclist) - 1
    b_idx = 0
    search_idx = int(len(aclist) / 2)
 
    while(b_idx + 1 < t_idx and aclist[search_idx] != l):
        if aclist[search_idx] > l:
            t_idx = search_idx
            search_idx = int((t_idx + b_idx) / 2)
        elif aclist[search_idx] < l:
            b_idx = search_idx
            search_idx = int((t_idx + b_idx) / 2)
    for i in range(search_idx, len(aclist), 1):
        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 = input()

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

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

for question in questions:
    ac_count = 0

    for ac_position in ac_positions:
        if question[0] <= ac_position and ac_position + 1 <= question[1]:
            ac_count += 1

    print(ac_count)

Submission status: Time Limit Exceeded

Solution code:
N,Q = list(map(int,input().split()))
S = str(input())
num = []
c = []

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

for i in range(Q):
    cnt = 0
    tl,tr = list(map(int,input().split()))
    for j in range(len(num)):
        if num[j] >= tl and num[j]+1 <= tr:
            cnt+=1
    c.append(cnt)

for i in range(Q):
    print(c[i])

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
b = input()
a = [[int(x) for x in input().split()] for _ in range(q)]
ans=[0]
for j in range(len(b)-1):
        if b[j:j+2] == "AC":
            ans.append(1)
        else:
            ans.append(0)
for i in a:
    print(sum(ans[i[0]:i[1]]))

Submission status: Time Limit Exceeded

Solution code:
n,q = list(map(int,input().split()))
s = list(input())
num = list()
check = list()
for i in range(0,n-1):
    if s[i] == "A" and s[i+1] == "C":
        check.append(i+1)
for i in range(0,q):
    num.append(list(map(int,input().split())))
    count = 0
    for k in check:
        if num[i][1] <=k:
            break
        if num[i][0] <= k:
            count +=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,q = map(int,input().split())
s = str(input())
k = np.array([ 1 if s[i-1] == "A" and s[i] == "C" else 0  for i in range(n)])
#print(k)
for i in range(q):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    #print(k[a:b+1])
    ans = np.sum(k[a:b+1])
    if k[a] == 1:
        ans -= 1
    print(ans)

Submission status: Time Limit Exceeded

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


for i in range(q):
  h,f= map(int, input().split())
  print(len(s[h-1:f].split("AC"))-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans=[]

for i in range(q):
    l,r=map(int,lr[i].split())
    #print(int((len(s[l-1:r])-len(s[l-1:r].replace('AC',"")))/2))
    ans.append(str(int((len(s[l-1:r])-len(s[l-1:r].replace('AC',"")))/2)))

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

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())
  s1=S[l1-1:l2]
  z=0
  flg=0
  for k in s1:
    if k == 'A':
      flg=1
      continue
    elif k == 'C' and flg == 1:
      z+=1
    flg=0
  print(z)

Submission status: Time Limit Exceeded

Solution code:
def ac_count(alist):
    ac_count=0
    i=0
    while i < len(alist)-1:
        if alist[i]=='A':
            if alist[i+1]=='C':
                ac_count+=1
                i+=2
            else:
                i+=1
        else:
            i+=1
    return ac_count

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, Q = map(int, input().split())
S = input()
L_R = np.array([input().split() for _ in range(Q)], dtype=int)
L = L_R[:,0]
R = L_R[:,1]

for l, r in zip(L, R):
    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())
  tmp = S[l-1:r]
  tmp = tmp.replace('AC','z')
  print(tmp.count('z'))

Submission status: Time Limit Exceeded

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

A = input()

for j in range(b):
    x, y = map(int ,input().split())
    print(A[x-1:y].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int,input().split())
S = input()
LRlist = []
for i in range(Q):
    LRlist.append(list(map(int,input().split())))
indexlist = []
for i in range(len(S)-1):
    if S[i] == 'A':
        if S[i+1] == 'C':
            indexlist.append(i)
for LR in LRlist:
    L = LR[0]
    R = LR[1]
    answer = 0
    for i in indexlist:
        if L - 1 <= i <= R - 2:
            answer += 1
        elif R - 2 < i:
            break
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
char_numbers = [int(e) for e in input().split(" ")]

char = input()

questions = []
for i in range(char_numbers[1]):
    questions.append([int(e) - 1 for e in input().split()])


for i in questions:
    start = i[0]
    end = i[1] + 1
    count = 0
    while start > -1:
        start = char.find("AC",start,end)
        if start == -1:
            exit
        else:
            start = start + 2
            count = count + 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N, Q = (int(i) for i in input().split())
S = input()
lr = []
for _ in range(Q):
    lr.append([int(i) for i in input().split()])  # S += [input()] とも書けるprint(lr)
# print(lr)
# print(S)
for lis in lr:
    l = lis[0]
    r = lis[1]
    part = S[l - 1:r]
    # print(part)
    # part2 = part.replace("AC", "")
    # print("part", part2)
    print(part.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    ans = []
    carray = [0] * N
    for i in range(1,N):
        # print(S[i-1:i+1])
        # if(S[i-1:i+1] == 'AC'):
        #     carray[i:] = map(lambda x:x+1, carray[i:])
        if(S[i-1:i+1] == 'AC'):
            carray[i] = 1

    # print(carray)
    for i in range(Q):
        # print(carray[l[i]-1:r[i]])
        # t = carray[:r[i]+1].count(1)-carray[:l[i]].count(1)
        t = carray[l[i]:r[i]].count(1)
        ans.append(t)

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


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N, Q = list(map(int, input().split()))
S = input()
target = 'AC'
index = -1
idx = []
while True:
    index = S.find(target, index + 1)
    if index == -1:
        break
    idx.append(index+1)

ans = ''
for i in range(Q):
    l, r = list(map(int, input().split()))
    cnt = 0
    for j in idx:
        if l <= j < r:
            cnt += 1
    ans += str(cnt) + '\n'

print(ans, end='')

Submission status: Time Limit Exceeded

Solution code:
def countAC(s):
    index = []
    for i in range(N):
        if i == N-1:
            break
        if s[i] == 'A':
            if s[i+1] == 'C':
                index.append(1)
                continue
        index.append(0)
    return index

N,Q = (int(_) for _ in input().split())
S = input()
SIndex = countAC(S)
out = 0
for i in range(Q):
    l,r = (int(_) for _ in input().split())
    s = SIndex[l-1:r-1]
    print(sum(s))
    out = 0

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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':
        if S[i + 1] == 'C':
            AC.append(i)

ans = []

for i in range(Q):
    li, ri = map(int, input().split())
    count = 0
    for i in range(li - 1, ri - 1):
        if i in AC:
            count += 1
    ans.append(count)

for a in ans:
    print(a)

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

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
word_list=list(S)
for i in range(Q):
  count=0
  flag =0
  l,r=map(int,input().split())
  box=word_list[l-1:r]
  for i in box:
    if i == 'A':
      flag =1
    elif i!= 'C':
      flag=0
    if flag == 0 and i=='C':
      flag = 0
    if flag == 1 and i =='C':
      count += 1
  print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

    ans = []
    ac = 'AC'
    for q in range(Q):
        lq, rq = input().split()
        S_sub = S[int(lq) -1 : int(rq)]
        ans.append(str(S_sub.count(ac)) + '\n')

    # solve
    print(''.join(ans), end="")
            


if __name__ == '__main__':
    C()

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

cl = [0 for i in range(len(S))]

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


#print(cl) 
#print(S)

for l,r in lr:
    sub = cl[l-1:r]
    res = sub.count(1)
    if sub[0] == 1:
        res -= 1
    print(res)

Submission status: Time Limit Exceeded

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

N, M = (int(i) for i in input().split())
moji = input()
e = [[int(i) for i in input().split()] for i in range(M)]

c_list = []

if moji.count('AC') == None:
    print(0)
    exit()

for idx in e:
    sub = moji[idx[0]-1:idx[1]]
    if 'AC' in sub:
        print(sub.count('AC'))
    else:
        print(0)

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])
    end = int(lr[i][1])

    cnt = s[start-1:end].count('AC')

    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
l=[]
for i in range(q):
  l.append(tuple(map(int,input().split())))
for j in range(q):
  x,y=l[j]
  a=s[x-1:y]
  num=a.count('AC')
  print(num)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#GeT AC

n, q= map(lambda x: int(x), input().split(' '))
s= input()
gaplist= []
for i in range(q):
    l, r= map(lambda x: int(x), input().split(' '))
    internal_s= s[l-1:r]
    replaced_inteernal_s= internal_s.replace('AC', '')
    gap= int((len(internal_s)-len(replaced_inteernal_s))/2)
    gaplist.append(gap)

for value in gaplist:
    print(value)

Submission status: Time Limit Exceeded

Solution code:

count = 0;
maxnum=0;
n,m = input().split();

s = input();




for j in range(int(m)):
    x,y = input().split();
    for i in range(int(x)-1,int(y)-1):
        if(s[i]=='A' and s[i+1] == 'C'):
            count = count +1;
    print(count);  
    count = 0;

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

Submission status: Time Limit Exceeded

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

for i in range(q):
  l, r = map(int, input().split())
  print(sum(l-1 <= i and i + 1 < r for i in cache))

Submission status: Time Limit Exceeded

Solution code:
import re

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

for i in range(Q):
    c = 0
    word_s = l[i][0] - 1
    word_e = l[i][1]
    for m in re.finditer('AC', S[word_s:word_e]):
        c += 1
    print(c)

Submission status: Time Limit Exceeded

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

for s1,e1 in qlists:
    print(s[s1-1:e1].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int, input().split())
S = input()
for _ in range(q):
    a, b = map(int, input().split())
    ans=0
    for i in range(a,b):
        if S[i-1] == "A" and S[i] == "C":
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

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

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


for i in range(q):
    count=0
    target_s=s[l_list[i]-1:r_list[i]]
    indexes=[i for i, x in enumerate(target_s) if x=="A"]
    for j in indexes:
        if j+1<=len(target_s)-1 and target_s[j+1]=="C":
            count=count+1

    print(count)

Submission status: Time Limit Exceeded

Solution code:
length,question = map(int, input().split())
string = input()
e = [[int(i) for i in input().split()] for i in range(question)]
c = 0
tmp = []
for i in e:
    s = ''
    for j in range(i[0],i[1]+1):
        s+=string[j-1]
    for n in range(len(s)):
        if s[n:n+2] == "AC":
            c+=1
    print(c)
    c = 0

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())
    st=s[l-1:r]
    print((len(st)-len([i for i in st.split("AC") if i!=""]))//2)