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()
L = len(S)
target = 'AC'
shiftID = len(target) - 1

found_id = []

for i in range(L-shiftID):
    if S[i:i+len(target)] == target:
        found_id.append(i)


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

    ans = 0
    for i in found_id:

        if l <= i and i+shiftID <= r:
            ans += 1
        elif r < i + shiftID:
            break

    print(ans)

Submission status: Time Limit Exceeded

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


for i in range(n[1]):
  count = 0
  st = s[q[i][0]-1:q[i][1]].strip("TG")
  for j in range(len(st)-1):
    if st[j] in "A":
      if st[j+1] in "C":
        count += 1
  print(count)

Submission status: Time Limit Exceeded

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


for i in range(n[1]):
  st = s[q[i][0]-1:q[i][1]].strip("TG")
  print(st.count("AC"))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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(" "))
    s = S[l-1:r]
    len_ss = 0
    for i in s.split("AC"):
        len_ss += len(i)
    print(int((len(s)-len_ss)/2))

Submission status: Time Limit Exceeded

Solution code:
length, loop_count = list(map(int, input().split()))
s = input()
list_AC = []
for i in range(0, len(s)-1):
  if s[i] == 'A' and s[i+1] == 'C':
    list_AC.append(1)
  else:
    list_AC.append(0)
while loop_count > 0:
  start, end = list(map(int, input().split()))
  print(sum(list_AC[start-1:end-1]))
  loop_count -= 1
  count = 0

Submission status: Time Limit Exceeded

Solution code:
length, loop_count = list(map(int, input().split()))
s = input()

count = 0

while loop_count > 0:
  start, end = list(map(int, input().split()))
  s_select = s[start-1:end]
  for i in range(0, len(s_select)-1):
    if s_select[i] == 'A' and s_select[i+1] == 'C':
      count += 1
  print(count)
  
  loop_count -= 1
  count = 0

Submission status: Time Limit Exceeded

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

ac = [0] * (n-1)
for i in range(0, n-1):
    if str[i:i+1+1] == "AC":
        ac[i] = 1

val = [0] * q

for i in range(0, q):
    l, r = [int(x) for x in input().split(" ")]
    val[i] = sum(ac[l-1:r-1])

for v in val:
    print(v)

Submission status: Time Limit Exceeded

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

l = []
r = []

for i in range(q):
    l_tmp,r_tmp = map(int,input().split())
    tmp_s = s[l_tmp-1:r_tmp]
    print(tmp_s.count("AC"))

Submission status: Time Limit Exceeded

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

l = []
r = []

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


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

Submission status: Time Limit Exceeded

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

counter = 0
for i in range(len(l)):
    for j in range(l[i]-1, r[i]-1):
        temp3 = S[j:j+2]
        if j == len(S):
            continue
        elif j == r[i]:
            continue
        elif temp3 == "AC":
            counter += 1
    print(counter)
    counter = 0

Submission status: Time Limit Exceeded

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

for i in range(q):
  a,b=map(int,input().split())
  huga=hoge[a-1:b]
  print(huga.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
I=lambda:map(int,input().split());n,q=I();s=input();a=0,
for i in range(n):a+=a[i]+(s[i-1:i+1]=='AC'),
while q:l,r=I();print(a[r]-a[l]);q-=1

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
ac=[0]*(n-1)
for i in range(n-1):
  ac[i]=(s[i]=="A" and s[i+1]=="C")
ans=""
for i in range(q):
  l,r=map(int,input().split())
  ans+=str(sum(ac[l-1:r-1]))+"\n"
print(ans,end="")

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
s = input()
rr = (list(map(int, input().split())) for _ in range(k))

from collections import Counter

for a, b in rr:
  c = Counter(s[a-1:b].replace('AC', '1'))['1']
  print(c)

Submission status: Time Limit Exceeded

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

pair = [0] * len(S)
for i in range(len(S)-1):
    if S[i] is 'A' and S[i+1] is 'C':
        pair[i] = 1

for i in range(Q):
    ans = 0
    l = lr[i][0]-1
    r = lr[i][1]-1
    for j in range(l,r):
        ans += pair[j]
    print(ans)

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())
    count=0
    for j in range(l-1,r-1):
        count+=(s[j:j+2]=="AC")
    print(count)

