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

Submission status: Time Limit Exceeded

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

ps = [S[i] == 'A' and S[i+1] == 'C' for i in range(len(S) - 1)]

for l, r in lrs:
    p = len([b for b in ps[l-1:r] if b])
    if r < len(ps)-1 and not ps[r]:
        p -= 1
    print(p)

Submission status: Time Limit Exceeded

Solution code:
x = input().split()
N = int(x[0])
Q = int(x[1])
atcgstr = list(input())

for i in range(Q):
    y = input().split()
    a = int(y[0])
    b = int(y[1])
    ans = 0
    for i in range(a-1,b-1):
        if atcgstr[i] == 'A':
            if atcgstr[i+1] == 'C':
                ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, Q = map(int, input().split())
S = input()
ls, rs = [], []
for _ in range(Q):
    l, r = map(int, input().split())
    ls.append(l-1)
    rs.append(r-1)

arr = np.zeros(N, np.int)

for i, (a, c) in enumerate(zip(S, S[1:])):
    if a == 'A' and c == 'C':
        arr[i] = 1

for l, r in zip(ls, rs):
    print(np.sum(arr[l:r]))

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int, input().split())
S=list(input())
A = []
for i in range(Q):
  A.append(list(map(int, input().split())))
for i in range(Q):
  count=0
  ent=False
  L=S[A[i][0]-1:A[i][1]]
  for j in range(len(L)):
    if L[j]=="A":
      ent=True
    if L[j]=="C" and ent==True:
      count+=1
      ent=False
  print(count)

Submission status: Time Limit Exceeded

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

def check(count, a, s):
  if s == 'A':
    a = True
  elif s == 'C' and a == True:
    count += 1
  return count, a

def f():
  l, r = map(int, input().split())
  count = 0
  a = False
  for s in S[l-1:r]:
    count, a = check(count, a, s)
  return count

for i in range(Q):
  print(f())

Submission status: Time Limit Exceeded

Solution code:
N, Q = input().split()
Q = int(Q)
S = input()
for i in range(Q):
    l,r = input().split()
    l,r = int(l), int(r)
    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 i in range(q)]
for i in range(q):
    cnt = 0
    t = s[x[i][0]-1:x[i][1]]
    for i in range(len(t)-1):
        if t[i]=="A" and t[i+1]=="C":
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
num = 0
trig = 0
for i in range(q):
  l, r = map(int, input().split())
  lim = s[l-1:r]
  #print(lim)
  for i in lim:
    if i == "A":
      trig = 1
    elif i == "C" and trig == 1:
      num += 1
      trig=0
    else: trig=0
  print(num)
  num = 0

Submission status: Time Limit Exceeded

Solution code:
import re

N, Q = map(int, input().split())
S = input()
P = []
for _ in range(Q):
	l, r = map(int, input().split())
	P.append((l, r))
for p in P:
	#print(p)
	s = S[p[0] - 1:p[1]]
	ac = re.findall("AC", s)
	print(len(ac))
	#print(s)
	#print(ac)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = [ _ for _ in input()]
lr = [[int(_) for _ in input().split()] for _ in range(Q)]
A = [i for i, _ in enumerate(S, 1) if _ == "A"]
C = [i for i, _ in enumerate(S, 1) if _ == "C"]
AC = [_ for _ in A if _ + 1 in C]
for l,r in lr:
    ans = [_ for _ in AC if l <= _ and _ + 1 <= r]

    print(len(ans))

Submission status: Time Limit Exceeded

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

for i in range(q):
    cnt = 0
    start = int(lr[i][0])
    end = int(lr[i][1])

    if end+1 < len(s):
        cnt = s[start-1:end].count('AC')
    else:
        cnt = s[start-1:end].count('AC')

    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,q = (int(x) for x in input().split())
s = input()
a_index = []
for i in range(len(s)):
    if s[i:i+2] == "AC":
        a_index.append(i)

for i in range(q):
    l,r = (int(x) for x in input().split())
    ans = 0
    for ii in a_index:
        if (l-1<=ii and ii+1<=r-1):
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, Q = map(int, input().split())
S = input()
L_R = np.array([input().split() for _ in range(Q)], dtype=int)
for row in zip(L_R[:,0],L_R[:,1]):
    l = row[0]
    r = row[1]
    print(S[l-1:r].count('AC'))

Submission status: Time Limit Exceeded

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

for i in LR:
    ct = 0
    for k in range(i[0]-1, i[1]-1):
        if T[k] == "A" and T[k+1] == "C":
            ct += 1
    else:
        print(ct)

