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:
import re

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

ans = [0] * q

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

    result = re.findall(r"AC", sl)
    # print(len(result))
    ans[i] = len(result)
print(*ans, sep="\n")

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())
    sl = s[l - 1 : r]
    # sl = sl.replace("AC", "-")
    # ans = sl.count("-")
    # print(ans)

    result = re.findall(r"AC", sl)
    print(len(result))

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())
    sl = s[l - 1 : r]
    sl = sl.replace("AC", "-")
    ans = sl.count("-")
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

N, Q = map(int, input().split())
S = input()
P = [[int(v) - 1 for v in sys.stdin.readline().split()] for _ in range(Q)]
X = [0] * (N - 1)

for i in range(N - 1):
    if S[i:i + 2] == 'AC':
        X[i] = 1

for l, r in P:
    cnt = sum(X[l:r])
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys

N, Q = map(int, input().split())
S = input()
P = [[int(v) - 1 for v in sys.stdin.readline().split()] for _ in range(Q)]

for l, r in P:
    substr = S[l:r + 1]
    cnt = 0
    for i in range(len(substr) - 1):
        if substr[i:i + 2] == 'AC':
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#import copy
def main():
    n,q = map(int,input().split()) 
    s=list(input())
    cnt=[0 for _ in range(n+2)]
    for i in range(n-1):
        if s[i]=="A" and s[i+1]=="C":
            cnt[i]=1            
    for _ in range(q):
        l,r = map(int,input().split())
        print(sum(cnt[l-1:r-1]))
main()

Submission status: Time Limit Exceeded

Solution code:
#import copy
def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト atcoder
    # ord(c) chr(2) alphabet <=> number
    n,q = map(int,input().split()) 
    s=list(input())
    cnt=[0 for _ in range(n+2)]
    for i in range(n-1):
        if ''.join(s[i:i+2])=="AC":
            cnt[i]=1            
    for _ in range(q):
        l,r = map(int,input().split())
        print(sum(cnt[l-1:r-1]))
main()

Submission status: Time Limit Exceeded

Solution code:
#import copy
def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト atcoder
    # ord(c) chr(2) alphabet <=> number
    n,q = map(int,input().split()) 
    s=list(input())
    for _ in range(q):
        l,r = map(int,input().split())
        t=s[l-1:r]
        cnt=0
        for i in range(len(t)-1):
            if ''.join(t[i:i+2])=="AC":
                cnt+=1
        print(cnt)
main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n,q = map(int,input().split())
s = list(input())
lr = [list(map(int,input().split())) for _ in range(q)]
for i in range(q):
  x = [s[j] for j in range(n) if (lr[i][0]-1) <= j <= (lr[i][1]-1)]
  print("".join(x).count("AC"))

Submission status: Time Limit Exceeded

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

Sev = [0] * n
for i in range(n-1):
  if S[i] == "A" and S[i+1] == "C":
    Sev[i] = 1

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

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())
  l = l-1
  r = r-1
  counter = 0
  for j in range(r - l):
    if S[l+j] == "A" and S[l+j+1] == "C":
      counter += 1
  print(counter)

Submission status: Time Limit Exceeded

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

for i in range(q):
  l, r = map(int, input().split())
  l = l-1
  r = r-1
  if r - l < 1:
    print(0)
  else:
    counter = 0
    for j in range(r - l):
      if S[l+j] == "A" and S[l+j+1] == "C":
        counter += 1
    print(counter)

Submission status: Time Limit Exceeded

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

# 最初から数えておく
C=[1 if S[i:i+2]=='AC' else 0 for i in range(N-1)]
#print(C)
#exit()

