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()
li=[list(map(int,input().split())) for _ in range(Q)]
t=0
li2=[]
for i,j in li:
    if "A" in S[i-1:j]:
      s=S[i-1:j].count("AC")
      li2.append(s)
for l in li2:
  print(l)

Submission status: Time Limit Exceeded

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

for i in range(Q):
  a, b = map(int, input().split())
  m = S[a-1:b]
  ans = m.count("AC")
  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 i in range(Q)]
#print(lr)

for i in range(Q):
  m = S[lr[i][0]-1:lr[i][1]]
  ans = m.count("AC")
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#ABC122C
import sys
import copy
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
q=hoge[1]

s = input()

l=[]
r=[]
sum=0
for i in range(0,q):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	for j in range(hoge[0]-1,hoge[1]-1):
		#print(j)
		#print(hoge[0]-1)
		#print(hoge[1])
		if(s[j]=="A")and(s[j+1]=="C"):
			sum+=1
	print(sum)
	sum=0

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#ABC122C
import sys
import copy
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
q=hoge[1]

s = input()

l=[]
r=[]
for i in range(0,q):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	l.append(hoge[0])
	r.append(hoge[1])

#print(s)

for i in range(0,q):
#	print(l[i])
#	print(r[i])
	tmp=copy.deepcopy(s[l[i]-1:r[i]])
#	print(s[3:7])
#	print(s[l[i]:r[i]])

#	print(tmp)
	
	lentmp = len(tmp)
	sum = 0
	for j in range(0,lentmp-1):
		if(tmp[j]=="A")and(tmp[j+1]=="C"):
			sum+=1
	print(sum)

Submission status: Time Limit Exceeded

Solution code:
# GET AX
N, Q = map(int, input().split())
S = str(input())
lr = [list(map(int, input().split())) for _ in range(Q)]

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
def main(): #startline-------------------------------------------
    N,Q = map(int,input().split())
    S = input()
    LR = [list(map(int,input().split())) for i in range(Q)]
    def account(s):
        a = ""
        cnt = 0
        for i in s:
            if i == "A":
                if a == "":
                    a += "A"
                else:
                    pass
            elif i == "C":
                if a == "A":
                    a = ""
                    cnt += 1
            else:
                a = ""
        return cnt
    for i in range(Q):
        print(account(S[LR[i][0]-1:LR[i][1]]))

if __name__ == "__main__":
    main() #endline===============================================
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

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())
  l = l-1
  r = r-1
  temp = s[l:r+1]
  c = 0
  for i in range(len(temp)-1):
    if temp[i] == "A" and temp[i+1] == "C":
      c += 1

  print(c)

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

idx = [s[i:i+2] == "AC" for i in range(n-1)]
idx2 = [sum(idx[:i]) for i in range(n)]

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

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

idx = [s[i:i+2] == "AC" for i in range(n-1)]
idx2 = [sum(idx[:i]) for i in range(n)]

for i in range(q):
    print(idx2[lr[i][1]-1]-idx2[lr[i][0]-1])

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

idx = [s[i:i+2] == "AC" for i in range(n-1)]

for i in range(q):
    print(sum(idx[lr[i][0]-1:lr[i][1]-1]))

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

idx = [0] * (n-1)

for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        idx[i] = 1

for i in range(q):
    print(sum(idx[lr[i][0]-1:lr[i][1]-1]))

Submission status: Time Limit Exceeded

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

ACindex = []
index = 0
while (True):
    index = S.find("AC", index)
    if index == -1:
        break
    ACindex.append(index)
    index += 2
# print(ACindex)


for i in range(Q):
    L, R = map(int, input().split())
    L -= 1
    R -= 1
    count = 0
    for index in ACindex:
        if L <= index and index + 1 <= R:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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

for i in range(q):
    l, r = lr[i]
    ans = s[l-1:r].count('AC')
    print(ans)

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

S = input()

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

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

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
s = input()
tmp=[0]*n
for i in range(n):
  if 'AC' == s[i:i+2]:
    tmp[i+1]=1
for i in range(q):
  l,r = map(int,input().split())
  print(sum(tmp[l:r]))

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
s = input()
tmp=[]
l,cnt=0,0
r=1
while r<=n:
  if 'AC' in s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    r+=1

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

Submission status: Time Limit Exceeded

Solution code:
import sys,re
n,q = map(int, input().split())
s = input()
tmp=[]
l,cnt=0,0
s=s.replace('AC','01')
s=list(map(int,list(re.sub('[a-zA-Z]','0',s))))
for i in range(q):
  l,r = map(int,input().split())
  print(sum(s[l:r]))

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
s = input()
tmp=[]
l,cnt=0,0
for r in range(1,n+1):
  if 'AC' in s[l:r]:
    cnt+=1
    l=r
  tmp.append(cnt)

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

