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()
question = []
for i in range(Q):
  question.append(list(map(int, input().split())))

# Sの中で、ACという部分文字列が含まれるときの（Aの）index
index = []
for i in range(N-1):
  if S[i]+S[i+1] == "AC":
    index.append(i)

for i, q in enumerate(question):
  ans = 0
  for j in range(len(index)):
    if index[j] >= q[0]-1 and index[j]+1 <= q[1]-1:
      ans +=1
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
num = list(map(int,input().split()))
string = input()
s_key=[]
count=[]
for i in range(num[1]):
    s_key.append(list(map(int,input().split())))
for i in range(num[1]):
    count.append(0)
    for j in range(s_key[i][0]-1,s_key[i][1]-1):
        if (string[j]=='A' and string [j+1]=='C'):
            count[i]+=1
            j+=1
for k in range(num[1]):
    print(count[k])

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int,input().split())
a=input()
c=[0]*len(a)
for i in range(len(a)-1):
    if (a[i]+a[i+1])=="AC":c[i]=1
for i in range(b):
    d,e=map(int,input().split())
    print(c[d-1:e-1].count(1))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, Q = map(int, input().split())
# print(N, Q)
S = input()
AC_array = np.array([
    1 if (S[i] == "A" and S[i + 1] == "C") else 0 for i in range(N - 1)
])
lr_array = [list(map(int, input().split())) for i in range(Q)]
# print(lr_array)
# print(AC_array)
ans = ""
for lr in lr_array:
    ans += str(np.sum(AC_array[lr[0]-1:lr[1]-1])) + "\n"
print(ans[:-1])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, Q = map(int, input().split())
# print(N, Q)
S = input()
AC_array = np.array([
    1 if (S[i] == "A" and S[i + 1] == "C") else 0 for i in range(N - 1)
])
lr_array = [list(map(int, input().split())) for i in range(Q)]
# print(lr_array)
# print(AC_array)
for lr in lr_array:
    print(np.sum(AC_array[lr[0]-1:lr[1]-1]))

Submission status: Time Limit Exceeded

Solution code:
N,Q=(int(i) for i in input().split())
x=input()
a=[]

j=0
s=[]
while (j<N-1):
  if (x[j]=="A") and (x[j+1]=="C"):
    s.append(1)
    s.append(0)
    j+=1
  else:s.append(0)
  j+=1
for i in range(0,Q):
  a.append([int(j) for j in input().split()])
  p=s[a[i][0]-1:a[i][1]-1]
  print(sum(p))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,Q=(int(i) for i in input().split())
x=input()
a=[]

j=0
s=[]
while (j<len(x)-1):
  if (x[j]=="A"):
    if (x[j+1]=="C"):
      s.append(1)
      s.append(0)
      j+=1
    else:s.append(0)
  else:s.append(0)
  j+=1
for i in range(0,Q):
  a.append([int(j) for j in input().split()])
  p=np.array(s[a[i][0]-1:a[i][1]-1])
  print(np.sum(p))

Submission status: Time Limit Exceeded

Solution code:
N,Q=(int(i) for i in input().split())
x=input()
a=[]

j=0
s=[]
while (j<len(x)-1):
  if (x[j]=="A"):
    if (x[j+1]=="C"):
      s.append(1)
      s.append(0)
      j+=1
    else:s.append(0)
  else:s.append(0)
  j+=1
for i in range(0,Q):
  a.append([int(j) for j in input().split()])
  p=s[a[i][0]-1:a[i][1]-1]
  print(sum(p))

Submission status: Time Limit Exceeded

Solution code:
N,Q=(int(i) for i in input().split())
x=input()
a=[]

j=0
s=[]
while (j<len(x)-1):
  if (x[j]=="A"):
    if (x[j+1]=="C"):
      s.append(1)
      s.append(0)
      j+=1
    else:s.append(0)
  else:s.append(0)
  j+=1
for i in range(0,Q):
  a.append([int(j) for j in input().split()])
  p=s[a[i][0]-1:a[i][1]-1]
  answer=0
  for j in range(len(p)):
    if p[j]==1:answer+=1
  print(answer)

Submission status: Time Limit Exceeded

Solution code:
N,Q=(int(i) for i in input().split())
x=input()
a=[]

j=0
s=[]
while (j<len(x)-1):
  if (x[j]=="A"):
    if (x[j+1]=="C"):
      s.append(j+1)
      j+=1
  j+=1