Submission status: Time Limit Exceeded

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

for i in range(Q):
    count = 0
    l = lr[i][0]-1
    r = lr[i][1]-1
    for j in range(l,r):
        if S[j] is 'A':
            if S[j+1] is 'C':
                count += 1
    print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
for i in range(Q):
    count=0
    l,r=map(int,input().split())
    for j in range(r-l):
        if S[l-1+j]=="A" and S[l+j]=="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):
    l,r=map(int,input().split())
    print(int((r-l+1-len(S[l-1:r].replace("AC","")))/2))

Submission status: Time Limit Exceeded

Solution code:
arr_len, q_num = map(int, input().split(" "))
array = input()
search_arr = 'AC'

for _ in range(q_num):
	count = 0
	search_l, search_r = map(int, input().split(" "))
	target_arr = array[search_l-1:search_r]

	for char in range(0, len(target_arr)-1):
		if target_arr[char:char+2] == search_arr:
			count += 1
	print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
	arr_len, q_num = map(int, input().split())
	array = str(input())
	search_arr = 'AC'

	for q in range(q_num):
		count = 0
		search_l, search_r = map(int, input().split())
		target_arr = array[search_l-1:search_r]

		for char in range(0, len(target_arr)-1):
			if target_arr[char:char+2] == search_arr:
				count += 1
		print(count)

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

Submission status: Time Limit Exceeded

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


for _ in range(Q):
  l, r = list(map(int, input().split()))
  s = S[l-1:r]
  print(len(re.findall("AC", s)))

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

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

Submission status: Time Limit Exceeded

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

for cnt 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 q in range(Q):
    ans=0
    q1,q2=map(int,input().split())
    q3 = q2 - q1
    for i in range(q2-q1):
        if S[q1-1+i:q1+i+1] == 'AC':
            ans+=1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
for q in range(Q):
    q1,q2=map(int,input().split())
    LIST = S[q1-1:q2].split('AC')

    print(len(LIST)-1)

Submission status: Time Limit Exceeded

Solution code:
import re
I=[]
R=[]

N,Q=map(int,input().split())
S=input()
for q in range(Q):
    q1,q2=map(int,input().split())
    ACLIST = re.findall('AC',S[q1-1:q2])
    print(len(ACLIST))

Submission status: Time Limit Exceeded

Solution code:
import re
I=[]
R=[]


N,Q=map(int,input().split())
S=input()
for q in range(Q):
    q1,q2=map(int,input().split())
    I.append(q1)
    R.append(q2)
    
count = 0

for i in range(Q):
    ACLIST = re.findall('AC',S[I[i]-1:R[i]])
    print(len(ACLIST))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

n,q =map(int,input().split())
l = input()
Count = [0] * q

for i in range(q):
    a, b = map(int, input().split())
    enki_hairetu = l[a-1:b]
    Count[i] = enki_hairetu.count("AC")

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

n,q =map(int,input().split())
l = input()
Count = []

for i in range(q):
    a, b = map(int, input().split())
    enki_hairetu = l[a-1:b]
    Count.append(enki_hairetu.count("AC"))

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

Submission status: Time Limit Exceeded

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

for i in range(q):
    n_list = [int(x) for x in input().split()]
    enki_hairetu = l[n_list[0]-1:n_list[1]]
    Count.append(enki_hairetu.count("AC"))

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

Submission status: Time Limit Exceeded

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

Start_end = []
for i in range(q):
    n_list = [int(x) for x in input().split()]
    Start_end.append(n_list)


