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 = [int(i) for i in input().split()]
s = input()

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

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8

n, q = map(int, raw_input().split())
s = raw_input()
def f(a, b):
    return s[a-1:b].count("AC")
for i in range(q):
    a, b = map(int, raw_input().split())
    print(f(a, b))

Submission status: Time Limit Exceeded

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

start_pair = [-1]
for j in range(N-1):
    if S[j] == 'A' and S[j+1] == 'C':
        start_pair.append(j)

for i in range(Q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    Count = 0
    for x in start_pair:
        if l <= x < r:
            Count += 1
    print(Count)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
s = [0] * Q
ans = 0

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

for j in range(Q):
    print(s[j].count('AC'))

Submission status: Time Limit Exceeded

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

import re

def solv(s, l, r):
    s = s[l-1:r]
    ans = 0
    a = False
    for c in s:
        if c == 'A':
            a = True
        elif a and c == 'C':
            ans += 1
            a = False
        else:
            a = False

    return ans


if __name__ == '__main__':

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

    for _ in range(q):
        l, r = map(int, input().split())
        ans = solv(s, l, r)
        print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = list(map(int, input().split()))
S = input()
ans = [0]*Q
for i in range(Q):
    l, r = list(map(int, input().split()))
    tmp = S[l - 1:r]
    ans[i] = tmp.count('AC')
print(*ans, sep='\n')

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(" "))
    temp = S[L-1:R]
    print(temp.count("AC"))

Submission status: Time Limit Exceeded

Solution code:


tmp = input().split(" ")
n = tmp[0]
q = int(tmp[1])

s = input()

for i in range(q):
    tmp = input().split(" ")
    a = int(tmp[0]) - 1
    b = int(tmp[1])
    sub = s[a:b]
    start=0
    count=0
    while True:
        ind = sub.find("AC", start)
        if ind != -1:
            start=ind+2
            count += 1
        else:
            break
    print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