Submission status: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, q = na()
s = input()
index = []
for i in range(len(s)):
    if s[i:i+2] == "AC":
        index.append(i)
for i in range(q):
    l, r = na()
    ct = 0
    for a in index:
        if l-1 <= a <= r-1 and l-1 <= a+1 <= r-1:
            ct += 1
    print(ct)

Submission status: Time Limit Exceeded

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


for i in range(N[1]):
	print(S[l[i][0]-1:l[i][1]].count("AC"))

Submission status: Time Limit Exceeded

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

    l = []
    r = []
    ans = []

    for q in range(Q):
        lq, rq = input().split()
        l.append(int(lq) - 1)
        r.append(int(rq) - 1)
        
    # solve
    ac = 'AC'
    for q in range(Q):
        S_sub = S[l[q] : r[q] + 1]
        S_sub_list = list(S[l[q] : r[q] + 1])
        find_ = S_sub.find(ac)
        cnt = 0
        while find_ != -1:
            del S_sub_list[find_ + 1]
            del S_sub_list[find_]
            cnt  += 1
            S_sub = ''.join(S_sub_list)
            find_ = S_sub.find(ac)
        ans.append(cnt)
    
    for q in range(Q):
        print(ans[q])
            


if __name__ == '__main__':
    C()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
if __name__ == '__main__':
  N, Q = map(int, input().split())
  l = input()
  ans = 0
  anslist = []
  for i in range(Q):
    sublist = []
    left, right = map(int, input().split())
    sublist = l[left-1:right]
    ans = len(re.findall("AC", sublist))
    anslist.append(ans)
    
  for i in anslist:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
a = []
a = input().split(" ")
string = input()
x = int(a[1])
for num in range(x):
  b = []
  b = input().split(" ")
  y = int(b[0])
  z = int(b[1])
  string2 = string[y-1:z]
  count = string2.count("AC")
  print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    ans = []
    carray = [0] * N
    for i in range(1,N):
        # print(S[i-1:i+1])
        if(S[i-1:i+1] == 'AC'):
            carray[i:] = map(lambda x:x+1, carray[i:])
    
    # print(carray)
    for i in range(Q):
        # print(carray[l[i]-1:r[i]])
        ans.append(carray[r[i]-1]-carray[l[i]-1])

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


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for i in range(Q):
  c = 0
  l, r = map(int, input().split())
  li = S[l-1:r]
  for j, s in enumerate(li[:-1]):
    if li[j] == 'A' and li[j+1] == 'C':
      c += 1
  
  print(c)

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.count("AC",l-1,r))

Submission status: Time Limit Exceeded

Solution code:
from sys import exit

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

S = input()

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

ans = []

for i in range(Q):
    li, ri = map(int, input().split())

    count = 0
    for ac in AC:
        if ac < li - 1:
            count += 1
        else:
            break
    for ac in reversed(AC):
        if ri - 1 < ac + 1:
            count += 1
        else:
            break
    ans.append(len(AC) - count)

for a in ans:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

idx = -1
idxList = []
while True:
    idx = S.find('AC', idx + 1)
    if idx == -1:
        break
    idxList.append(idx)

idxList = np.array(idxList)
ans = []

for q in range(Q):
    l, r = map(int, input().split())
    ans.append(np.sum((l-1 <= idxList) & (idxList < r-1)))

for a in ans:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
inputl = []
inputr = []
for i in range(0,Q):
    l,r = map(int, input().split())
    inputl.append(l)
    inputr.append(r)
answerlist = []
for j in range(0,Q):
    l = inputl[j]
    r = inputr[j]
    appear = 0
    for k in range(0,N):
        if(S[l+k-1:l+2+k-1] == 'AC'):
            appear = appear +1
        if(l+2+k-1 == r):
            answerlist.append(appear)
            break
            
for p in range(0,Q):
    print(answerlist[p])

Submission status: Time Limit Exceeded

Solution code:

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

while Q > 0:
    r, l = map(int, input().split())

    s = list(S[r-1:l])
    counter = 0
    oldsp =''
    while len(s) > 0:
        sp = s.pop(0)
        if sp == "C" and oldsp == "A":
            counter+=1
        
        oldsp=sp

    print(counter)
    

    Q -= 1

Submission status: Time Limit Exceeded