for i in range(q):
    enki_hairetu = l[Start_end[i][0]-1:Start_end[i][1]]
    print(enki_hairetu.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

n,q =map(int,input().split())
l = list(input())
counter = 0

Start_end = []
for i in range(q):
    n_list = [int(x) for x in input().split()]
    Start_end.append(n_list)


for i in range(q):
    for j in range(Start_end[i][0],Start_end[i][1]):

        if(l[j-1] == "A"):
            if(l[j] == "C"):
                counter += 1

    print(counter)
    counter = 0

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

n,q =map(int,input().split())
l = list(input())
counter = 0

Start_end = []
for i in range(q):
    n_list = [int(x) for x in input().split()]
    Start_end.append(n_list)

for i in range(q):
    for j in range(Start_end[i][0],Start_end[i][1]):
        if(l[j-1] + l[j] == "AC"):
            
            counter += 1
    print(counter)
    counter = 0

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    length, question_count = map(int, input().split())

    string = input()
    for i in range(question_count):
        l, r = map(int, input().split())
        current_string = string[l - 1:r]
        print(current_string.count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = str(input())
lists = list(list(map(int, input().split())) for i in range(q))
AC_index = []
counter = 0

for k in range(n - 1):
    if s[k] == 'A' and s[k + 1] == 'C':
        AC_index.append(k)

for i in range(q):
    l, r = (lists[i][0] - 1), (lists[i][1] - 1)
    for j in AC_index:
        if l <= j <= r - 1:
            counter += 1
    print(counter)
    counter = 0

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

# ACの位置を記憶
ac_pos = []
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        ac_pos.append(i+1) # 1-index

for i in range(q):
    count = 0
    for j in ac_pos:
        if lr[i][0] <= j < lr[i][1]:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = str(input())
lists = list(list(map(int, input().split())) for i in range(q))
AC_index = []
counter = 0

for k in range(n-1):
    if s[k] + s[k+1] == 'AC':
        AC_index.append(k)

for i in range(q):
    l, r = (lists[i][0]-1), (lists[i][1]-1)
    for j in AC_index:
        if l <= j <= r-1:
            counter += 1
    print(counter)
    counter = 0

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = str(input())
lists = list(list(map(int, input().split())) for i in range(q))
AC_index = []
counter = 0

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

for i in range(q):
    l, r = (lists[i][0]-1), (lists[i][1]-1)
    for j in AC_index:
        if l <= j <= r-1:
            counter += 1
    print(counter)
    counter = 0

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

Submission status: Time Limit Exceeded

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

counter = 0

for i in range(q):
    seq = s[(lists[i][0]-1):(lists[i][1]+1)]
    for j in range(len(seq)-2):
        if seq[j] + seq[j+1] == 'AC':
            counter += 1
        else:
            pass
    print(counter)
    counter = 0

Submission status: Time Limit Exceeded

Solution code:
N, k = map(int, input().split())
S = input()
start, endl = [], []
for i in range(k):
  a, b = map(int, input().split())
  start.append(a)
  endl.append(b)
count = 0
for i in range(len(start)):
  for j in range(start[i]-1, endl[i]-1):
    if S[j] == 'A':
      if S[j+1] == 'C':
        count += 1
  print(count)
  count = 0

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
t = [[0 for i in range(2)] for j in range(q)]
for k in range(q):
    t[k][0], t[k][1] = map(int, input().split())

for l in range(q):
    count = 0
    for m in range(t[l][1] - t[l][0]):
        if s[t[l][0] - 1 + m] == "A" and s[t[l][0] + m] == "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, endl = map(int, input().split())
  j = S[start-1:endl]
  print(j.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]

ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]

i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())

ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]

def main(N, Q, S, lrs):
    acindex = []
    for i in range(N-1):
        if S[i] == 'A' and S[i+1] == 'C':
            acindex.append(i)
    for l, r in lrs:
        count = 0
        for i in acindex:
            if l-1 <= i and i <= r-2:
                count += 1
        print(count)


N, Q = i2nn()
S = i2s()
lr = ss2nnn(ii2ss(Q))
main(N, Q, S, lr)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = str(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())
s = str(input())

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

Submission status: Time Limit Exceeded

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

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

for i in range(Q):
    l, r = map(int, input().split())
    l = l - 1
    r = r - 1
    print(str(len([x for x in AC_appearance if l <= x and x+1 <= r])))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

import re

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
def ACGT(x):
    if x == "A":
        return 0
    if x == "C":
        return 1
    else:
        return 2