N,Q = map(int, input().split())
S = input()
l = [0] * Q
r = [0] * Q
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:
import sys
input = sys.stdin.readline

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
for _ in range(Q):
  l, r = map(int, input().split())
  strin = S[l - 1:r]
  Tlis = []
  count = 0
  for i in range(len(strin) - 1):
    if strin[i] == "A":
      if strin[i + 1] == "C":
        count += 1
  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 index in lr:
    str = s[index[0]-1:index[1]]
    print(str.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
    j = l - 1
    while j < r - 1:
        if s[j] == 'A' and s[j+1] == 'C':
            ans += 1
            j += 2
        else:
            j += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,mondaisuu=map(int,input().split())
s=input()
for i in range(mondaisuu):
  ans=0
  l,r=map(int,input().split())
  prob=s[l-1:r]
  print(prob.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:
    k = 0
    for i in range(lr_v[0] - 1, lr_v[1] + 1, 2):
        if s[i:i + 2] == "AC":
            k += 1

        if i + 2 < lr_v[1]:
            if s[i + 1:i + 3] == "AC":
                k += 1

    print(k)

Submission status: Time Limit Exceeded

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

def count_AC(s):
    l, r = map(int, s.split())
    t = S[l-1:r]
    return str(t.count("AC"))


LR_list = [sys.stdin.readline() for i in range(Q)]
Count = [count_AC(s) for s in LR_list]
print("\n".join(Count))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = input().split()
N = int(n[0])
Q = int(n[1])
S = input()

ans = []
for i in range(Q):
    lr = input().split()
    l = int(lr[0])
    r = int(lr[1])
    tmp = S[l-1:r]
    count = tmp.count('AC')
    print(str(count))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# C
n, q = map(int, input().split())
s = str(input())
s_flag = [0] * n
for i in range(n-1):
    if s[i:i+2] == 'AC':
        s_flag[i] = 1
for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    ans = sum(s_flag[l:r])
    if s_flag[r:r+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())
  print(S.count('AC',l-1,r))

Submission status: Time Limit Exceeded

Solution code:
#C
import collections



N,Q =map(int,input().split())
S = input()
List=[[int(j) for j in input().split()] for i in range(1,Q+1)]

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

Submission status: Time Limit Exceeded

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

for i in range(n-1):
     if (a[i] == "A") and (a[i+1] == "C"):
          pos_AC.append(i)

for i in range(q):
     s,e = map(int,input().split())
     count = 0
     for j in pos_AC:
          if (s-1 <= j) and (j < e-1):
               count += 1
     print(count)

Submission status: Time Limit Exceeded

Solution code:
import re

N, Q = [int(item) for item in re.split(r"\s", input())]
S = input()

l = []
r = []
for i in range(Q):
    l_i, r_i = [int(item) for item in re.split(r"\s", input())]
    l.append(l_i)
    r.append(r_i)

# ACの場所を探す
p_list = []
for i in range(N - 1):
    if S[i:i + 2] == "AC":
        p_list.append(1)
    else:
        p_list.append(0)

for q in range(Q):
    # qに答える
    l_i = l[q] - 1
    r_i = r[q] - 1
    print(sum(p_list[l_i:r_i]))

Submission status: Time Limit Exceeded

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

for i in range(Q):
    l,r=map(int,input().split())
    l,r=l-1,r-1 #リストのインデックスとの整合
    count_list.append(S[l:r+1].count('AC'))
for k in count_list:
    print(k)

Submission status: Time Limit Exceeded

Solution code:
def count(s):
    num = 0
    check = False
    for i in s:
        if i == 'A' and not(check):
            check = True
        elif i == 'C' and check:
            num += 1
            check = False
        else:
            check = False
    return num


n, q = map(int, input().split())
s = input()
s = ''.join([i if i == 'A' or i == 'C' else ' ' for i in s])
inds = [list(map(int, input().split())) for _ in range(q)]
for ind in inds:
    ss = s[ind[0]-1:ind[1]]
    print(count(ss))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def main():
	N,Q=map(int,input().split())
	S=input()
	l=[]
	r=[]
	for i in range(Q):
		l_temp,r_temp=map(int,input().split())
		l.append(l_temp-1)
		r.append(r_temp-1)

	for j in range(Q):
		s_temp=S[l[j]:r[j]+1]
		s_judge(s_temp)

def s_judge(temp):
	result=0
	for i in range(len(temp)-1):
		if(temp[i]=='A'):
			if(temp[i+1]=='C'):
				result+=1
	print(result)

def inputList():
	a=list(map(int,input().split()))
	return a

def multisort(li,index):
	return sorted(li,key=lambda x: x[index])

if(__name__=='__main__'):
	main()

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(0,q):
    l[i], r[i] = map(int,input().split())
    l[i] = l[i] -1
    r[i] = r[i] -1

s_list = list(s)

ac_list = []

for i in range(0,n-1):
    if s_list[i] == "A" and s_list[i+1] == "C":
        ac_list.append(i)

#print(ac_list)

for i in range(0,q):
    count = 0
    for j in range(l[i],r[i]):
        if j in ac_list:
            count = count + 1
    print(count)

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()
for i in range(q):
    l, r = na()
    flg = s[l-1:r]
    print(flg.count("AC"))

Submission status: Time Limit Exceeded

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

ac_list = []
for i in range(N-1):
    if S[i] == "A":
        if S[i+1] == "C":
            ac_list.append(i)

for i in range(Q):
    l,r = input().split()
    c = 0
    for ac in ac_list:
        if int(l)-1 <= ac <= int(r)-2:
            c += 1
    print(c)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
info=[]
    
def count_ac(l,info1,info2):
    return l[info1-1:info2].count("AC")

for i in range(q):
    info.append(list(map(int,input().split())))
    print(count_ac(s,info[i][0],info[i][1]))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int, input().split())
S = list(input())
lr = [list(map(int,input().split())) for i in range(Q)]
S_tmp = []
bef = ''
cnt = 0
for i in range(Q):
    for j in range(lr[i][0] - 1,lr[i][1]):
        S_tmp.append(S[j])
    for s in S_tmp:
        if s == 'C' and bef == 'A':
            cnt += 1
        bef = s
    print(cnt)
    cnt = 0
    S_tmp.clear()

Submission status: Time Limit Exceeded

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



for i in range(q):
    l,r = map(int,input().split())
    s2 = s[l-1:r]
    a = re.findall("AC", s2)
    print(len(a))

Submission status: Time Limit Exceeded

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

count = []
for i in range(1,N + 1):
    count.append(S[0:i].count("AC"))


for i in range(0,Q):
    l,r = map(int,input().strip().split())
    if r > len(count):
        r = len(count)
    print(count[r - 1] - count[l - 1])

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = list(input())
qs = [list(map(int, input().split())) for _ in range(Q)]
for q in qs:
    count = 0
    string = S[q[0]-1:q[1]]
    indexes = [i for i, x in enumerate(string) if x == 'A']
    for i in indexes:
        try:
            if string[i+1] == 'C':
                count += 1
        except:
            pass
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

def parse(inp):
    N,Q=map(int,next(inp).split())
    S=list(next(inp))
    
    lr=[[] for _ in range(Q)]
    
    for i in range(Q):
        lr[i]=list(map(int,next(inp).split()))
        
    return N,Q,S,lr
  
def solve(S,lr):
    Q=len(lr)
    l,r=lr
    
    ans=0
    for i in range(r-l):
        if(S[l-1+i]=='A' and S[l+i]=='C'):
            ans += 1
            
    return ans

def main(inp):
    N,Q,S,lr=inp
    
    for i in range(Q):
        print(solve(S,lr[i]))
      
main(parse(sys.stdin))

Submission status: Time Limit Exceeded

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

for i in range(Q):
  tmp = input().split()
  l = int(tmp[0])
  r = int(tmp[1])
  
  deleted = S[l-1:r]
  print(len(''.join(deleted).split('AC'))-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]
    print(s_.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int,input().split())
S = list(input())
ans = []
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        ans.append(i)
for i in range(Q):
    count = 0
    L, R = map(int,input().split())
    for j in range(len(ans)):
        if ans[j] >= L-1 and ans[j] <= R-2:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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

for i in range(Q):
    L,R = map(int,input().split(" "))
    temp = S[L-1:R]
    temp = list(temp)
    count = 0
    #print(temp)
    for k in range(R - L + 1 - 1):
        if temp[k] == 'A' and temp[k+1] == 'C':
            count += 1
    print(count)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

for i in num_list:
    print(s[i[0]-1:i[1]].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
def countAC(s):
    counter = 0
    for i in range(len(s)):
        if i == len(s)-1:
            break
        if s[i] == 'A':
            if s[i+1] == 'C':
                counter += 1
    return counter



N,Q = (int(_) for _ in input().split())
S = input()

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

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 = []
    # for i in range(Q):
    #     ts = S[l[i]:r[i]].count('AC')
    #     print(S[l[i]-1:r[i]1])
    #     ans.append(ts)
    carray = [0] * N
    for i in range(1,N):
        if(S[i] == 'C' and S[i-1] == 'A'):
            carray[i] = 1
        else:
            continue

    for i in range(Q):
        # print(carray[l[i]-1:r[i]])
        ans.append(carray[l[i]:r[i]].count(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:
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=input()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main_(lst):
    a=s[lst[0]-1:lst[1]]
    return a.count("AC")

n,q=map(int,input().split())
s=str(input())
lr=[list(map(int,input().split())) for i in range(q)]
na=list(map(main_,lr))
for i in na:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
f_string = "AC"
for i in range(Q):
    l,r = map(int,input().split())
    cnt=0
    for k in range(l-1,r-1,1):
        nimoji = S[k] + S[k+1]
        if nimoji == f_string:
            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())
    s = S[l-1:r]
    print(s.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())
    ans = S.count('AC',l-1,r)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = list(map(int, input().split()))
a = list(input())
nlist = []
for i in range(0, n[1]):
  acnum = 0
  nlist = list(map(int, input().split()))
  b = a[nlist[0] - 1 : nlist[1]]
  while len(b) >= 2:
    if b[0] == 'A' and b[1] == 'C':
      acnum += 1
      b.pop(0)
      b.pop(0)
    else:
      b.pop(0)
  print(acnum)

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())
  P = S[l-1: r]
  cnt = 0
  flg = False
  for p in P:
    if flg:
      if p == 'C':
        cnt += 1
      flg = False
    elif p == 'A':
      flg = True
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
count_l=[]
for i in range(Q):
    a,b = map(int,input().split())
    flag=False
    counting=0
    if b==N:
        l=S[a-1:]
    else:
        l=S[a-1:b]
    #print(l)
    for ii in l:
        #print(ii)
        if ii=="A":
            flag=True
        elif ii=="C" and flag==True:
            counting+=1
            flag=False
    count_l.append(counting)
for i in count_l:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N, Q = [int(x) for x in input().split()]
S = input()
for _ in range(Q):
	l, r = [int(x) for x in input().split()]
	count = 0
	for i in range(l-1,r-1):
		if S[i:i+2] == "AC":
			count += 1
	print(count)

Submission status: Time Limit Exceeded

Solution code:
n = input().split()
N = int(n[0])
Q = int(n[1])
S = input()

ans = []
for i in range(Q):
    lr = input().split()
    l = int(lr[0])
    r = int(lr[1])
    tmp = S[l-1:r]
    count = tmp.count('AC')
    ans.append(count)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for _ in range(Q):
    l,r = list(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()

pos = []
for i in range(Q):
    pos.append(list(map(int, input().split())))
    
def countAC(S, r, l):
    data = S[r-1:l]
    cnt = 0
    for i in range(len(data)-1):
        if data[i]=='A':
            if data[i+1] == 'C':
                cnt+=1
    return cnt
  
ret = []
for it in pos:
    cnt = countAC(S, it[0], it[1])
    ret.append(cnt)
_ = [print(it) for it in ret]

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

ac_list = []
for i in range(N-1):
    if S[i] == "A":
        if S[i+1] == "C":
            ac_list.append(i)

c_list = []
for i in range(Q):
    l,r = input().split()
    c = 0
    for ac in ac_list:
        if int(l)-1 <= ac <= int(r)-2:
            c += 1
    c_list.append(c)

for c in c_list:
    print(c)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = (int(i) for i in input().split())
S = input()
A = []
for q in range(Q):
        l, r = (int(i) for i in input().split())
        A.append(str(S[(l-1):r].count('AC')))
print("\n".join(A))

Submission status: Time Limit Exceeded

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

for i in range(q):
    tl=s[lr[i][0]-1:lr[i][1]]
    ctr=0
    for k in range(len(tl)-1):
        if tl[k]=="A" and tl[k+1]=="C":
            ctr+=1
        else:
            pass
    print(ctr)

Submission status: Time Limit Exceeded

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

flg = []
for i in range(N-2):
    tmp_S = S[i:i+2]
    if tmp_S == 'AC':
        flg.append(1)
    else:
        flg.append(0)

for a in A:
    tmp_f = flg[a[0]-1:a[1]-1]
    print(sum(tmp_f))

Submission status: Time Limit Exceeded

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

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

for i in range(Q):
    matched = [ x for x in aclist if x >= lr[i][0] and x+1 <= lr[i][1] ]
    print(len(matched))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

N, Q = map(int, input().split())
s = sys.stdin.readline().rstrip()
ac_list = []
start = 0
while True:
  index = s.find('AC', start)
  if index == -1:
    break
  ac_list.append([index + 1, index + 2])
  start = index + 1


for _ in range(Q):
  l, r = map(int, input().split())
  res = 0
  for a, c in ac_list:
    if l <= a and c <= r:
      res += 1
  print(res)

Submission status: Time Limit Exceeded

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

for i in range(q):
        r = s[t[i][0]-1:t[i][1]]
        r1 = ''.join(r)
        print(r1.count("AC"))

Submission status: Time Limit Exceeded

Solution code:

import sys
input = sys.stdin.readline
import numpy as np

def question():
    n, q = list(map(int, input().split()))
    s = input()
    lr = [list(map(int, input().split())) for i in range(q)]
    a = [1 if (s[i]=="A" and s[i+1] =="C") else 0 for i in range(n-1)]
    a = np.array(a)
    for i in range(q):
        print(np.sum(a[lr[i][0]-1:lr[i][1]-1]))

question()

Submission status: Time Limit Exceeded

Solution code:
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 = [0] * n
prev_char = ""

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

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

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]
    #print(S2)
    S3 = S2.replace("AC", "")
    print( (len(S2) - len(S3)) // 2 )

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,Q = (int(i) for i in input().split())
S = input()
flag = False

for i in range(Q):
  x,y = (int(i)-1 for i in input().split())
  cnt = 0
  for j in S[x:y+1]:
    if j == 'A':
      flag = True
    elif j == 'C' and flag:
      cnt += 1
      flag = False
    else:
      flag = False
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = not True
def ddprint(x):
  if DBG:
    print(x)

n,q = inm()
s = input()
a = [0] * (n+1)
cnt = 0
prevA = False
for i in range(n):
    if s[i] == 'A':
        prevA = True
    elif s[i] == 'C':
        if prevA:
            cnt += 1
        prevA = False
    else:
        prevA = False
    a[i] = cnt

ddprint(a)

for j in range(q):
    l,r = inm()
    ddprint(str(l) + ' ' + str(r))
    print(a[r-1] - a[l-1])

Submission status: Time Limit Exceeded

Solution code:
def solve(N, Q, S, L_R):
    answers = [None] * Q
    q = 0
    for l, r in L_R:
        pstr = S[l - 1:r]
        count = count_ac(pstr)
        answers[q] = count
        q += 1
    return answers


def count_ac(pstr):
    count = 0
    a_flag = False
    for i in range(len(pstr)):
        s = pstr[i]
        if s == "A":
            a_flag = True
            continue
        elif s == "C":
            if a_flag:
                count += 1
            a_flag = False
        else:
            a_flag = False
    return count

N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
for ans in solve(N, Q, S, L_R):
    print(ans)

Submission status: Time Limit Exceeded

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

for q in qlist:
    sparts = S[q[0]-1:q[1]]
    print(sparts.count("AC"))

Submission status: Time Limit Exceeded

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

positions = []
prev_A = False
for j in range(N):
    if S[j] == 'A':
        prev_A = True
    elif prev_A == True and S[j] == 'C':
        positions.append(j - 1)
        prev_A = False
    else:
        prev_A = False

for i in range(Q):
    l, r = map(int, input().split())
    print(len(list(filter(lambda x: l - 1 <= x < r - 1, positions))))

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

def count(l,r):
    global s
    wasA=False
    count=0
    for c in s[l-1:r]:
        if c=='A':
            wasA=True
            continue
        if c=='C':
            if wasA:
                count+=1
        wasA=False
    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 = map(int, input().split())
s = input()
quiz = [list(map(int, input().split())) for _ in range(q)]

for i in range(q):
    t = s[quiz[i][0] - 1:quiz[i][1]]
    cnt = t.count("AC")
    print(cnt)

Submission status: Time Limit Exceeded

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

S = S.split('AC')
S = [len(s) + 2 * i for i, s in enumerate(S)][:-1]

for q in range(Q):
    l, r = map(int, input().split())
    l, r = l-1, r-1
    n = 0
    f = False
    for s in S:
        if f == False:
            if l <= s:
                f = True
                if s+1 <= r:
                    n += 1
        else:
            if s+1 <= r:
                n += 1
            else:
                break
    print(n)

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):
        if tmpS[i] == 'C':
            if tmpS[i - 1] == 'A':
                cnt += 1
        i += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache


@lru_cache(maxsize=None)
def find_word(word):
    return word.count('AC')


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

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

print('\n'.join(map(str, answers)))