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()
list = [0]*q

for i in range(q):
    start,end=[int(i) for i in input().split()]
    list[i] = s.count("AC", start-1, end)

for i in list:
    print(i)

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)]
count = 0

for i in range(q):
    s_extra = s[(lr[i][0] - 1):lr[i][1]]
    print(s_extra.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)]
count = 0
for i in range(q):
    for j in range(lr[i][0] - 1, lr[i][1] - 1):
        if s[j] == 'A' and s[j + 1] == 'C':
            count += 1

    print(count)
    count = 0

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
 # -*- coding: utf-8 -*-
     
[N, Q] = [int(i) for i in input().split()]

S = input()

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

for q in range(Q):
    l = lr[q][0]
    r = lr[q][1]
    s = S[l-1:r]

    # 文字列中に'AC'がなければ0を出力
    if 'AC' not in s:
        print(0)
        continue

    count = s.count('AC')
    print(count)

Submission status: Time Limit Exceeded

Solution code:
 # -*- coding: utf-8 -*-
     
[N, Q] = [int(i) for i in input().split()]

S = input()

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

for q in range(Q):
    l = lr[q][0]
    r = lr[q][1]
    s = S[l-1:r]
    count = s.count('AC')
    print(count)

Submission status: Time Limit Exceeded

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

for l,r in LR:
  check_s = S[l-1:r]
  ans = 0
  start_index = 0
  for end_index in range(len(check_s)):
    if check_s[start_index] == "A":
      if check_s[end_index] == "C":
        ans +=1
      else:
        start_index = end_index
    else:
      start_index = end_index

  print(ans)

Submission status: Time Limit Exceeded

Solution code:
lst_1 = input().split()
N = int(lst_1[0])
Q = int(lst_1[1])
moji_lis = input().split()
lst_lr = []
for i in range(Q):
    lst_lr.append(input().split())
#print(lst_lr)

moji_retu = moji_lis[0]
lst_M = list(moji_retu)

#print(lst_M)

lst_AC = []

i = 0
while i < (N - 1):
    if (lst_M[i] == "A") and (lst_M[i + 1] == "C"):
        lst_AC.append(str(i + 1))
        i += 2
    else:
        i += 1

#print(lst_AC)

for i in range(Q):
    lst_ans = []
    lst_ans = [lst_AC for j in range(len(lst_AC)) if (int(lst_lr[i][0]) <= int(lst_AC[j])) and (int(lst_lr[i][1]) > int(lst_AC[j]))]

    print(len(lst_ans))

Submission status: Time Limit Exceeded

Solution code:
lst_1 = input().split()
N = int(lst_1[0])
Q = int(lst_1[1])
moji_lis = input().split()
lst_lr = []
for i in range(Q):
    lst_lr.append(input().split())
#print(lst_lr)

moji_retu = moji_lis[0]
lst_M = list(moji_retu)

#print(lst_M)

lst_AC = []

i = 0
while i < (N - 1):
    if (lst_M[i] == "A") and (lst_M[i + 1] == "C"):
        lst_AC.append(str(i + 1))
        i += 2
    else:
        i += 1

#print(lst_AC)

for i in range(Q):
    lst_ans = []
    for j in range(len(lst_AC)):
        if (int(lst_lr[i][0]) <= int(lst_AC[j])) and (int(lst_lr[i][1]) > int(lst_AC[j])):
            lst_ans.append(lst_AC[j])
    print(len(lst_ans))

Submission status: Time Limit Exceeded

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