Solution code:
nq = list(map(int, input().split()))
n = nq[0]
q = nq[1]
s = input()
ac = [0] * (n - 1)
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        ac[i] = 1
for i in range(q):
    lr = list(map(int, input().split()))
    l = lr[0]
    r = lr[1]
    ans = ac[l - 1: r - 1].count(1)
    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 q in range(Q):
        L[q], R[q] = (int(i) for i in input().split())
A = [str(S.count('AC', l-1, r)) for l, r in zip(L, R)]
print("\n".join(A))

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.count("AC", l-1, r))
  i += 1

Submission status: Time Limit Exceeded

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

for i in range(Q):
    start = lr_lists[i][0] -1
    end = lr_lists[i][1] 
    str_list = S[start:end]

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

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

Submission status: Time Limit Exceeded

Solution code:
acgt = ['A','C','G','T']
N, Q = map(int, input().split())
S = list(input())
for _ in range(Q):
    cnt = 0
    li, ri = map(int, input().split())
    tmpS = S[li-1:ri]
    i = 1
    while i < len(tmpS):
        t = tmpS[i]
        if t == 'A':
            i += 1
        elif t == 'C':
            if tmpS[i-1] == 'A':
                cnt += 1
            i += 2
        else:
            i += 2
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
nyu = input().split()

text = input()

lst = []
for i in range(int(nyu[1])):
  count = 0
  flag = 0
  jyo = input().split()
  tt = text[(int(jyo[0])-1):int(jyo[1])]
  for j in tt:
    if j=='A':
      flag = 1
    elif flag==1 and j=='C':
      count+=1
    else:
      flag=0
  print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,mondaisuu=map(int,input().split())
s=input()
li=np.zeros(n)
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    li[i]=1
for i in range(mondaisuu):
  l,r=map(int,input().split())
  print(int(np.sum(li[l-1:r-1])))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int,input().split())
s = input()
#cnt = 0
for i in range(q):
  cnt = 0
  l, r = map(int,input().split())
  #print(s[l-1:r])
  cnt = s[l-1:r].count('AC')
  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
    tmp = [j for j, x in enumerate(s[l-1:r-1]) if x == 'A']
    for k in range(len(tmp)):
        if s[l - 1 + tmp[k]+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 _ in range(Q)]
q_lis = [S[lr[x][0]-1:lr[x][1]:] for x in range(Q)]
for q in range(Q):
    print(q_lis[q].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())
  deleted = S[l-1:r]
  print(deleted.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

A = list(map(int, input().split(" ")))
str = input()

for i in range(A[1]):
    Q = list(map(int, input().split(" ")))
    S = str[Q[0]-1:Q[1]]
    print(S.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())
    c = S.count('AC', l-1, r)
    print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys

N, Q = map(int, sys.stdin.readline().split())
S = input()
s = []

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

for j in range(Q):
    print(s[j])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n, q = [int(item) for item in input().split()]
s = input()
lr = [[int(item) for item in input().split()] for _ in range(q)]

is_ac = np.zeros(n)
for i in range(n-2):
  if s[i:i+2] == "AC":
    is_ac[i] = True

for item in lr:
  ans = sum(is_ac[item[0]-1: item[1]])
  if s[item[1]-1] == "A":
    if item[1] != n:
      if s[item[1]] == "C":
        ans -= 1
  print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
a = input().split()
a = list(map(int, a))
b = input()
c = [0] * a[1]
d = [0] * a[1]
for n in range(a[1]):
	c[n] = input().split()
	c[n] = list(map(int, c[n]))
	flag = False
	count = 0
	for i in range(c[n][1]-c[n][0]+1):
		if flag == True:
			if b[c[n][0]+i-1] == "C":
				count += 1
		if b[c[n][0]+i-1] == "A":
			flag = True
		else:
			flag = False
	d[n] = count
for z in range(len(d)):
	print(d[z])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:




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

S=input()

L=[]
R=[]
D=0
for i in range(Q):
	l,r=input().split(" ")
	L.append(int(l))
	R.append(int(r))

D=sum(R)-sum(L)#距離の総和 交換法則よりこの方法で求められる



##Nが十分小さい時 O(N+Q)になる
#十分大きいというより, かぶることがあるときかな???

if(D>N):
	if("A" not in S and "C" not in S):
		for i in range(Q):
			print(0)
			exit()
	count=[0 for i in range(N)]
	last="X"
	for i in range(N):
		if(S[i]=="C"):
			if(last=="A"):
				count[i]+=1
		last=S[i]


	for i in range(Q):
		c=sum(count[L[i]-1:R[i]])
		if(L[i]-2>=0):
			if(S[L[i]-1]=="C" and S[L[i]-2]=="A"):
				c-=1
		print(c)
else:
#if(1):
	for i in range(Q):
		s=S[L[i]-1:R[i]]
		if("A" not in s and "C" not in s):
			print(0)
			continue
		c=0
		last="X"
		for j in range(len(s)):
			if(s[j]=="C" and last=="A"):
				c+=1
			last=s[j]
		print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=input()

for _ in range(q):
    l,r=map(int, input().split())
    ps=s[l - 1:r]
    cnt=0
    for i in range(0,len(ps)-1):
        if ps[i: i+2] == 'AC':
            cnt+=1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
li = []
for i in range(Q):
    l,r = map(int,input().split())
    #print(S[l-1:r])
    tmp = S[l-1:r].split("AC")
    print(len(tmp)-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())
  s=S[l-1:r]
  cnt=s.count('AC')
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
n,q = [int(x) for x in stdin.readline().rstrip().split()]
s = stdin.readline().rstrip()
data = [stdin.readline().rstrip().split() for _ in range(q)]
data = [[int(i) for i in l] for l in data]
for d in data:
    sub=s[d[0]-1:d[1]]
    sub=sub.replace('T','').replace('G','')
    print(sub.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int, input().split())
S = input()
e = [[int(i) for i in input().split()] for i in range(q)] 
for i in range(q):
    ans=0
    for a in range(e[i][0],e[i][1]):
        #print(a)
        if S[a-1] == "A" and S[a] == "C":
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = list(input())
def ac(s,l,r):
    cnt = 0
    for i in range(r-l):
        if s[l-1+i] == "A" and s[l+i] == "C":
            cnt+= 1
    return cnt

for j in range(q):
    l,r = map(int,input().split())
    print(ac(s,l,r))

Submission status: Time Limit Exceeded

Solution code:
# ２つの数値
# 12 34 
n, q = input().strip().split(' ')
n, q = [int(n), int(q)]
s = input()
for i in range(q):
        l, r = input().strip().split(' ')
        l, r = [int(l), int(r)]
        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())
  x = S[l-1:r]
  if("AC" in x):
    print(x.count("AC"))
  else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
