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

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 l,r in lr:
    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())))
ac = ['1' if 'AC'==s[i-1:i+1] else '0' for i in range(1,len(s))]
for i in lr: print(ac[i[0]-1:i[1]-1].count('1'))

Submission status: Time Limit Exceeded

Solution code:
import re

n,q = map(int,input().split())
s = input()
lr = []
for i in range(q): lr.append(list(map(int, input().split())))
for i in lr: print(len(re.findall('AC', s[i[0]-1:i[1]])))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
num = []
for Q 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()
num = []
for Q in range(q):
	l,r = map(int,input().split())
	num.append(s[l - 1:r].count('AC'))
for NUM in range(q):
	print(num[NUM])

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
n, q = [int(_) for _ in stdin.readline().rstrip().split()]
s = list(stdin.readline().rstrip())
data = [list(map(int, stdin.readline().rstrip().split())) for _ in range(q)]
for d in data:
    l = [0]
    sub_s = s[d[0]-1:d[1]]
    sub_n = len(sub_s)
    for i in range(sub_n):
        l.append(l[i]+1 if i+1 < sub_n and sub_s[i] == 'A' and sub_s[i+1] == 'C' else l[i])
    print(l[-1])

Submission status: Time Limit Exceeded

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

for v in se:
    str = s[v[0]-1:v[1]]
    print (str.count('AC'))

Submission status: Time Limit Exceeded

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

for i in range(q):
    l1, l2 = map(int, input().split())
    b = [i for i in a if  l1 <= i+1 < l2]
    print(len(b))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
moji = 'ACGT'

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

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
list1 = raw_input().split()


String = raw_input()

lr_list = []

q = int(list1[1])

for x in range(q):
    item_list = raw_input().split()
    lr_list.append(item_list)
    str_list = []

    l = int(lr_list[x][0]) -1
    r = int(lr_list[x][1])

    string_item = String[l:r]
    print string_item.count('AC')

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
list1 = raw_input().split()


String = raw_input()

lr_list = []

q = int(list1[1])

for x in range(q):
    item_list = raw_input().split()
    lr_list.append(item_list)

str_list = []

for x in range(q):
    l = int(lr_list[x][0]) -1
    r = int(lr_list[x][1])
    l = int(l)
    r = int(r)

    str_item = String[l:r]
    str_list.append(str_item)

for string in str_list:
    
    print string.count('AC')

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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=input().split()
  l_list.append(int(l))
  r_list.append(int(r))
f=0
j=0
AC=[]
while f>=0:
  f=S.find("AC",j,len(S))
  if f>=0:
    AC.append(f+1)
    j=f+1
for i in range(Q):
  n=sum(1 for x in AC if x>=l_list[i] and x<=r_list[i]-1)
  print(n)

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=input().split()
  l_list.append(int(l))
  r_list.append(int(r))
for i in range(Q):
  SS=S[int(l_list[i])-1:int(r_list[i])]
  n=0
  while "AC" in SS:
    n+=1
    SS=SS.replace("AC","",1)
  print(n)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n, q = map(int, stdin.readline().split())
s = stdin.readline().strip()
count = 0
for i in range(q):
    l, r = map(int, stdin.readline().split())
    for j in range(l - 1, r - 1):
        if s[j] + s[j + 1] == 'AC':
            count += 1

    print(count)
    count = 0

Submission status: Time Limit Exceeded

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

#入力
N, Q = map(int, raw_input().split())
#print("N", N)
#print("Q", Q)
S = raw_input()
#print("S", S)
l = [map(int, raw_input().split()) for i in range(0, Q)]
#print(l)

#print(l[1][0])

lstring = list(S)
#print(lstring)

lslice = [lstring[l[i][0]-1:l[i][1]] for i in range(0, Q)]
#print(lslice)
moji = ["".join(lslice[i]) for i in range(0, Q)]
#print(moji)
for i in range(0, Q):
    print(moji[i].count('AC'))

Submission status: Time Limit Exceeded

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

dp = [[0 for column in range(n)] for row in range(n)]
for i in range(n):
    dp[i][0] = 0
    for j in range(i + 1, n):
        if s[j-1] == 'A' and s[j] == 'C':
            dp[i][j] = dp[i][j-1] + 1
        else:
            dp[i][j] = dp[i][j-1]