for i in range(0,Q):
  if s==[]:
    print(0)
    continue
  a.append([int(j) for j in input().split()])
  answer=0
  j=0
  while s[j]<a[i][0]:
    j+=1
    if len(s)<=j:break
  k=0
  while s[k]<a[i][1]:
    k+=1
    if len(s)<=k:break
  print(k-j)

Submission status: Time Limit Exceeded

Solution code:
N,Q=(int(i) for i in input().split())
x=input()
a=[]
for i in range(0,Q):
  a.append([int(j) for j in input().split()])
  answer=0
  l=x[a[i][0]-1:a[i][1]]
  j=0
  while (j<len(l)-1):
    if (l[j]=="A"):
      if (l[j+1]=="C"):
        answer+=1
        j+=1
    j+=1
  print(answer)

Submission status: Time Limit Exceeded

Solution code:
N,Q=(int(i) for i in input().split())
x=input()
a=[]
for i in range(0,Q):
  a.append([int(j) for j in input().split()])
  answer=0
  l=x[a[i][0]-1:a[i][1]]
  for j in range(0,len(l)-1):
    if (l[j]=="A"):
      if (l[j+1]=="C"):
        answer+=1
  print(answer)

Submission status: Time Limit Exceeded

Solution code:
N,Q=(int(i) for i in input().split())
x=input()
a=[]
for i in range(0,Q):
  a.append([int(j) for j in input().split()])


for i in range(0,Q):
  answer=0
  l=x[a[i][0]-1:a[i][1]]
  for j in range(0,len(l)-1):
    if (l[j]=="A"):
      if (l[j+1]=="C"):
        answer+=1
  print(answer)

Submission status: Time Limit Exceeded

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

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

dp = [[None for i in range(N)] for j in range(N)]
for i in range(N-1):
    if S[i:i+2] == 'AC':
        dp[i][i+1] = 1
    else:
        dp[i][i+1] = 0

def count(l, r):
    if dp[l][r] != None:
        return dp[l][r]
    else:
        if S[r-1:r+1] == 'AC':
            num = count(l, r-1) + 1
            dp[l][r] = num
            return num
        else:
            dp[l][r] = count(l, r-1)
            return count(l, r-1)

for i in range(Q):
    l, r = input_list[i]
    num = count(l-1, r-1)
    print(num)

Submission status: Time Limit Exceeded

Solution code:
import sys  
from itertools import accumulate
input = sys.stdin.readline  

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

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

s = list(S)
ac = [0] * N

for i in range(N-1):
    if s[i] == 'A':
        if s[i+1] == 'C':
            s[i] = "AC"
            ac[i] += 1

#ans = list(accumulate(ac))
#ans = [0] + ans


#for i in range(Q):
#    print(ans[r[i]-1]- ans[l[i]-1])
ac = [0] + ac
for i in range(Q):
    print(sum(ac[l[i]:r[i]]))

Submission status: Time Limit Exceeded

Solution code:
n, q = [int(i) for i in input().split()]
s = input()
l = [0] * q
r = [0] * q
ans = ""
table = [1 if s[i:i+2] == "AC" else 0 for i in range(n)]   
for i in range(q):
  l[i], r[i] = [int(j) for j in input().split()]
  ans = ans+str(sum(table[l[i]-1:r[i]-1]))+"\n"
print(ans)

Submission status: Time Limit Exceeded

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

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

S.split("AC")

s = list(S)

for k in range(Q):
    z = "".join(s[l[k]-1:r[k]])
    print(len(z.split("AC"))-1)

Submission status: Time Limit Exceeded

Solution code:

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

s = list(S)

for k in range(Q):
    z = "".join(s[l[k]-1:r[k]])
    print(len(z.split("AC"))-1)

Submission status: Time Limit Exceeded

Solution code:
n, q = [int(i) for i in input().split()]
s = input()
l = [0] * q
r = [0] * q
ans = ""
for i in range(q):
  l[i], r[i] = [int(j) for j in input().split()]
  t = s[l[i]-1:r[i]]
  cnt = 0
  for k in range(len(t)-1):
    if t[k:k+2] == "AC":
      cnt += 1
      k += 1
  ans = ans+str(cnt)+"\n"
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
l = [0]*Q
r = [0]*Q
for i in range(Q):
    l[i], r[i] = list(map(int, input().split()))