#print()
#print("#"*20)
for q in range(Q):
    l,r=map(int,input().split())
    #print(S[l-1:r].count("AC"))
    print(sum(C[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())
    print(S[l-1:r].count("AC"))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
l, r = [0]*q, [0]*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:
#2019/10/25
NQ, S, *lr = [s for s in open(0)]
# print(NQ, S, lr)
N, Q = map(int, NQ.split())
lr = [list(map(int, i.split())) for i in lr]
# print(N,Q,S,lr)
cnt=0
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()
slis=[0]*n
for i in range(len(s)-1):
	if s[i]+s[i+1]=="AC":
		slis[i]='1'
for j in range(q):
	l,r=map(int,input().split())
	print(slis[l-1:r-1].count("1"))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
slis=list(input())
ta_slis=[]
for i in range(q):
	l,r=map(int,input().split())
	t_slis=slis[l-1:r]
	counter=0
	for j in range(len(t_slis)-1):
		if t_slis[j]=='A':
			if t_slis[j+1]=='C':
				counter+=1
	print(counter)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = str(input())
W = []
L = []
R = []
for q in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

for s in S:
    W.append(s)

for n in range(N-1):
    if W[n] == 'A' and W[n+1] == 'C':
        W[n] = 'x'

for q in range(Q):
    print(W[L[q]-1:R[q]-1].count('x'))

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 = str(input())
L = []
R = []
for q in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

for q in range(Q):
    S_temp = S[L[q]-1:R[q]]
    count = S_temp.count('AC')
    print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import bisect

N,Q = list(map(int,stdin.readline().strip().split()))
S = input().strip()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

l_L,r_L = [],[]

for val in range(q):
    l,r = map(int,input().split())
    l_L.append(l-1)
    r_L.append(r-1)

s = list(s)
s.append(" ")

for val in range(n+1):
    if s[val] == "A" and s[val+1] == "C":
        s[val] = "*"


for val in range(q):
    tmp = s[l_L[val]:r_L[val]]
    print(tmp.count("*"))

Submission status: Time Limit Exceeded

Solution code:
def countAC(s, stt, end):
    count = 0
    for i in range(stt, end-1):
        if (s[i] == 'A' and s[i+1] == 'C'):
            count += 1
    return count

N, Q = map(int, input().split())
S = input()
ans = []
for q in range(Q):
    l, r = map(int, input().split())
    ans.append(countAC(S, l-1, r))

for q in range(Q):
    print(ans[q])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
s = input()
l = [list(map(int, input().split())) for _ in range(m)]
for i in range(m):
    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()

Sl1 = list(S)
Sl2 = list(S)
del Sl2[-1]

idx = [i for i, a in enumerate(Sl2) if a=="A"]

AT = [0]*N

for i in idx:
    if Sl1[i+1]=="C":
        AT[i] += 1

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

result = [0 for _ in range(q)]
for i in range(1, len(s)):
    if 'A' == s[i - 1] and 'C' == s[i]:
        for index, question in enumerate(questions):
            if question[0] <= i - 1 and question[1] > i:
                result[index] += 1
for num in result:
    print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
q =[]
for i in range(Q):
    q.append(list(map(int, input().split())))
for i,j in q:
    tmp = S[i-1:j].replace("G","").replace("T","")
    print(tmp.count("AC"))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
A=[list(map(int,input().split())) for i in range(q)]
B=[0]*(n+1)
for i in range(n):
    t=s[i:]
    cnt=0
    for j in range(len(t)-1):
        if t[j]+t[j+1]=="AC":
            cnt +=1
    B[i+1]=cnt

for l,r in A:
    print(B[l]-B[r])

Submission status: Time Limit Exceeded

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

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())
    ans=0
    for i in range(l-1,r-1):
        if s[i]=="A" and s[i+1]=='C':
            ans+=1
    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())
    ss=s[l-1:r]
    n=len(ss)
    ans=0
    for i in range(n-1):
        if ss[i]=="A" and ss[i+1]=='C':
            ans+=1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
s = str(input())
lr = [list(map(int, input().split())) for _ in range(q)]
ans = [0]*q
i = 0
while i<n-1:

    if s[i]=="A" and s[i+1]=="C":
        for j in range(q):
            if lr[j][0]-1<=i and lr[j][1]-2>=i:
                ans[j] = ans[j]+1
            else:
                continue
        i +=2
    elif s[i+1]=="A":
        i+=1
    else:
        i +=2

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

n,q = map(int,input().split())
s = input()
lr = [list(map(int,input().split())) for _ in range(q)]
ac_l = []
for i in range(n-1):
    if s[i:i+2] == "AC":ac_l.append(i+1)
ac = np.array(ac_l)

for i in range(q):
    print(np.sum(lr[i][0] <= ac) - np.sum(lr[i][1] <= 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)]
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 = input()
AClist = []