for i in range(n):
    com, term = map(int, input().split())
    print(string[com-1:term].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
set = input().split()
len_q = [int(set[0]), int(set[1])]
char_code = list(input())
len_q_set = [[int(i) for i in input().split()] for j in range(0, len_q[1])]
count_ac = 0

for i in range(0, len_q[1]):
    for j in range(len_q_set[i][0] - 1, len_q_set[i][1] - 1):
        if char_code[j] == "A" and char_code[j+1] == "C":
            count_ac += 1
    print(count_ac)
    count_ac = 0

Submission status: Time Limit Exceeded

Solution code:
set = input().split()
len_q = [int(set[0]), int(set[1])]
code = input()
len_q_set = [[int(i) for i in input().split()] for j in range(0, len_q[1])]
char_code = list(code)
count_ac = 0

for i in range(0, len_q[1]):
    for j in range(len_q_set[i][0] - 1, len_q_set[i][1] - 1):
        if char_code[j] == "A" and char_code[j+1] == "C":
            count_ac += 1
    print(count_ac)
    count_ac = 0

Submission status: Time Limit Exceeded

Solution code:
set = input().split()
len_q = [int(set[0]), int(set[1])]
code = input()
len_q_set = [[i for i in input().split()] for j in range(0, len_q[1])]
char_code = list(code)
count_ac = 0

for i in range(0, len_q[1]):
    for j in range(int(len_q_set[i][0]) - 1, int(len_q_set[i][1]) - 1):
        if char_code[j] == "A" and char_code[j+1] == "C":
            count_ac += 1
    print(count_ac)
    count_ac = 0

Submission status: Time Limit Exceeded

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

# 1文字目から n 文字目までの AC の数 = 1文字目から n - 1 文字目までの、Cを右に持つ A の数

where_ac = [0] * N

for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        where_ac[i+1] += 1

for lr in lr_list:
    print(sum(where_ac[0:lr[1]]) - sum(where_ac[0:lr[0]]))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
lr_list = [list(map(int, input().split())) for q in range(Q)]
 
# 1文字目から n 文字目までの AC の数 = 1文字目から n - 1 文字目までの、Cを右に持つ A の数
 
where_ac = [0] * N
 
for i in range(N-1):
	#    print(i)
    if S[i] == 'A' and S[i+1] == 'C':
        where_ac[i+1] += 1
 
count = [sum(where_ac[0:i+1]) for i in range(N)]
 
for lr in lr_list:
    print(count[lr[1]-1] - count[lr[0]-1])

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc122/tasks/abc122_c

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

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


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

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc122/tasks/abc122_c

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

for i in range(q):
	count=0
	l,r=map(int,input().split())
	for j in range(l,r):
		if s[j-1:j+1]=="AC":
			count+=1
	answerlist.append(count)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
dict={}
for _ in range(Q):
    l,r=map(int,input().split())
    string=S[l-1:r]
    if string in dict:
        print(dict[string])
    else:
        v=string.count('AC')
        print(v)
        dict[string]=v

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n, q = [ int(v) for v in input().split() ]
s = input()
ac_list = [ 0 for i in range(n-1) ]
for i in range(n-1):
	if s[i:i+2] == "AC":
		ac_list[i] += 1


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

Submission status: Time Limit Exceeded

Solution code:

n, q = [ int(v) for v in input().split() ]
s = input()
ac_list = [ 0 for i in range(n-1) ]
for i in range(n-1):
	if s[i:i+2] == "AC":
		ac_list[i] += 1


for i in range(q):
	l, r = [ int(v) for v in 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()
ans=[]
for i in range(q):
	x,y=map(int,input().split())
	ans.append(s[x-1:y].count('AC'))
for i in ans:
	print(i)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
ans=[]
for i in range(q):
	x,y=map(int,input().split())
	ans.append(s[x-1:y].count('AC'))
print('\n'.join(list(map(str,ans))))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
flag = False
AClist = [0] * N
for i in range(N):
    if S[i] == "A":
        flag = True
    elif S[i] == "C" and flag:
        AClist[i] = -1
        AClist[i-1] = 2
        flag = False
for i in range(Q):
    l , r = map(int, input().split())
    l -= 1
    ans = sum(AClist[l:r])
    if AClist[r-1] == 2:
        ans -= 2
    if AClist[l] == -1:
        ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
flag = False
AClist = [0] * N
for i in range(N):
    if S[i] == "A":
        flag = True
    elif S[i] == "C" and flag:
        AClist[i] = -1
        AClist[i-1] = 2
        flag = False
ansList = [0] * Q
for i in range(Q):
    l , r = map(int, input().split())
    l -= 1
    ans = sum(AClist[l:r])
    if AClist[r-1] == 2:
        ans -= 2
    if AClist[l] == -1:
        ans += 1
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# sys.stdin.readline()
import sys
input = sys.stdin.readline

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

Submission status: Time Limit Exceeded

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

for q_i in range(Q):
  l, r = input().strip().split()
  l = int(l)-1
  r = int(r)  
  subs = S[l:r]
  answer = 0
  for j, c in enumerate(subs):
    if j==0:
      pass
    else:
      if subs[j] == 'C' and subs[j-1] == 'A':
        answer += 1
  print(answer)

Submission status: Time Limit Exceeded

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

for q_i in range(Q):
  l, r = input().strip().split()
  l = int(l)-1
  r = int(r)  
  print(S.count("AC", l, r))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ac_list = []

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

for i 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()
flg = 0
for i in range(q):
    l, r = map(int, input().split())
    cnt = 0
    for i in range(l-1, r):
        if s[i] == 'A':
            flg = 1
        elif s[i] == 'C' and flg == 1:
            cnt += 1
            flg = 0
        else:
            flg =0
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
list = [[0 for i in range(2)] for j in range(Q)]
#print(list)

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

for i in range(Q):
    sub_S = S[list[i][0]-1:list[i][1]]
    count = 0
    for j in range(len(sub_S)-1):
        if sub_S[j] == 'A':
            if sub_S[j:j+2] == 'AC':
                count += 1
                j += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
list = [[0 for i in range(2)] for j in range(Q)]
#print(list)

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

for i in range(Q):
    sub_S = S[list[i][0]-1:list[i][1]]
    count = 0
    for j in range(len(sub_S)-1):
        if sub_S[j] == 'A':
            if sub_S[j:j+2] == 'AC':
                count += 1
    print(count)

Submission status: Time Limit Exceeded

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

for i in range(Q):
    sub_S = S[list[i][0]-1:list[i][1]]
    count = 0
    for j in range(len(sub_S)-1):
        if sub_S[j] == 'A':
            if sub_S[j:j+2] == 'AC':
                count += 1
    print(count)

Submission status: Time Limit Exceeded

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

#print(list)

target_s = 'AC'
for i in range(Q):
    sub_S = S[list[i][0]-1:list[i][1]]

    '''
    #print(i,sub_S)
    count = 0
    for j in range(len(sub_S)+1-len(target_s)):
        sub_sub_S = sub_S[j:j+len(target_s)]
        #print(sub_sub_S)
        if sub_sub_S == target_s:
            count += 1
    '''

    print(sub_S.count(target_s))

Submission status: Time Limit Exceeded

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

#print(list)

target_s = 'AC'
for i in range(Q):
    sub_S = S[list[i][0]-1:list[i][1]]
    #print(i,sub_S)
    count = 0
    for j in range(len(sub_S)+1-len(target_s)):
        sub_sub_S = sub_S[j:j+len(target_s)]
        #print(sub_sub_S)
        if sub_sub_S == target_s:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import re
N, Q = map(int, input().split())
S = input()
idx_list = [1 if S[i:i + 2] == 'AC' else 0 for i in range(len(S) - 1)]
for _ in range(Q):
  l, r = map(int, input().split())
  print(sum(idx_list[l - 1:r - 1]))

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

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:
# coding: utf-8

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

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

count = len(ac)
for i in range(q):
    l,r = (map(int, input().split()))
    x = sum(j<l for j in ac)
    y = sum(j+1>r for j in ac)
    print(count-x-y)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
ans_list=[]
for i in range(q):
    a,b=map(int,input().split())
    ans=0
    lis=s[a-1:b]
    while "AC" in lis:
        lis=lis.replace("AC","",1)
        ans+=1
    ans_list.append(ans)
for j in range(len(ans_list)):
    print(ans_list[j])

Submission status: Time Limit Exceeded

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

s=input()

input_list=[]

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

for i in range(q):
    temp=0
    for j in range(input_list[i][0]-1,input_list[i][1]-1):
        if s[j]=='A' and s[j+1]=='C':
            temp=temp+1
    print(temp)

Submission status: Time Limit Exceeded

Solution code:
import sys
imput =sys.stdin.readline
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())
S =input()
for _ in range(Q):
  l,r = map(int,input().split())
  print(S[l-1:r].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import re
N,Q=map(int,input().split())
S=input()
list1=[list(map(int,input().split())) for i in range(Q)]
for i in range(Q):
    str1=S[list1[i][0]-1:list1[i][1]]
    list2=re.findall("AC",str1)
    print(len(list2))

Submission status: Time Limit Exceeded

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

S = input()

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N, Q = map(int, input().split())
S = input()
l = [0 for i in range(Q)]
r = [0 for i in range(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]]
    print(s.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N, Q = map(int, input().split())
S = input()
l = [0 for i in range(Q)]
r = [0 for i in range(Q)]
ans = r = [0 for i in range(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]]
    print(s.count('AC'))

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

import re
for lr in LR:
    print(len(re.findall('AC', S[lr[0]-1:lr[1]])))

Submission status: Time Limit Exceeded

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

for lr in LR:
    print(S[lr[0]-1:lr[1]].count('AC'))

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

import re
for lr in LR:
    print(re.subn('AC', '', S[lr[0]-1:lr[1]])[1])

Submission status: Time Limit Exceeded

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

counter = 0
for lr in LR:
    print(re.subn('AC', '_', S[lr[0]-1:lr[1]])[1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int, input().split())
s=input()
t=s.replace("AC","11")
u=[0 if i!="1" else 1 for i in t]
for i in range(q):
    l,r=map(int, input().split())
    ans=sum(u[l-1:r])
    if s[l-1]=="C" and s[r-1]=="A":
        print(ans//2-1)
    else:
        print(ans//2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for _ in range(q):
	st , en =map(int,input().split())
	t = s[st-1 : en]
	cnt = 0
	for i in range(len(t)-1):
		if t[i] == 'A' and t[i+1]=='C':
			cnt +=1

	print(cnt)
	cnt = 0

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#Coding:Utf-8

N,Q=input().split()
S=list(map(str,input()))
b=[]
c=[]
for i in range(int(Q)):
  a=list(map(int, input().split()))
  b.extend((a))
for j in range(0,int(Q)*2,2):
  count=0
  for l in range(b[j],b[j+1]):
    if S[l-1]=="A" and S[l]=="C":
      count+=1
  else:
    print(count)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
i=0
bb=[]
while True:
    b=s.find('AC', i)
    if b<0:
        break
    bb.append(b)
    i=b+1
for _ in range(q):
    l,r=map(int,input().split())
    print(sum(1 for b in bb if l-1<=b<=r-2))

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = (int (x) for x in input().split())
str_input = input()

for i in range(Q):
    start, end = (int (x) for x in input().split())
    target = str_input[start-1:end]
    count = 0

    for j in range(len(target)-1):
        if target[j] == "A" and target[j+1] == "C":
            count += 1

    print(count)

Submission status: Time Limit Exceeded

Solution code:
import re

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

for i in range(q):
    prt = s[l[i]-1:r[i]]
    mch = re.findall('AC', prt)
    print(len(mch))

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
t = [0]*(N+1)
for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        t[i+1] = 1

for _ in range(Q):
    l=list(map(int,input().split()))
    print(sum(t[l[0]:l[1]]))

Submission status: Time Limit Exceeded

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

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

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

for j in range(len(l)):
    print(sum(t[l[j][0]:l[j][1]]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

S = input()
cumurative_sum_lst = np.zeros(N+1)
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        cumurative_sum_lst[i+1:] += 1

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

    tmp = cumurative_sum_lst[r] - cumurative_sum_lst[l]
    outputs.append(int(tmp))

for i in outputs:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
So = input()
import re
S = So.replace('AC', '11')
S = re.sub('[A-Z]', '0', S)
Si = list(map(int, S))

for q in range(Q):
    s, e = map(int,input().split())
    si = Si[s-1:e]
    so = So[s-1:e]
    if So[s-1] == 'C':
        si.pop(0)
    if So[e-1] == 'A':
        si.pop()
    #print(si)
    print(sum(si)//2)

Submission status: Time Limit Exceeded

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

for i in range(1,len(S)+1):
    t.append(S[0:i].count('AC'))

for i in range(Q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-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 i in range(l-1,r-1):
    if s[i]+s[i+1]=="AC":
      count=count+1
  print(count)

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

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int, input().split())
w = input()
for i in range(b):
  w1 = ""
  c, d = map(int, input().split())
  for j in range(c-1,d):
    w1 += w[j]
  print(w1.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int, input().split())
w = input()
for i in range(b):
  c, d = map(int, input().split())
  w1 = w[c-1:d]
  print(w1.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, Q = map(int, input().split())

S = input()
AC_place_arr = np.zeros(N)
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        AC_place_arr[i] = 1


outputs = []
for i in range(Q):
    l, r = map(int, input().split())
    count = int(np.sum(AC_place_arr[l-1:r-1]))
    outputs.append(count)

for i in outputs:
    print(i)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

for i in outputs:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n, nQueries = map(int,input().split())
inString = input()
queries = [ [int(x)-1 for x in input().split()] for i in range(nQueries)]

for (i,j) in queries:
    count = 0
    while(i < j):
        if(inString[i] == "A" and inString[i+1] == "C"):
            i+=2
            count+=1
        else:
            i+=1
        
    print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a = map(int,input().split())
a = list(a)
for g in range(len(a)):
    a[g] = int(a[g])
b = input()
b = list(b)
c = [list(map(int,input().split())) for i in  range(a[1])]
d = []
e = 0
for j in range(a[1]):
    k = c[j][1] - c[j][0]
    d = b[c[j][0]-1:c[j][1]]
    for s in range(k):
        if (d[s] == 'A') & (d[s+1] == 'C'):
            e += 1
    print(e)
    e = 0

Submission status: Time Limit Exceeded

Solution code:
#文字列の要素の数、問題の数
N, Q = map(int, input().split())
#大文字の文字列の入力
S = list(input())
#問の値を格納しておくリスト
lst = []
#各問題の解を格納しておくリスト
ACcnt = []
#各問題のスライスする範囲を格納する
for i in range(Q):
    l, r = map(int, input().split())
    lst.append([l-1, r])
#Q問とく
for i in range(Q):
    #入力した範囲をスライスする
    nS = S[lst[i][0]:lst[i][1]]
    new = " "
    for j in nS:
        new += j       
    ACcnt.append(new.count("AC"))
#出力
for i in range(Q):
    print(ACcnt[i])

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]"):
    aclist = [] 
    end = N - 1
    for i in range(end):
        if S[i] == 'A' and S[i+1] == 'C':
            aclist.append(i)

    for i in range(Q):
        res = 0
        begin = l[i] - 1
        end   = r[i] - 2

        for ac in aclist:
            if ac >= begin:
                if ac <= end:
                    res += 1
                else:
                    break

        print(res)

            


# Generated by 1.1.4 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:
#!/usr/bin/env python3
import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    isAC = [False] * N
    
    end = N - 1
    for i in range(end):
        if S[i] == 'A' and S[i+1] == 'C':
            isAC[i] = True

    for i in range(Q):
        res = 0
        begin = l[i] - 1
        end   = r[i] - 1
        for j in range(begin,end):
            if isAC[j]:
                res += 1
        print(res)


# Generated by 1.1.4 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()