s = list(S)
ac = []

for i in range(N-1):
    if s[i] == 'A':
        if s[i+1] == 'C':
            s[i] = "AC"
            ac.append(i)



for i in range(Q):
    cnt = 0
    for k in ac:
        if k< r[i]-1 and k >= l[i]-1:
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

"""
import random
base_list = ['A', 'T', 'C', 'G']
S = ''
N = int(1e5)
Q = 1
A = [[100, 900]]
for i in range(N):
  S += random.choice(base_list)
"""

L_cnt = np.zeros(N-1)
L_cnt[0] = 0
L_str = S[0]
R_cnt = np.zeros(N-1)
R_cnt[0] = 0
R_str = S[N-1]

for i in range(N-2):
  #L_str = L_str + S[i+1]
  #L_cnt[i+1] = L_cnt[i] + (L_str[-2:] == 'AC')
  #R_str = S[N-2-i] + R_str
  #R_cnt[i+1] = R_cnt[i] + (R_str[:2] == 'AC')
  #print(i, L_str)
  #print(i, R_str)
  #L_str = S[i] + S[i+1]
  #L_cnt[i+1] = L_cnt[i] + (L_str == 'AC')
  #R_str = S[N-2-i] + S[N-1-i]
  #R_cnt[i+1] = R_cnt[i] + (R_str == 'AC')
  L_str = S[i] + S[i+1]
  L_cnt[i+1] = (L_str == 'AC')
  R_str = S[N-2-i] + S[N-1-i]
  R_cnt[i+1] = (R_str == 'AC')

#print(L_cnt)
#print(R_cnt)
  
n_whole = S.count('AC')
for i in range(Q):
  #ans = n_whole - (L_cnt[A[i][0]-1] + R_cnt[N-A[i][1]])
  ans = n_whole - (sum(L_cnt[:A[i][0]]) + sum(R_cnt[:N-A[i][1]+1]))
  print(int(ans))
  




"""
## 題意を愚直に表したもの（~10^10の計算量）
for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)
"""

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

L_cnt = np.zeros(N-1)
L_cnt[0] = 0
L_str = S[0]
R_cnt = np.zeros(N-1)
R_cnt[0] = 0
R_str = S[N-1]

for i in range(N-2):
  L_str = L_str + S[i+1]
  L_cnt[i+1] = L_cnt[i] + (L_str[-2:] == 'AC')
  R_str = S[N-2-i] + R_str
  R_cnt[i+1] = R_cnt[i] + (R_str[:2] == 'AC')
  #print(i, L_str)
  #print(i, R_str)

#print(L_cnt)
#print(R_cnt)
  
n_whole = S.count('AC')
for i in range(Q):
  #ans = n_whole - (L_cnt[A[i][0]-1] + R_cnt[N-A[i][1]])
  A = list(map(int,input().split()))
  ans = n_whole - (L_cnt[A[0]-1] + R_cnt[N-A[1]])
  print(int(ans))
  




"""
## 題意を愚直に表したもの（~10^10の計算量）
for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)
"""

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

L_cnt = np.zeros(N-1)
L_cnt[0] = 0
L_str = S[0]
R_cnt = np.zeros(N-1)
R_cnt[0] = 0
R_str = S[N-1]

for i in range(N-2):
  L_str = L_str + S[i+1]
  L_cnt[i+1] = L_cnt[i] + (L_str[-2:] == 'AC')
  R_str = S[N-2-i] + R_str
  R_cnt[i+1] = R_cnt[i] + (R_str[:2] == 'AC')
  #print(i, L_str)
  #print(i, R_str)

#print(L_cnt)
#print(R_cnt)
  
n_whole = S.count('AC')
for i in range(Q):
  ans = n_whole - (L_cnt[A[i][0]-1] + R_cnt[N-A[i][1]])
  print(int(ans))
  




"""
## 題意を愚直に表したもの（~10^10の計算量）
for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)
"""

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):
    lr_list[i] = list(map(int, input().split()))

a_list = []
for i in range(len(S)):
    if S[i] == "A" and i != len(S) - 1:
        if S[i + 1] == "C":
            a_list.append(i)