for i in range(N - 1):
  if(s[i:i + 2] == "AC"): AClist.append(i)

for i in range(Q):
  l, r = map(int, input().split())
  l -= 1
  r -= 1
  result = 0
  idx = 0
  
  while(idx < len(AClist) and l > AClist[idx]):
    idx += 1
    
  while(idx < len(AClist) and AClist[idx] + 1 <= r):
    idx += 1
    result += 1
  
  print(result)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(Q):
    ans = 0
    for j in range(lr[i][0], lr[i][1]):
        if S[j] == 'A' and S[j+1] == 'C':
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

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

S = list(input())
slice_list = []
for _ in range(Q):
    l , r =map(int,input().split())
    slice_list.append([l - 1,r])
for i in range(Q):
    cnt = 0
    work_s = S[slice_list[i][0] : slice_list[i][1]]
    for i in range(len(work_s) - 1):
        if work_s[i] == "A" and work_s[i + 1] == "C":
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = list(input())
lr_list = [0]*q
for i in range(q):
    l,r = map(int,input().split())
    lr_list[i] = s[l-1:r]
for i in lr_list:
    pre_s = "hoge"
    ans = 0
    for j in i:
        if pre_s == "A" and j == "C":
            ans += 1
        pre_s = j
    print(ans)

        
#print(lr_list)

Submission status: Time Limit Exceeded

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

s = input()

count = []

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

Submission status: Time Limit Exceeded

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

s = input()

count = []

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

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

Submission status: Time Limit Exceeded

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

s = input()

count = []

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

for j in range(0,q) :
    print(count[j])

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)]
s_len = len(s)
account = s.count('AC')
count = 0
for i in range(q):
    center = len(s[l[i][0]-1:l[i][1]])
    if center <= s_len:
        print(s[l[i][0]-1:l[i][1]].count('AC'))
    else:
        '''
        left = s[0:]
        if s[l[i][0]-1:l[i][0]+1] == 'AC':
            count += 1
        if s[l[i][1]-1:l[i][1]+!] =='AC':
            count += 1
        print(account-)
        '''
        pass

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
t=list(map(int,input().split()))
s=input()
u=[list(map(int,input().split())) for _ in range(t[1])]
list=[0 for i in range(len(s))]
a=0
for i in range(len(s)-1):
  if s[i]=='A':
    list[i]+=1
  elif s[i]=='C':
    list[i]+=2
for i in range(t[1]):
  a=0
  for j in range(u[i][0]-1,u[i][1]-1):
    if list[j]==1:
      if list[j+1]==2:
        a+=1
  print(a)

Submission status: Time Limit Exceeded

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

for start, end in ranges:
    print(s.count('AC', start-1, end))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
i = 0
while i < n:
    if s[i] == "A":
        i += 1
        if s[i] == "C":
            ac[i-1] = 1
            ac[i] = 1
            i += 1
        else: i += 1
    else: i += 1
for p in lr:
    l, r = p[0] - 1, p[1] - 1
    a = sum(ac[l:r]) + ac[r]
    if s[l] == "C" and ac[l] == 1: a -= 1
    if s[r] == "A" and ac[r] == 1: a -= 1
    print(int(a/2))

Submission status: Time Limit Exceeded

Solution code:
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
i = 0
while i < n:
    if s[i] == "A":
        i += 1
        if s[i] == "C":
            ac[i-1] = 1
            ac[i] = 1
        else: i += 1
    else: i += 1
for p in lr:
    l, r = p[0] - 1, p[1] - 1
    a = sum(ac[l:r]) + ac[r]
    if s[l] == "C" and ac[l] == 1: a -= 1
    if s[r] == "A" and ac[r] == 1: a -= 1
    print(int(a/2))

Submission status: Time Limit Exceeded

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

for _ in range(Q):
    count = 0
    start, end = map(int, input().split())
    for i in range(start - 1, end - 1):
        if S[i] + S[i + 1] == "AC":
            count += 1

    print(count)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = list(input())