x = input().split()
N = int(x[0])
Q = int(x[1])
atcgstr = list(input())
atcgstr.append('tmp')
def finc1(x,y,ans):
    if x == 'A':
        if y == 'C':
            ans += 1
    return ans

for i in range(Q):
    y = input().split()
    a = int(y[0])
    b = int(y[1])
    ans = 0
    for i in range(a-1,b-1):
        ans = finc1(atcgstr[i],atcgstr[i+1],ans)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import math
import itertools
import re


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix


def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix


def makeInt(line):
    return int(line.rstrip())


def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    S = input_string[1]
    intMatrix = makeIntMatrix(input_string[2:])
    #print(input_string[2:])
    for line in intMatrix:
        l, r = line
        #print(l, r)
        #print(S[l:r+1])
        cnt = len(re.findall(r'AC', S[l-1:r]))
        print(cnt)
    return


def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    #print(answer)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
strlen,num = map(int,input().split())
word = input()
for i in range(num):
  l,r = map(int,input().split())
  print(word[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(" "))
    ans = 0
    #x = []
    for j in range(l-1, r-1):
        #jにl-1からr-2までを代入する
        #x.append(S[j])
        if S[j]=="A":
            if S[j+1]=="C":
                ans += 1
            #else:
                #ans += 0
        #else:
            #ans += 0
    print(ans)
    #print(x)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
nums = [list(map(int, input().split())) for i in range(q)]
for m in nums:
    s2 = s[m[0]-1:m[1]]
    print(s2.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)]
P=[]
for k, j in enumerate(S[:-1]):
        if j=="A" and S[k+1]=="C":
            P.append(1)
        else:
            P.append(0)
for i in L:
    res=0
    res=sum(P[i[0]-1:i[1]-1])
    #print(P[i[0]-1:i[1]-1])
    '''
    for j in P:

        if(j>=i[0] and j<i[1]):
            flag=1
            res+=1
        else:
            if(flag==1):
                break
        '''
    print(res)

Submission status: Time Limit Exceeded

Solution code:
import re

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

lr_list=[input() for i in range(q)]

for lr in lr_list:
    l,r = map(int, lr.split())
    count = 0
    aflag = False
    for slr in s[l-1:r]:
        if slr == 'A':
            aflag = True
        elif slr == 'C' and aflag == True:
            count += 1
            aflag = False
        else:
            aflag = False
    print(count)