counter = 0
for i in range(Q):
    for j in range(len(a_list)):
        if lr_list[i][0] - 1 <= a_list[j] and a_list[j]+1 <= lr_list[i][1]-1:
            counter += 1
    print(counter)
    counter=0

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
ans=''
for i in range(q):
    t = list(map(int, input().split()))
    ans += str(len(s[t[0]-1:t[1]].split('AC'))-1)+'\n'
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
data = []
for i in range(q):
    data.append(list(map(int, input().split())))
for i in data:
    #print(s[i[0]-1:i[1]])
    tmp = s[i[0]-1:i[1]].split('AC')
    print(len(tmp)-1)

Submission status: Time Limit Exceeded

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

for i in lr:
    front = i.split()[0]
    end = i.split()[1]

    count = str(''.join(S[int(front)-1:int(end)])).count('AC')
    
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import re
n,q=map(int,input().split())
s=input()
a=[0]*n
b=[0]*n
i=[p.span()[0]for p in re.finditer('(AC){1,1}',s)]
c=0
for m in range(n):
  if c>=len(i):
    if m<n-1:a[m+1]=a[m]
    b[m]=b[m-1]
    continue
  if m==i[c]:
    if m>0:
      if m<n-1:a[m+1]=a[m]+1
      b[m]=b[m-1]+1
    else:
      a[m]=0
      a[m+1]=1
      b[m]+=1
    c+=1
  else:
    a[m+1]=a[m]
    b[m]=b[m-1]
for _ in range(q):
  l,r=map(int,input().split())
  print(a[r-1]-max(b[:l-1]+[0]))

Submission status: Time Limit Exceeded

Solution code:
import re
n,q=map(int,input().split())
s=input()
i=[p.span()[0] for p in re.finditer('(AC){1,1}',s)]
for _ in range(q):
  v=0
  l,r=map(int,input().split())
  for c in i:
    v+= l-1<=c and c+1<=r-1
  print(v)

Submission status: Time Limit Exceeded

Solution code:
import re
n,q=map(int,input().split())
s=input()
i=[p.span()[0] for p in re.finditer('(AC){1,1}',s)]
for _ in range(q):
  v=0
  l,r=map(int,input().split())
  a=list(range(l-1,r))
  for c in i:
    v+= c in a and c+1 in a
  print(v)

Submission status: Time Limit Exceeded

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

for i in range(Q):
    A.append([int(j) for j in input().split()])

for i in range(Q):
    start = A[i][0] - 1
    end = A[i][1]
    print(S[start:end].count('AC'))

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())
  b=s[(l-1):r]
  m=[p.group(0)for p in re.finditer('(AC){1,1}',b)]
  print(len(m))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
l = [0]*Q
r = [0]*Q
for i in range(Q):
    l[i], r[i] = list(map(int, input().split()))

s = list(S)

for i in range(N-1):
    if s[i] == 'A':
        if s[i+1] == 'C':
            s[i] = "AC"

d = np.array(s)
tf = np.where(d=="AC", True, False)


for i in range(Q):
    print(np.sum(tf[l[i]-1:r[i]-1]))

Submission status: Time Limit Exceeded

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

zeroone=[]
for n in range(N-1):
    zeroone.append(S[n]+S[n+1]=='AC')

for q in range(Q):
    l,r=map(int,input().split())
    ct=sum(zo for i,zo in enumerate(zeroone) if (i>=l-1) & (i<=r-2))
    print(ct)

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=str(input())
for q in range(Q):
    l,r=map(int,input().split())
    Sc=S[l-1:r]
    slist=[]
    s=0
    ct=0
    while s>-1:
        s=Sc.find('AC')
        if s>-1:
            Sc=Sc[(s+2):]
            ct=ct+1
    print(ct)

Submission status: Time Limit Exceeded

Solution code:
import copy
N,Q=map(int,input().split())
S=str(input())
Sc=copy.copy(S)
s=0
slist=[]
while s>-1:
    s=Sc.find('AC')
    if s>-1:
        Sc=Sc[(s+2):]
        slist.append(s+len(slist)*2)
for q in range(Q):
    l,r=map(int,input().split())
    print(sum( (s+1>=l) & (s+2<=r) for s in slist))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import numpy as np
import math

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

for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
R = [list(map(int, input().split())) for i in range(Q)]
ans = []
for i in range(Q):
    x = R[i][0]-1
    y = R[i][1]
    a=S[x:y].count("AC")
    ans.append(a)

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
is_AC_list = [None] * (N - 1)