N, Q = map(int, input().split(" "))
S = np.array([ACGT(x) for x in input()])
lr = [[int(j) for j in input().split(" ")] for i in range(Q)]

ind = np.linspace(1,N,N)
posA = np.hstack((np.array([False]), (S == 0)[:-1]))
ind_cand = ind[posA]
posC = (S[posA] == 1)
indAC = ind_cand[posC]

for l, r in lr:
    print(np.sum(((indAC >= l+1) & (indAC <= r))))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=str(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:
l = input().split()
N,Q = int(l[0]),int(l[1])
S = input()
blue = []
for k in range(N-1):
  if S[k] == 'A' and S[k+1] == 'C':
    blue += [1]
  else:
    blue += [0]
for i in range(1,Q+1):
  rl = input().split()
  print(sum(blue[int(rl[0])-1:int(rl[1])-1]))

Submission status: Time Limit Exceeded

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

for i in range(a[1]):
  c = list(map(int, input().split()))
  d = 0
  for j in range(c[0] - 1, c[1] - 1):
    if(b[j] == "A" and b[j+1] == "C"):
      d += 1
  print(d)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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())
    y=S[l-1:r]
    ans=0
    for i in range(len(y)-1):
        if y[i:i+2]=='AC':
            ans+=1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
_, Q = [int(s) for s in input().strip().split(' ')]
S = input().strip()
ls = []
for i in range(Q):
    l, r = [int(s) for s in input().strip().split(' ')]
    ls.append((l, r))

for l, r in ls:
    cnt = 0
    s = S[l - 1:r]
    for j in range(len(s) - 1):
        if s[j] == 'A' and s[j + 1] == 'C':
            cnt += 1

    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
_, Q = [int(s) for s in input().strip().split(' ')]
S = input().strip()

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

    cnt = 0
    s = S[l - 1:r]
    for j in range(len(s) - 1):
        t = s[j:j + 2]
        if t == 'AC':
            cnt += 1

    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import re

_, Q = [int(x) for x in input().split()]
S = input()
ac = re.compile('AC')

results = []
for i in range(Q):
    l, r = [int(x) for x in input().split()]
    target = S[l-1:r]
    c = 0
    for j in range(len(target)-1):
        if target[j:j+2] == 'AC':
            c += 1
    results.append(c)

for i in results:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import re

_, Q = [int(x) for x in input().split()]
S = input()
ac = re.compile('AC')

results = []
for i in range(Q):
    l, r = [int(x) for x in input().split()]
    target = S[l-1:r]
    results.append(len(ac.findall(target)))

for i in results:
    print(i)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, q = list(map(int, input().split()))
s = input()
for i 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 = list(map(int, input().split()))
s = input()
lr = []
for i in range(q):
  lr.append(list(map(int, input().split())))
  str_a = s[(lr[i][0] - 1):(lr[i][1])].replace('AC', '+')
  print(str_a.count('+'))

Submission status: Time Limit Exceeded

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

for i in range(q):
  str_a = s[(lr[i][0] - 1):(lr[i][1])].replace('AC', '+')
  print(str_a.count('+'))

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
data=[]
for i in input():
  data.append(i)
  
def X(a,b):
  N=0
  for i in range(a-1,b-1):
    if data[i]=="A":
      if data[i+1]=="C":
        N=N+1
  print(N)
  
for i in range(0,Q):
  a,b=map(int,input().split())
  X(a,b)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(Q):
    L += [list(map(int, input().split()))]

for n in L:
    a = None if n[0] - 1 <= 0 else n[0] - 1
    b = None if n[1] - len(S) == 0 else n[1] - len(S)
    print(S[a:b].count('AC'))

Submission status: Time Limit Exceeded

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

for i in range(Q):
    L += [list(map(int, input().split()))]

for n in L:
    count = 0
    a = None if n[0] - 1 == 0 else n[0] - 1
    b = None if n[1] - len(S) == 0 else n[1] - len(S)
    ss = S[a:b]
    print(ss.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(map(int, input().split())))

num_list = []
for i in range(N-1):
    if S[i:i+2] == 'AC':
        num_list.append(1)
    else:
        num_list.append(0)