for _ in range(q):
    i, j =  map(int, input().split())
    print(dp[i-1][j-1])

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, raw_input().split())
s = str(raw_input())
ans = []
arr = []
for i in range(n-1):
	if s[i:i+2] == 'AC':
		arr.append(1)
	else:
		arr.append(0)
for i in range(q):
	l, r = map(int, raw_input().split())
	print sum(arr[l-1:r-1])

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, raw_input().split())
s = str(raw_input())
ans = []
arr = []
for i in range(n-1):
	if s[i:i+2] == 'AC':
		arr.append(1)
	else:
		arr.append(0)
for i in range(q):
	l, r = map(int, raw_input().split())
	count = sum(arr[l-1:r-1])
	ans.append(count)
for i in range(q):
	print ans[i]

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

#入力
N, Q = map(int, raw_input().split())
#print("N", N)
#print("Q", Q)
S = raw_input()
#print("S", S)
l = []
for i in range(0, Q):
    l.append(map(int, raw_input().split()))
#print(l)

#print(l[1][0])

lstring = list(S)
#print(lstring)

for i in range(0, Q):
    lslice = lstring[l[i][0]-1:l[i][1]]
    #print(lslice)
    moji = "".join(lslice)
    #print(moji)
    print(moji.count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n_s, q_s = input().rstrip().split(' ')
n = int(n_s)
q = int(q_s)

s = input()
lr_list = []
for i in range(q) :
    l_s, r_s = input().rstrip().split(' ')
    l = int(l_s)
    r = int(r_s)
    lr_list.append([l, r])

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

Submission status: Time Limit Exceeded

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

s=input()
lr=[]

for _ in range(q):
    l,r=map(int,input().split())
    lr.append((l,r))
    
def count_x(s):
    count=0
    for i in range(len(s)):
        if s[i]=="x":
            count+=1
    return count

for l,r in lr:
    total=0
    print(count_x(s[l-1:r].replace("AC","x")))

Submission status: Time Limit Exceeded

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


for l,r in lr:
    total = 0
    aflag = False
    for i in range(l-1,r):
        c = s[i]
        if aflag:
            if c == 'C':
                total += 1
            aflag = False
        else:
            if c == 'A':
                aflag = True
    print(total)

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):
  first, last = map(int, input().split())
  print(s[first-1:last].count("AC"))

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):
  first, last = map(int, input().split())
  print(s[first-1:last].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
for _ in range(q):
  first, last = map(int, input().split())
  print(s[first-1:last].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]
	print(T.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
for j, temp in enumerate(a):
    #print(temp)
    str_sub = string[temp[0]-1:temp[1]]
    #print('j',j)
    if j == 0:
        test_dict[str_sub] = str_sub.count('AC')
        result = str(test_dict[str_sub])
        continue
    if test_dict.get(str_sub) and j >= 1:
        #print(test_dict.get(str_sub))
        result += '\n' + str(test_dict.get(str_sub))
        continue
    test_dict[str_sub] = str_sub.count('AC')
    result += '\n' + str(test_dict[str_sub])
    #print(test_dict[str_sub])
    #print('result', result)
print(result)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
for j, temp in enumerate(a):
    #print(temp)
    str_sub = string[temp[0]-1:temp[1]]
    #print('j',j)
    if j == 0:
        test_dict[str_sub] = str_sub.count('AC')
        result = str(test_dict[str_sub])
        continue
    if test_dict.get(str_sub) and j >= 1:
        #print(test_dict.get(str_sub))
        result += '\n' + str(test_dict.get(str_sub))
        continue
    test_dict[str_sub] = str_sub.count('AC')
    result += '\n' + str(test_dict[str_sub])
    #print(test_dict[str_sub])
    #print('result', result)
print(result)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
for temp in a[:100000]:
    #print(temp)
    str_sub = string[temp[0]-1:temp[1]]
    if test_dict.get(str_sub):
        print(test_dict.get(str_sub))
        continue
    test_dict[str_sub] = str_sub.count('AC')
    print(test_dict[str_sub])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = str(input())
SD = [0]*N

for n in range(N - 1):
    SD[n] = S[n]+S[n+1]

DONE = {}
for q in range(Q):
    l, r = map(int, input().split())

    if str(l)+" "+str(r) not in DONE.keys():
        cnt = SD[l - 1:r - 1].count("AC")
        DONE[str(l)+" "+str(r)] = cnt
        print(cnt)
    else:
        print(DONE[str(l)+" "+str(r)])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

    for i in range(len(S[l-1: r])-1):

        if S[l-1 + i: l-1 + i +2 ] == "AC":    
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = str(input())
SD = [0]*N

for n in range(N - 1):
    SD[n] = S[n]+S[n+1]

for q in range(Q):
    l, r = map(int, input().split())
    cnt = 0
    print(SD[l-1:r-1].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = str(input())
SD = {}

for n in range(N):
    SD[n] = S[n]

for q in range(Q):
    l, r = map(int, input().split())
    cnt = 0
    for i in range(l-1, r-1):
        if SD[i] + SD[i + 1] == "AC":
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

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

a_indexes = []
# 下処理として、Aの場所だけ覚えておく
for i in range(len(S)) :
    if (S[i] == "A") :
        a_indexes.append(i)

# 幅に応じて、Aの次がCかどうかを判定する
for item in q_list :
    from_index = item[0]
    to_index = item[1]
    # 次の文字がCであることを調べるので、toは1文字手前にする
    target_indexes = [i for i in a_indexes if i >= from_index-1 and i < to_index-1]
    ac_count = 0
    for index in target_indexes :
        if (S[index+1] == "C") :
            ac_count += 1
    
    print(ac_count)


# もちろんTLE。。。
# for item in q_list :
#     from_index = item[0]
#     to_index = item[1]
#     search_str = S[from_index-1:to_index]
#     find_index = 0
#     ac_count = 0
#     while(find_index != -1) :
#         find_index = search_str.find("AC",find_index)
#         if (find_index != -1) :
#             ac_count += 1
#             find_index += 1
#     print(ac_count)

# for item in q_list :
#     from_index = item[0]
#     to_index = item[1]
#     search_str = S[from_index-1:to_index]
    # print(search_str.replace("AC","X").count("X"))
    # print(search_str.count("AC"))

Submission status: Time Limit Exceeded

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

# もちろんTLE。。。
# for item in q_list :
#     from_index = item[0]
#     to_index = item[1]
#     search_str = S[from_index-1:to_index]
#     find_index = 0
#     ac_count = 0
#     while(find_index != -1) :
#         find_index = search_str.find("AC",find_index)
#         if (find_index != -1) :
#             ac_count += 1
#             find_index += 1
#     print(ac_count)

for item in q_list :
    from_index = item[0]
    to_index = item[1]
    search_str = S[from_index-1:to_index]
    # print(search_str.replace("AC","X").count("X"))
    print(search_str.count("AC"))

Submission status: Time Limit Exceeded

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

# もちろんTLE。。。
# for item in q_list :
#     from_index = item[0]
#     to_index = item[1]
#     search_str = S[from_index-1:to_index]
#     find_index = 0
#     ac_count = 0
#     while(find_index != -1) :
#         find_index = search_str.find("AC",find_index)
#         if (find_index != -1) :
#             ac_count += 1
#             find_index += 1
#     print(ac_count)

for item in q_list :
    from_index = item[0]
    to_index = item[1]
    search_str = S[from_index-1:to_index]
    print(search_str.replace("AC","X").count("X"))

Submission status: Time Limit Exceeded

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

for item in q_list :
    from_index = item[0]
    to_index = item[1]
    search_str = S[from_index-1:to_index]
    find_index = 0
    ac_count = 0
    while(find_index != -1) :
        find_index = search_str.find("AC",find_index)
        if (find_index != -1) :
            ac_count += 1
            find_index += 1
        
    
    print(ac_count)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = [i if i in 'AC' else '-' for i in input()]
for i in range(Q):
  l, r = map(int, input().split())
  a = ''.join([S[i] if S[i] == 'A' and S[i+1] == 'C' else '-' for i in range(l-1, r-1)])
  a = [i for i in a.split('-') if len(i) > 0]
  print(len(a))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
Slist = [0 for x in range(0,N)]
L = list()
R = list()

for x in range(0,N-1):
    if S[x] is 'A' and S[x+1] is 'C':
        Slist[x] = 1

for x in range(0,Q):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)

for x in range(0,Q):
    Sumple = Slist[L[x]-1:R[x]]
    answer = sum(Sumple) - Sumple[-1]
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
Slist = [0 for x in range(0,N)]
Answer = []

for x in range(0,N-1):
    if S[x] is 'A' and S[x+1] is 'C':
        Slist[x] = 1

for x in range(0,Q):
    l,r = map(int,input().split())
    Sumple = Slist[l-1:r]
    answer = sum(Sumple) - Sumple[-1]
    Answer.append(answer)

for x in range(0,len(Answer)):
        print(Answer[x])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
ans = []
rl = []
for i in range(Q):
    a,b = map(int,input().split())
    rl += [[a,b]]

for i in range(Q):
    count = 0
    for j in range(rl[i][0]-1,rl[i][-1]-1):
        if S[j] == "A" and S[j+1] == "C":
            count += 1
    ans.append(count)
    
for i in range(Q):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
 
def cnt():
    n, q = map(int, input().split())
    s = input()
    qs = []
    for i in range(q):
        qs.append(list(map(int, input().split())))
    for l, r in qs:
        que = deque(maxlen = 2)
        cnt = 0
        for a in s[l-1: r]:
            que.append(a)
            if que == deque(['A', 'C']):
                cnt += 1
        print(cnt)
        
cnt()

Submission status: Time Limit Exceeded

Solution code:
n,q = (int(i) for i in input().split())
S = input()
for i in range(q):
  x,y = (int(j) for j in input().split())
  print(S[x-1:y].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
import re


n, q = map(int, input().split())
s = input()
ql = set(range(q))
for i in ql:
    ans = 0
    l1, l2 = map(int, input().split())
    s_part = s[l1 - 1:l2]
    s_re = re.findall(r'(AC)', s_part)
    ans = len(s_re)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re


n, q = map(int, input().split())
s = input()
ql = set(range(q))
for i in ql:
    ans = 0
    l1, l2 = map(int, input().split())
    s_part = s[l1 - 1:l2]
    s_re = re.findall(r'(AC)', s_part)
    for j in s_re:
        if j == 'AC':
            ans += 1
    else:
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
ql = set(range(q))
for i in ql:
    ans = 0
    l1, l2 = map(int, input().split())
    s_part = s[l1 - 1:l2]
    sl = set(range(len(s_part)))
    for j in sl:
        if s_part[j:j+2] == 'AC':
            ans += 1
    else:
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
base=list(map(int,input().split()))
genom=input()
for i in range(base[1]):
    question=list(map(int,input().split()))
    print(genom[question[0]-1:question[1]].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, Q = tuple([int(x) for x in input().split(' ')])
S = input()
lr = [tuple([int(x) for x in input().split(' ')]) for i in range(Q)]

out = [] 
start = S.find('AC')
while start >= 0:
    out.append(start)
    start += 1
    start = S.find('AC', start)
out = np.array(out)

for l, r in lr:
    print(sum((out >= l - 1) * (out <= r - 2)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, Q = tuple([int(x) for x in input().split(' ')])
S = input()

out = [0] * N
 
start = S.find('AC')
while start >= 0:
    out[start] += 1
    start += 1
    start = S.find('AC', start)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, Q = tuple([int(x) for x in input().split(' ')])
S = input()

lr = []
for i in range(Q):
    lr.append(tuple([int(x) for x in input().split(' ')]))

out = np.zeros(N, int)

start = S.find('AC')
while start >= 0:
    out[start] += 1
    start += 1
    start = S.find('AC', start)

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = tuple([int(x) for x in input().split(' ')])
S = input()

lr = []
for i in range(Q):
    lr.append(tuple([int(x) for x in input().split(' ')]))

out = [0] * N

start = S.find('AC')
while start >= 0:
    out[start] += 1
    start += 1
    start = S.find('AC', start)

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

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().strip().split(' '))
s = input()
ac = []
for i in range(n-1):
    if s[i-1:i+1] == 'AC':
        ac.append(i)
for i in range(q):
    num = 0
    l, r = map(int, input().strip().split(' '))
    print(sum((x >= l and x < r) for x in ac))

Submission status: Time Limit Exceeded

Solution code:
N, Q = tuple([int(x) for x in input().split(' ')])
S = input()

lr = []
for i in range(Q):
    lr.append(tuple([int(x) for x in input().split(' ')]))

out = [0] * Q

start = S.find('AC')
while start >= 0:
    start += 1
    for i, (l, r) in enumerate(lr):
        if l <= start and r > start:
            out[i] += 1
    start = S.find('AC', start)

for x in out:
    print(x)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().strip().split(' '))
s = input()
ac = []
for i in range(n-1):
    if s[i-1:i+1] == 'AC':
        ac.append(i)
for i in range(q):
    num = 0
    l, r = map(int, input().strip().split(' '))
    for i in range(len(ac)):
        if ac[i] >= l and ac[i] < r: 
            num = num + 1
    print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
N,Q = map(int,sys.stdin.readline().rstrip().split())
S = sys.stdin.readline().rstrip()
lr = [list(map(int,sys.stdin.readline().rstrip().split())) for _ in range(Q)]
for i in lr:  
  print(S[i[0]-1:i[1]].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import sys
N,Q = map(int,sys.stdin.readline().rstrip().split())
S = sys.stdin.readline().rstrip()
for _ in range(Q):
  l,r  = map(int,sys.stdin.readline().rstrip().split())
  print(S[l-1:r].count("AC"))
  del l
  del r

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:
N, Q = map(int, input().split())
text = input()
for _ in range(Q):
    l, r = map(int, input().split())
    p = text[l-1:r]
    print(p.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
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):
    t=s[lr[i][0]-1:lr[i][1]]
    print(t.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i,j in enumerate(range(Q)):
    temp = map(int, raw_input().split())
    if i == 0:
        result = str(string[temp[0]-1:temp[1]].count('AC'))
    else:
        result += '\n' + str(string[temp[0]-1:temp[1]].count('AC'))
print(result)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
for i,temp in enumerate(a):
    if i == 0:
        result = str(string[temp[0]-1:temp[1]].count('AC'))
    else:
        result += '\n' + str(string[temp[0]-1:temp[1]].count('AC'))
print(result)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
for temp in a:
    print(string[temp[0]-1:temp[1]].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
for temp in a:
    str_sub = string[temp[0]-1:temp[1]]
    #print(str_sub)
    result = 0
    print(str_sub.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
for temp in a:
    str_sub = string[temp[0]-1:temp[1]]
    #print(str_sub)
    result = 0
    for i in range(len(str_sub)-1):
        if str_sub[i:i+2] == 'AC':
            result += 1
    print(result)

Submission status: Time Limit Exceeded

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

L = []
R = []
for i in range(Q):
    L, R = (int(i) for i in input().split())
    old_len = len(S)
    print(S[(L-1):R].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
# C - GeT AC
# https://atcoder.jp/contests/abc122/tasks/abc122_c
n, q = list(map(int, input().split()))

s = input()

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

cnt = []

for index in range(0, len(separators)):
    cnt.append(s[separators[index][0]-1:separators[index][1]].count('AC'))

for i in cnt:
    print(i)

Submission status: Time Limit Exceeded

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

s = input()

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

cnt = []

for separate in separators:
    current_string = s[separate[0]-1:separate[1]]

    cnt.append(current_string.count('AC'))

for i in cnt:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
length, quests = map(int, input().rstrip().split())
string = input()
positions = []

for i in range(len(string) - 1):
    if string[i] == "A" and string[i+1] == "C":
        positions.append(1)
    else:
        positions.append(0)

for i in range(quests):
    left, right = map(int, input().rstrip().split())
    count = 0
    for j in range(left-1, right-1):
        if positions[j] == 1 and right + 1 != len(positions) and j + 1 != right:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
length, quests = map(int, input().rstrip().split())
string = input()

for i in range(quests):
    left, right = map(int, input().rstrip().split())
    substring = string[left-1:right]
    j = 0
    count = 0
    while j < len(substring) - 1:
        if substring[j] == 'A' and substring[j + 1] == 'C':
            count += 1
            j += 2
        else:
            j += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import re
n, q = map(int, input().split(' '))
s = input()
l_r = []
for _ in range(q):
    l_r.append(tuple(map(int, input().split(' '))))
for (l, r) in l_r:
    agct_substr = re.findall(r'AC', s[l-1:r])
    print(len(agct_substr))

Submission status: Time Limit Exceeded

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

ixs = []
for i in range(int(q)):
    start, end = list(map(int, input().split(" ")))
    ixs.append([start-1, end])

for start, end in ixs:
    #print(s[start:end])
    print(s[start:end].count("AC"))