Submission status: Time Limit Exceeded

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

for l,r in lr_list:
    count = 0
    tmp_str = ''.join(s[l-1:r])
    v = [tmp_str[i: i+2] for i in range(0, len(tmp_str)) if len(tmp_str[i: i+2])==2]
    for p in v:
        if 'AC' == p:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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

# In[3]:


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


# In[17]:


for i in range(Q):
    print(S[data[i][0]-1:data[i][1]].count("AC"))


# In[ ]:

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]
    m=0
    for j in range(r-l+1):
        if j==r-l+1:
            pass
        elif ss[j:j+2]=="AC":
            m+=1
    print(m)

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

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

for lr in lr_list:
    len_bfr = len(S[lr[0] - 1:lr[1]])
    len_aft = len((S[lr[0] - 1:lr[1]]).replace("AC",""))
    print((len_bfr - len_aft) // 2 )

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

N, Q = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
lr_list = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]


for l, r in lr_list:
    S2 = S[l-1:r]
    count = 0
    #print(S2)
    flg = False
    for i in range(len(S2)):
        if S2[i] != "A":
            continue
        try:
            if S2[i+1] == "C":
                count += 1
        except:
            pass
    print(count)

Submission status: Time Limit Exceeded

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

for lr in LR:
    s = S[lr[0]-1:lr[1]]
    print(s.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()
lr = [list(map(int, input().split())) for _ in range(q)]

for lr_v in lr:
    _s = s[lr_v[0] - 1:lr_v[1]]
    r_s = _s.replace("AC", "S")
    print(r_s.count("S"))

Submission status: Time Limit Exceeded

Solution code:
def countAC(s):
    index = []
    for i in range(N):
        if i == N-1:
            break
        if s[i] == 'A':
            if s[i+1] == 'C':
                index.append(1)
                continue
        index.append(0)
    return index

N,Q = (int(_) for _ in input().split())
S = input()
SIndex = countAC(S)
out = 0
for i in range(Q):
    l,r = (int(_) for _ in input().split())
    s = SIndex[l-1:r-1]
    for x in s:
        out += x
    print(out)
    out = 0

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input().split()[1])
s=input()

def count(l,r):
    global s
    lr_str = s[l-1:r]
    #print(lr_str)
    As_ind = [i for i, x in enumerate(lr_str) if x == 'A']
    count=0
    for a in As_ind:
        if a<len(lr_str)-1:
            #print(a+1)
            if lr_str[a+1]=='C':
                count+=1
    print(count)

for i in range(n):
    lr=input().split()
    count(int(lr[0]),int(lr[1]))

Submission status: Time Limit Exceeded

Solution code:
N,Q = list(map(int,input().split()))
S = input()
ac_index = [i for i in range(N-1) if S[i:i+2]=="AC"]

for _ in range(Q):
    l,r = list(map(int,input().split()))
    l = l - 1
    r = r - 1
    print(len([i for i in ac_index if i >= l and i < r]))

Submission status: Time Limit Exceeded

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

l_list = []
r_list = []

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
N, Q = map(int, input().split())
S = input()
l = [0] * N
c = 0
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
        l[i + 1] = c
for _ in range(Q):
    a, b = map(int, input().split())
    print(max(l[a - 1: b]) - max(l[:a]))

Submission status: Time Limit Exceeded

Solution code:
import re

i = int(input().split()[1])
s = input()
k = 0
result = []

while k < i:
    ft, et = map(int, input().split())
    result.append(len(re.findall("AC", s[ft - 1:et])))
    k += 1

for kekka in result:
    print(kekka)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

S = list(input())
l = np.empty(Q)
r = np.empty(Q)
for i in range (Q):
    l[i],r[i] = map(int, input().split())
for i in range (Q):
    a = int(l[i]-1)
    b = int(r[i])
    S2 = S[a:b]
    count = 0
    for j in range (1,len(S2)):
        if (S2[j-1] == "A") and (S2[j] == "C"):
            count = count +1
    print (count)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
string = input()
a = []
for i in range(Q):
    ans = 0
    count = 0
    l,r = map(int,input().split())
    sp_str = string[l-1:r]
    for j in sp_str:
        if j == 'A':
            count += 1
        if j != 'A' and count == 1:
            if j == 'C':
                ans += 1
                count = 0
    a.append(ans)
for k in a:
    print(k)