for i in range(N - 1):
  is_AC_list[i] = S[i:i + 2].count('AC')

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
L = [None] * Q
R = [None] * 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 = [int(i) for i in input().split()]
s = input()
l =[]
r =[]
for i in range(q):
    l1, r1 = [int(i) for i in input().split()]
    l.append(l1)
    r.append(r1)

memo = []
for i in range(len(s)-1):
    if s[i]=="A" and s[i+1]=="C":
        memo.append(i)

#print(memo)

for i in range(q):
    cnt = 0
    for j in memo:
        if l[i] <= j+1 <= r[i]-1:
            cnt+=1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n, q = [int(i) for i in input().split()]
s = input()
l =[]
r =[]
for i in range(q):
    l1, r1 = [int(i) for i in input().split()]
    l.append(l1)
    r.append(r1)

memo = []
for i in range(len(s)-1):
    if s[i]=="A" and s[i+1]=="C":
        memo.append(i)

#print(memo)

for i in range(q):
    cnt = 0
    for j in memo:
        if l[i] <= j+1 and j+2 <= r[i]:
            cnt+=1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n, q = [int(i) for i in input().split()]
s = input()
l =[]
r =[]
for i in range(q):
    l1, r1 = [int(i) for i in input().split()]
    l.append(l1)
    r.append(r1)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
S = 'Z'+input()
L = []
res = 0
for i in range(0,N+1):
    if S[i] == 'C' and S[i-1] == 'A':
        res += 1
    L.append(res)
for i in range(Q):
    l,r = map(int,input().split())
    print(max(L[l:r+1])-min(L[l:r+1]))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = 'Z'+input()
L = []
res = 0
for i in range(0,N+1):
    if S[i] == 'C' and S[i-1] == 'A':
        res += 1
    L.append(res)
for i in range(Q):
    l,r = map(int,input().split())
    print(max(L[l:r+1])-min(L[l:r+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())
    T = S[l-1:r]
    ans = 0
    for j in range(len(T)-1):
        if T[j] == 'A' and T[j+1] == 'C':
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
n,q = map(int, input().split())
s = input()
m = list(re.finditer("AC",s))
for i in range(q):
    a=0
    loc = [int(s) for s in input().split()]
    for m_ in m:
        a+=1 if (m_.start()+1>=loc[0])&(m_.end()<=loc[1]) else 0
        if m_.start()+1>loc[1]:break
    print(a)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
place = []
for s in range(N - 1):
	if S[s] == 'A':
		if S[s + 1] == 'C':
			place.append(s)
PlaceCount = len(place)
for q in range(Q):
	num = 0
	l,r = map(int,input().split())
	l -= 1
	r -= 2
	for i in range(PlaceCount):
		if l <= place[i] <= r:
			num += 1
	print(num)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
for i in range(q):
    l, r = map(int, input().split())
    
    ans = s[l-1:r].count('AC')
    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())
  j = l-1
  AC = 0
  while j < r-1:
    if s[j] == "A" and s[j+1] == "C":
      AC += 1
      j += 1
    j += 1
  print(AC)

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())
ct=0
max=0
for i in range(Q):
  T = S[l[i]-1:r[i]]
  #print(T)
  for j in range(len(T)-1):
    if T[j]=='A' and T[j+1]=='C':
      ct+=1
  print(ct)
  ct=0

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = str(input())
l = []
for _ in range(q):
    l0, l1 = map(int, input().split())
    cnt = 0
    if 'AC' not in s[l0-1:l1]:
        l.append(0)
    else:
        cnt = sum(s[l0-1+i:l0+1+i] == 'AC' for i in range(l1-l0))
        l.append(cnt)
            
for x in l:
    print(x)

Submission status: Time Limit Exceeded

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

for l0, l1 in l:
    cnt = 0
    if 'AC' not in s[l0-1:l1]:
        print(0)
    else:
        cnt = sum(s[l0-1+i:l0+1+i] == 'AC' for i in range(l1-l0))
        print(cnt)

Submission status: Time Limit Exceeded

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

for l0, l1 in l:
    cnt = 0
    if 'AC' not in s[l0-1:l1]:
        print(0)
    else:
        for i in range(l1-l0):
            if s[l0-1+i:l0+1+i] == 'AC':
                cnt += 1
        print(cnt)

Submission status: Time Limit Exceeded

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