Submission status: Time Limit Exceeded

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

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)]
tmp = []
for i in range(1,n+1):
  tmp.append(s[:i].count('AC'))

for i in range(q):
  print(tmp[lr[i][1]-1]-tmp[lr[i][0]-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
s = input()
l = [list(map(int, input().split())) for _ in range(q)]
ind = []
for i in range(len(s)-1):
    if s[i] == "A" and s[i+1] == "C":
        ind.append(i+1)

for ll in l:
    print(len([j for j in ind if ll[0] <= j < ll[1]]))

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):
  tmp = [int(j) for j in input().split()]
  l.append(tmp[0])
  r.append(tmp[1])
  
search = [0]
for i in range(1,n):
  if s[i-1:i+1] == "AC":
    search.append(1)
  else:
    search.append(0)

for i in range(q):
  ans = sum(search[l[i]-1:r[i]])
  if search[l[i]-1] == 1:
    ans -= 1
  print(ans)

Submission status: Time Limit Exceeded

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

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

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

ac = [0]*n

for i in range(n-1):
  if s[i:i+2]=='AC':  
    ac[i]=1
    
for l,r in lr:
  print(sum(ac[l-1:r-1]))

Submission status: Time Limit Exceeded

Solution code:
print("".join([ [ "{0}\n".format(NQ_S[1][0][LR[0]-1:LR[1]].count('AC')) for LR in [list(map(int, input().split())) for i in range(NQ_S[0][1])] ] for NQ_S in [[[int(x) for x in input().split()],[str(x) for x in input().split()]]] ][0])[:-1])

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
li = [i for i in s]
pos = []
for i in range(len(li)-1):
    if li[i]== "A" and li[i+1] == "C":
        pos.append(i)
for i in range(q):
    l, r = map(int, input().split())
    pos_copy=pos.copy()
    pos_copy+=[r-1, l-1]
    pos_copy.sort()
    print(pos_copy.index(r-1)  - pos_copy.index(l-1) - 1)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
li = [i for i in s]
pos = []
for i in range(len(li)-1):
    if li[i ]== "A" and li[i+1] == "C":
        pos.append(i)


for i in range(q):
    l, r = map(int, input().split())
    pos_copy=pos.copy()
    pos_copy.append(l-1)
    pos_copy.append(r-1)
    pos_copy.sort()
    print(pos_copy.index(r-1)  - pos_copy.index(l-1) - 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 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()
for i in range(Q):
  l,r=map(int,input().split())
  AC=S[l-1:r]
  print(AC.count("AC") )

Submission status: Time Limit Exceeded

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

Temp = [0 for i in range(N)]
num = 0
while num <= N-2:
    if S[num] == "A" and S[num+1] == "C":
        Temp[num] = 1
        Temp[num+1] = 2
    num += 1

for j in range(Q):
    Temp2 = Temp[L[j][0]-1:L[j][1]]
    c = sum(Temp2)
    if c%3 == 0:
        if Temp2[0] != 2:
            print(int(c/3))
        else:
            print(int(c/3-1))
    elif c%3 == 1:
        print(int((c-1)/3))
    else:
        print(int((c-2)/3))

Submission status: Time Limit Exceeded

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

def AC(S):
    num = 0
    c = 0
    while num <= len(S)-2:
        if S[num] == "A" and S[num+1] == "C":
            c += 1
        num += 1
    return c

ANS = []
for j in range(Q):
    Temp = S[L[j][0]-1:L[j][1]]
    print(AC(Temp))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
v=[list(map(int,input().split())) for i in range(q)]
r=[0]*n
count=0
for i in range(n-1):
    if s[i]=='A':
        if s[i+1]=='C':
            r[i+1]=1
        else:
            pass
for i in range(q):
    print(sum(r[:v[i][1]])-sum(r[:v[i][0]]))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
v=[list(map(int,input().split())) for i in range(q)]
count=0
for i in range(q):
    for j in range(v[i][0]-1,v[i][1]-1):
        if s[j]=='A':
            if s[j+1]=='C':
                count+=1
            else:
                pass
    print(count)
    count=0

Submission status: Time Limit Exceeded

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

c = []
for j in range(n) :
  if s[j:j+2] == 'AC' :
    c.append(j)

for i in range(q) :
  l[i], r[i] = map(int,input().split())
  a = 0
  for k in c :
    if l[i]-1 <= k and k <= r[i]-2 :
      a += 1
  print(a)

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())
  c = [0]
  a = 0
  for j in range(n) :
    if s[j:j+2] == 'AC' :
      a += 1
    c.append(a)
  print(c[r[i]-1] - c[l[i]-1])

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())
  c = []
  for j in range(n) :
    if s[j:j+2] == 'AC' :
      c.append(j)

  a = 0
  for k in c :
    if l[i]-1 <= k and k <= r[i]-2 :
      a += 1
  print(a)

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())
  t = s[l[i]-1:r[i]]
  u = r[i] - l[i] + 1
  c = 0
  for j in range(u-1) :
    if t[j:j+2] == 'AC' :
      c += 1
  print(c)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