LR = [list(map(int,input().split())) for _ in range(Q)]
lis = []
s = [0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        s[i] = 1
L = [0]*(N+1)

R = [0]*N

tmp = 0
for i in range(0,N):
    if s[i] == 1:
        tmp += 1
    L[i+1] += tmp
tmp = 0
for i in range(N-2,-2,-1):
    if s[i] == 1:
        tmp += 1
    R[i+1] += tmp
R += [0]
for i in range(Q):
    ans = sum(s)-L[LR[i][0]-1]-R[LR[i][1]]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = list(input())
LR = [list(map(int,input().split())) for _ in range(Q)]
lis = []
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        lis.append(i)
for i in range(Q):
    ans = 0
    for j in lis:
        if LR[i][0]-1 <= j and j+1 <= LR[i][1]-1:
            ans += 1
        if LR[i][1]-1<j+1:
            break
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re

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

answer = []
pattern = re.compile(r'AC')

length = len

for _ in range(q):
    l, r = map(int, input().split()) 
    answer.append(length(re.findall(pattern, s[l-1:r])))

for ans in answer:
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
ac_list = [0]*n

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

for _ 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()
ac_list = [0]*n

for i in range(n-1):
  if s[i:i+2]=='AC':
    ac_list[i] += 1
  else:
    ac_list[i] += 0

for _ 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()
ac_list = []

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

for _ 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()
s_list = []

for _ in range(q):
  l, r = map(int, input().split())
  s_list.append(s[l-1:r])
  
for s in s_list:
  print(s.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())
  sub_s = s[l-1:r]
  print(sub_s.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())
  sub_s = s[l-1:r]
  print(sum([sub_s[i:i+2]=='AC' for i in range(r-l)]))

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
L=[0]*N
A=0
for i in range(len(S)-1) :
    if A == 0 :
        if S[i:i+2] == "AC":
            L[i] += 1
            A=1
    else:
        A=0

for i in range(Q):
    T,B=map(int,input().split())
    ans=sum(L[T-1:B-1])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
L=[]
A=0
for i in range(len(S)-1) :
    if A == 0 :
        if S[i] == "A":
            if S[i+1] == "C":
                L.append(i)
                A=1
    else:
        A=0

for i in range(Q):
    T,B=map(int,input().split())
    ans=0
    for n in range(len(L)):
        if L[n] >= T-1 and L[n]+1 <= B-1:
            ans += 1
        elif B <= L[n] :
            break
                
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
L=[]
A=0
for i in range(len(S)-1) :
    if A == 0 :
        if S[i] + S[i+1] == "AC":
            L.append(i)
            A=1
    else:
        A=0

for i in range(Q):
    T,B=map(int,input().split())
    ans=0
    for n in range(len(L)):
        if L[n] >= T-1 and L[n]+1 <= B-1:
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
for i in range(Q):
    ans=0
    T,B=map(int,input().split())
    for n in range(B - T) :
        if S[T+n-1]+S[T+n] == "AC":
            ans+=1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import pdb
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,Q = map(int, input().split())
    S = input().rstrip()
    ans = [0]*Q
    for q in range(Q):
        l,r = map(int, input().split())
        l -= 1
        r -= 1
        qua = (r+l)//4
        mid1 = qua+1
        mid2 = qua*2+1
        mid3 = qua*3+1
        cnt = 0
        for i in range(l,mid1):
            if S[i:i+2] == 'AC': cnt += 1
        for i in range(mid1,mid2):
            if S[i:i+2] == 'AC': cnt += 1
        for i in range(mid2,mid3):
            if S[i:i+2] == 'AC': cnt += 1
        for i in range(mid3,r):
            if S[i:i+2] == 'AC': cnt += 1
        print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import pdb
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,Q = map(int, input().split())
    S = input().rstrip()
    ans = [0]*Q
    for q in range(Q):
        l,r = map(int, input().split())
        l -= 1
        r -= 1
        mid = (r+l)//2+1
        cnt = 0
        for i in range(l,mid):
            if S[i:i+2] == 'AC': cnt += 1
        for i in range(mid,r):
            if S[i:i+2] == 'AC': cnt += 1
        print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import pdb
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,Q = map(int, input().split())
    S = input().rstrip()
    ans = [0]*Q
    for q in range(Q):
        l,r = map(int, input().split())
        cnt = 0
        for i in range(l-1,r-1):
            if S[i:i+2] == 'AC': cnt += 1
        print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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