ans = []
for l0, l1 in l:
    cnt = 0
    if 'AC' not in s[l0-1:l1]:
        ans.append(0)
    else:
        for i in range(l1-l0):
            if s[l0-1+i:l0+1+i] == 'AC':
                cnt += 1
        ans.append(cnt)

for x in ans:
    print(int(x))

Submission status: Time Limit Exceeded

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

N,Q = [int(x) for x in input().split()]
S = list(input())
lrlist =[]
for _ in range(Q):
    l,r = [int(x) for x in input().split()]
    lrlist.append((l,r))

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

for _ in range (Q):
    l = lrlist[_][0]
    r = lrlist[_][1]
    ans = sum(sumls[l-1:r-1])
    print(ans)

Submission status: Time Limit Exceeded

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

N,Q = [int(x) for x in input().split()]
S = list(input())
lrlist =[]
for _ in range(Q):
    l,r = [int(x) for x in input().split()]
    lrlist.append((l,r))
countls=[]
for x in lrlist:
    count = 0
    Spart = S[x[0]-1:x[1]]
    for i in range(len(Spart)-1):
        if Spart[i] =='A' and Spart[i+1] =='C':
            count+= 1
    countls.append(count)

for _ in range(Q):
    print(countls[_])

Submission status: Time Limit Exceeded

Solution code:
import re
N,Q = map(int,input().split())
S = input()
pattern = re.compile(r'AC')

for i in range(Q):
    l,r = map(int,input().split())
    total = 0
    flag = 0
    for j in S[l-1:r]:
        if j == 'A':
            flag = 1
        elif j == 'C' and flag == 1:
            total += 1
        else:
            flag = 0
    
    print(total)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(Q):
    start, end = q_list[i][0], q_list[i][1]
    partial_str = S[start-1:end]
    count = 0
    for j in range(end-start):
        if partial_str[j] == 'A' and partial_str[j+1] == 'C':
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
# C - GeT AC
n, q = list(map(int, input().split()))
s = input()
q_range = [ list(map(int, input().split())) for i in range(q)]
for i in q_range:
	s_ = s[i[0]-1:i[1]]
	r= 0
	for i in range(len(s_)-1):
		if s_[i] == "A" and s_[i+1] == "C":
			r += 1
	print(r)

Submission status: Time Limit Exceeded

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

for i in range(Q):
    for j in range(l[i], r[i]):
        if S[j - 1] + S[j] == "AC":
            counts[i] += 1

for i in counts:
    print(i)

Submission status: Time Limit Exceeded

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

for i in range(Q):
    s = ""
    for j in range(l[i], r[i]):
        s += S[j]
        if S[j - 1] + S[j] == "AC":
            counts[i] += 1

for i in counts:
    print(i)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
nq = list(map(int,input().split()))
s = input()
while nq[1] > 0:
    nq[1] -= 1
    lr = list(map(int,input().split()))
    print( s[lr[0]-1:lr[1]].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
import re
nq = list(map(int,input().split()))
s = input()
while nq[1] > 0:
    nq[1] -= 1
    lr = list(map(int,input().split()))
    print( re.subn(r'(AC)','',s[lr[0]-1:lr[1]])[1])

Submission status: Time Limit Exceeded

Solution code:
#122 C

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = str(input())
i = []
j = 1
while j <= (N + 1):
    part_S = S[0:j]
    i = i + [part_S.count('AC')]
    j += 1
k = 1
#print (i)
while k <= Q:
    l, r = map(int, input().split())
    ans = i[r-1]-i[l-1]
    k += 1
    print (ans)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
s = input()
i = 0
while i < q:
  l, r = map(int, input().split())
  print(s[l-1:r].count('AC'))
  i += 1

Submission status: Time Limit Exceeded

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

sliceS = ''
charSliceS = []

i = 0

while i < q:
  l, r = map(int, input().split())
  sliceS = s[l-1:r]
  count = sliceS.count('AC')
  print(count)
  i += 1

Submission status: Time Limit Exceeded

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

sliceS = ''
charSliceS = []

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

Submission status: Time Limit Exceeded

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

sliceS = ''
charSliceS = []

for i in range(q):
  l, r = map(int, input().split())
  sliceS = s[l-1:r]
  charSliceS = list(sliceS)
  count = 0
  for j in range(len(charSliceS)):
    if charSliceS[j] == 'A' and j != len(charSliceS) -1:
      if charSliceS[j+1] == 'C':
        count += 1
  
  print(count)