L = []
R = []
for i in range(Q):
    l,r = map(int, input().split())
    L.insert(i,l)
    R.insert(i, r)
    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 = []
for i in range(Q):
    l,r = map(int, input().split())
    L.insert(i,l)
    R.insert(i, r)
for i in range(Q):
    print(S[(L[i]-1):R[i]].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
tmp = [int(i) for i in input().split()]
N,Q = tmp[0],tmp[1]
S = [str(i) for i in input().split()][0]

for i in range(Q):
  L = [int(i) for i in input().split()]
  s = S[L[0]-1:L[1]]

  cnt = 0
  for i in range(0,len(s)):
    if s[i]=='A':
      if i+1!=len(s) and s[i+1]=='C':
        cnt+=1
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
tmp = [int(i) for i in input().split()]
N,Q = tmp[0],tmp[1]
S = [str(i) for i in input().split()][0]

for i in range(Q):
  L = [int(i) for i in input().split()]
  s = S[L[0]-1:L[1]]

  cnt = 0
  for i in range(0,len(s)):
    if s[i]=='A':
      if i+1!=len(s) and s[i+1]=='C':
        cnt+=1
  print(cnt)

Submission status: Time Limit Exceeded

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

cum = [0]*n

for i in range(1, len(s)+1):
  sp = s[:i]
  cum[i-1] = sp.count('AC')

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

    for l, r in zip(L, R):
        print(S[l-1:r].count("AC"))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(Q):
  before_a = False
  ans = 0
  for j in range(LR[i][0]-1, LR[i][1]):
    if before_a and S[j] == 'C':
      ans += 1
      before_a = False
    elif S[j] == 'A':
      before_a = True
    else:
      before_a = False
  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 i in range(Q):
  before_a = False
  ans = 0
  for j in range(LR[i][0]-1, LR[i][1]):
    if before_a and S[j] == 'C':
      ans += 1
      before_a = False
    elif S[j] == 'A':
      before_a = True
    else:
      before_a = False
  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)]

P = []
before_a = False
for i in range(N):
  if before_a and S[i] == 'C':
    P.append(i)
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
for i in range(Q):
  ans = 0
  for num in P:
    if num >= LR[i][0] and num <= LR[i][1]-1:
      ans += 1
    elif num > LR[i][1]-1:
      break
  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)]

P = []
before_a = False
for i in range(N):
  if before_a and S[i] == 'C':
    P.append(i)
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
for i in range(Q):
  ans = 0
  for num in P:
    if num >= LR[i][0] and num <= LR[i][1]-1:
      ans += 1
    elif num > LR[i][1]-1:
      break
  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)]

P = []
before_a = False
for i in range(N):
  if before_a and S[i] == 'C':
    P.append(i)
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
for i in range(Q):
  ans = 0
  for num in P:
    if num >= LR[i][0] and num <= LR[i][1]-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):
    l,r = map(int, input().split())
    Slr = S[l-1:r]
    print(Slr.count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
lr=[]
for _ in range(q):
  l,r=map(int,input().split())
  lr.append([l,r])
def ans(x):
  l=lr[x][0]
  r=lr[x][1]
  s_x=s[l-1:r]
  n=len(s_x)
  a=0
  for i in range(n-1):
    if s_x[i]=='A' and s_x[i+1]=='C':
      a+=1
  return a
for i in range(q):
  print(ans(i))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
#ABC122 C

n,q = map(int,input().split())
s = list(input())
t = ["0" for _ in range(n)]

for i in range(n):
    if i < n-1:
        if s[i] == 'A':
            if s[i+1] == 'C':
                t[i] = 'a'
ans = []
for _ in range(q):
    l,r = map(int,input().split())
    c = t[l-1:r-1].count("a")
    ans.append(c)
for i in range(q):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
#ABC122 C

n,q = map(int,input().split())
s = list(input())
def check(x):
    sum = 0
    i = 0
    while i < len(x):
        if i < len(x)-1:
            if x[i] == 'A':
                if x[i+1] == 'C':
                    sum += 1
                    i += 1
        i += 1
    return sum
ans = []
for _ in range(q):
    l,r = map(int,input().split())
    ans.append(check(s[l-1:r]))
for i in range(q):
    print(ans[i])

Submission status: Time Limit Exceeded

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

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)]
#print(n,q,s,l)

acl = []
acr = []
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        acl.append(i)
        acr.append(i+1)
#print(ac)
m = len(acl)
for i in range(q):
    ans = 0
    left = l[i][0] - 1
    right = l[i][1] - 1
    for a in acl:
        if left <= a and a < right:
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