for i in range(Q):
    print(sum(num_list[LR[i][0]-1:LR[i][1]-1]))

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())
  sum = 0
  for j in range(start,end):
    if s[j-1:j+1] == 'AC':
      sum+=1
  print(sum)

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()
l_r_list = [[int(j) for j in input().split()] for i in range(q)]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def solve():
    N, Q = list(map(int, input().split(" ")))
    S = input()
    L, R = [], []
    for i in range(Q):
        l, r = list(map(int, input().split(" ")))
        L.append(l)
        R.append(r)
    
    for i in range(Q):
        s = S[L[i]-1:R[i]]

        ans = 0
        if len(s) < 2:
            print(ans)
            continue
        
        for i in range(0, len(s)-1):
            if s[i]+s[i+1] == "AC":
                ans += 1
        print(ans)


if __name__ == "__main__":
    solve()

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(map(int, input().split())))

for i in range(Q):
    L = S[LR[i][0]-1:LR[i][1]]
    cnt = 0
    for j in range(len(L)-1):
        if L[j:j+2] == 'AC':
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

line = np.ones([n,])
for i in range(n-1):
    if (s[i:i+2]=="AC"): 
        line[i]=1
    else:
        line[i]=0
        

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

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=str(input())
import numpy as np

grid = np.ones([q,2])
for i in range(q):
    l,r = map(int,input().split())
    grid[i,:] = [l,r] 

line = np.ones([n,])
for i in range(n-1):
    if (s[i:i+2]=="AC"): 
        line[i]=1
    else:
        line[i]=0
    
for i in range(0,q):
    target = line[int(grid[i,0])-1:int(grid[i,1]-1)]
    print(int(sum(target)))

Submission status: Time Limit Exceeded

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

line = []
for i in range(n-1):
    if (s[i:i+2]=="AC"): 
        line.append(1)
    else:
        line.append(0)
    
for i in range(0,q):
    target = line[grid[i][0]-1:grid[i][1]-1]
    print(sum(target))

Submission status: Time Limit Exceeded

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

line = []
for i in range(n-1):
    if (s[i]=="A")&(s[i+1]=="C"): 
        line.append(1)
    else:
        line.append(0)
    
for i in range(0,q):
    target = line[grid[i][0]-1:grid[i][1]-1]
    print(sum(target))

Submission status: Time Limit Exceeded

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


for i in range(0,q):
    target = s[grid[i][0]-1:grid[i][1]]
    count = 0
    flag = False
    for j in range(0,len(target)):
        if (flag == False)&(target[j]=="A"):
            flag = True
        elif (flag == True)&(target[j]=="C"):
            count += 1
            flag = False
    print(count)

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

s = []
List = [i for i, x in enumerate(S[:-1]) if x == 'A' and S[i + 1] == 'C']

for i in range(Q):
    ans = 0
    for j in range(len(List)):
        if lr[i][0] - 1 <= List[j] and List[j] + 1 <= lr[i][1] - 1:
            ans += 1
    print(ans)

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

s = []
List = [i for i, x in enumerate(S[:-1]) if x == 'A' and S[i + 1] == 'C']

for i in range(Q):
    ans = 0
    for j in range(len(List)):
        if (List[j] in range(lr[i][0] - 1, lr[i][1])) and ((List[j] + 1) in range(lr[i][0] - 1, lr[i][1])):
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
l = input().split()
S = input()
N = int(l[0])
Q = int(l[1])
lr = [input().split() for _ in range(Q)]
for i in range(Q):
  lrlr = lr[i]
  score = 0
  for check in range(int(lrlr[0])-1,int(lrlr[1])-1):
    if S[check] == 'A' and S[check+1] == 'C':
      score += 1
  print(score)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
x = []
y = []
for i in range(q):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
t = []
for i in range(n):
    tmps = s[:i+1]
    t.append(tmps.count("AC"))
for i in range(q):
    ans = t[y[i]-1] - t[x[i]-1]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
x = []
y = []
for i in range(q):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
for i in range(q):
    tmps = s[x[i]-1:y[i]]
    ans = tmps.count("AC")
    print(ans)