s=input()
s=list(s)
li =[]

for i in range(n):
    a,b = map(int,input().split())
    num=0
    for j  in range(a-1,b-1):
        #print(j)
        
        if s[j]=="A" and s[j+1] == "C":
            num+=1
            
    li.append(num)
for i in range(len(li)):
    print(li[i])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
n,q = map(int,input().split())
s = input()
ac = s.count('AC')
for a in range(q):
    lm = list(map(int,input().split()))
    str1 = s[lm[0]-1:lm[1]:]
    if len(str1) > n:
        str2 = s[0:lm[0]-1:] + s[lm[1]::]
        print(s - str2.count('AC'))
    else:
        print(str1.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
import re
n,q = map(int,input().split())
s = input()
for a in range(q):
    lm = list(map(int,input().split()))
    str1 = s[lm[0]-1:lm[1]:]
    z = str1.count('AC')
    print(z)

Submission status: Time Limit Exceeded

Solution code:
import re
n,q = map(int,input().split())
s = input()
for a in range(q):
    lm = list(map(int,input().split()))
    str1 = s[lm[0]-1:lm[1]:]
    str2  = re.sub('AC','Z',str1)
    z = str2.count('Z')
    print(z)

Submission status: Time Limit Exceeded

Solution code:
import re
n,q = map(int,input().split())
s = input()
lm = []
for a in range(q):
    lm.append(list(map(int,input().split())))
for x in range(q):
    str1 = s[lm[x][0]-1:lm[x][1]:]
    str2 = re.sub('AC','Z',str1)
    z = str2.count('Z')
    print(z)

Submission status: Time Limit Exceeded

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

for i in range(b):
    d, e = map(int, input().split())
    f = c[d-1:e]
    print((len(f) - len(f.replace("AC", ""))) // 2)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n,q = input().split()
    s = input()
    l = []
    target = 'AC'
    for i in range(int(q)):
        l.append([int(s) for s in input().split()])
    index = -1
    index_list = []
    while True:
        index = s.find(target, index + 1)
        if index == -1:
            break
        index_list.append(index + 1)
    for i in range(int(q)):
        cnt = 0
        for j in index_list:
            if l[i][0] <= j and j <= l[i][1]-1:
                cnt += 1
            if j > l[i][1]:
                break
        print(cnt)

    """
    for i in range(int(q)):
        cnt = 0
        index = -1
        while True:
            index = s[l[i][0]-1:l[i][1]].find(target, index + 1)
            if index == -1:
                break
            cnt += 1
        print(cnt)
    """

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n,q = input().split()
    s = input()
    l = []
    target = 'AC'
    for i in range(int(q)):
        l.append([int(s) for s in input().split()])
    for i in range(int(q)):
        cnt = 0
        index = -1
        while True:
            index = s[l[i][0]-1:l[i][1]].find(target, index + 1)
            if index == -1:
                break
            cnt += 1
        print(cnt)
if __name__ == "__main__":
    main()

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

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

for i in lr:
    cnt = sum(ans[i[0]-1:i[1]-1])
    print(cnt)

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

ans = []
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        ans.append(1)
    else:
        ans.append(0)

for i in lr:
    cnt = sum(ans[i[0]-1:i[1]-1])
    print(cnt)

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

ans = []
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        ans.append("ac")
    else:
        ans.append("no")

for i in lr:
    cnt = ans[i[0]-1:i[1]-1].count("ac")
    print(cnt)

Submission status: Time Limit Exceeded

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

for i in lr:
    cnt = 0
    for j in range(i[0], i[1]):
        if s[j-1] == "A" and s[j] == "C":
            cnt += 1
    print(cnt)

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())
    part_len = r - l + 1
    removed_len = len(S[l - 1:r].replace('AC', ''))
    n_ac = (part_len - removed_len) // 2
    print(n_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:
n, q = map(int, input().split())
s = input()
count = 0
ans = []
for _ in range(q):
    l, r = map(int, input().split())
    partial = s[l-1:r]

    for i in range(len(partial) - 1):
        if partial[i] and partial[i + 1]:
            if partial[i] == 'A' and partial[i + 1] == 'C':
                count += 1

    ans.append(count)
    count = 0

for a in ans:
    print(a)

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

cum = [0]*n
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        cum[i] = 1

for i in range(q):
    print(sum(cum[l[i]-1:r[i]-1]))

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())
cum = [0]*n
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        cum[i] = 1
for i in range(q):
    temp = cum[l[i]-1:r[i]]
    cnt = 0
    for j in range(len(temp) - 1):
        if temp[j] == 1 and temp[j+1] == 0:
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

pos = []
for i in range(N-1):
    if S[i:i+2] == "AC":
        pos.append(i)
def count(l,r):
    return len([x for x in pos if l-1 <= x  <= r-2])

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