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()
for i in range(q):
    l, r = map(int, input().split())
    count = 0
    flg = 0
    for j in range(l-1, r, 2):
        if s[j] =="A":
            if s[j+1] == "C":
                count +=1
            elif s[j+1] == "A": 
                flg = 1
        elif s[j] =="T" or s[j] =="G":
            if s[j+1] == "A": 
                flg = 1
        elif s[j] == "C" and flg ==1:
                count +=1
                flg = 0
        else:
            pass
    print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, Q = map(int, input().split())
    S = input()
    inlist = [map(int, input().split()) for i in range(Q)]
    # inlist = [line.split(' ') for line in open(0).read().split('\n')]

    for start, stop in inlist:
        start = int(start)-1
        stop = int(stop)
        s = S[start:stop]
        print(s.count('AC'))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

for i in range(Q):
    now = [n for n in numlist if n>= l[i] and n <= r[i]-1]
    print(len(now))

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:
            continue
        else:
            if ss[j]=="A" and ss[j+1]=="C":
                m+=1
    print(m)

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()
    print(len([i for i in index if l-1<= i <= r-1 and l-1<= i+1 <=r-1]))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
""" AtCoder """

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

l = []
pos = 0

for _ in range(S.count("AC")):
    i = S.index("AC")
    l.append(i + pos + 1)
    pos = pos + i + 2
    S = S[i + 2:]

for i in range(Q):
    tmp = []
    tmp.extend(l)
    tmp.append(lr[i][0])
    tmp.append(lr[i][1])
    tmp.sort()
    print(tmp.index(lr[i][1]) - tmp.index(lr[i][0]) - 1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(q):
    l,r=map(int,lr[i].split())
    print(int((len(s[l-1:r])-len(s[l-1:r].replace('AC',"")))/2))

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 = [0] * (N - 1)
i = 0
while i < N - 1:
    if S[i:i + 2] == "AC":
        p_list[i] = 1
        i += 2
    else:
        i += 1

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

print("\n".join(out_list))

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys

def parse_input(lines_as_string = None):

    lines = []
    if lines_as_string is None:
        lines.append(input())
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        q = int(tokens[1])
        lines.append(input())
        for i in range(q):
            lines.append(input())
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        print("lines=%s" % lines)
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        q = int(tokens[1])

    s = lines[1]

    l = []
    r = []
    for i in range(q):
        tokens = lines[i+2].split(" ")
        l.append(int(tokens[0]))
        r.append(int(tokens[1]))

    return (n, q, s, l, r)

def solve(n, q, s, l, r):

#    result = []
    for i in range(q):
        b = l[i] - 1
        e = r[i] - 1
        count = 0
        ss = s[b:e+1]
        len_ss = len(ss)
        for j, c in enumerate(ss):
#            print("ss=%s" % ss)
            if c == "A" and j + 1 < len_ss and ss[j + 1] == "C":
                count = count + 1
        print(count)
#        result.append(count)
    
#    return result

def main():
    solve(*parse_input())
#    print("%d" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
Ss=[i for i in input()]
#S = input()
for i in range(Q):
    l,r = map(int,input().split())
    count = 0
    Sscopy = Ss[l-1:r]
    ans=0
    while True:
        #print(count)
        #print(ans)
        #print(Sscopy)
        if "A" not in Sscopy[ans:]:
            break
        else:
            indexnumber = Sscopy.index("A",ans)
            if indexnumber == len(Sscopy)-1:
                break
            if Sscopy[indexnumber+1]=="C":
                ans = indexnumber+1
                count+=1
        #print("========================")
    print(count)

Submission status: Time Limit Exceeded

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

for q in Q_LIST:
    left = q[0] - 1
    right = q[1] - 1
    target = S[left:right+1]
    print(target.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())
    A = S[:l].count('AC')
    B = S[:r].count('AC')
    print(B-A)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
l = []
ans = []
for i in range(Q):
    l1,l2 = map(int,input().split())
    l.append((l1,l2))

for i,x in l:
    count = 0
    ans1 = []
    s1 = S[i-1:x]
    ans.append(s1.count('AC'))
for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
def ac_count(alist):
    ac_count=0
    for i in range(len(alist)-1):
        if alist[i] == 'A':
            if alist[i+1]  == 'C':
                ac_count += 1
    return(ac_count)

N,Q = list(map(int, input().split()))
S=input()
for i in range(Q):
    l, r = list(map(int, input().split()))
    tmp_list=S[l-1:r]
    print(ac_count(tmp_list))

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())
    c = d = 0
    while a != 0:
        if l[a - 1] != 0:
            c = l[a - 1]
            break
        a -= 1
    while b > a:
        if l[b - 1] != 0:
            d = l[b - 1]
            break
        b -= 1
    print(max(d - c, 0))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
N, Q = (int(i) for i in input().split())
s = input()
lr = [[int(i) for i in input().split()] for i in range(Q)]

for i in range(Q):

    sol = s[(lr[i][0]-1):(lr[i][1])].count('AC')

    if sol < 0:
        sol = 0
    print(sol)

Submission status: Time Limit Exceeded

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

for i in range(q):
    cnt_ac = 0
    for j in range(max(1,quiz[i][0]), quiz[i][1]):
        if s[j] == "C" and s[j-1] == "A":
            cnt_ac += 1
    print(cnt_ac)

Submission status: Time Limit Exceeded

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

for i in range(b):
    d,e = map(int,input().split())
    c_ = c[d-1:e]

    print(c_.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)]

cntli = []
for i in range(q):
    si = s[lr[i][0]-1:lr[i][1]]
    cnt = 0
    for j in range(len(si)-1):
        if si[j] == "A":
            if si[j+1] == "C":
                cnt += 1
    else:
        cntli.append(cnt)

for p in cntli:
    print(p)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
flag = 0
if S.count('AC') == 0:
    flag = 1
for i in range(Q):
    if flag == 1:
        print(0)
    else:
        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()

A = []

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

for i in range(q):
    c = 0
    l, r = map(int, input().split())
    for j in range(len(A)):
        if A[j] >= l-1 and A[j] < r-1:
            c += 1
        if A[j] >= r-1:
            break
    print(c)

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]
        ans.append(S_sub.count(ac))
    
    for q in range(Q):
        print(ans[q])
            


if __name__ == '__main__':
    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())
  S=s[l-1:r]
  print(int((len(S)-len(S.replace("AC","")))/2))

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 = [0 for i in range(0, len(tmp_str)) if tmp_str[i: i+2]=='AC']
    print(len(v))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
tmp = ''
kesu = ''
ans = 0
for i in range(Q):
    LR = list(map(int, input().strip().split(' ')))
    ans = 0
    tmp = S[LR[0]-1:LR[1]]
    kesu = tmp.replace('AC', '')
    ans = (LR[1]-LR[0]+1-len(kesu))/2
    print(int(ans))

Submission status: Time Limit Exceeded

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

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:
# coding: utf-8
n = [int(i) for i in input().split()]
s = input()
for i in range(n[1]):
    a = 0
    m = [int(j) for j in input().split()]
    for j in range(m[1]- m[0] ):
        if s[m[0]-1+j:m[0]+1+j] == "AC":
            #print(s[m[0]-1+j:m[0]+1+j])
            #print(j)
            a += 1
    print(str(a))

Submission status: Time Limit Exceeded

Solution code:

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

landq = [list(map(int,input().split())) for i in range(q)]

def ac_checker(s_line):
    cnt = 0
    while 'AC' in s_line:
        cnt += 1
        s_line = s_line.replace('AC','',1)
        
    return cnt

for i in range(q):
    part_s = s[(landq[i][0]-1):(landq[i][1])]
    print(ac_checker(part_s))

Submission status: Time Limit Exceeded

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

# In[46]:


N,Q=map(int,input().split())
S=input()
lr=[list(map(int,input().split())) for l in range(Q)]

for i in range(Q):
    t=S[lr[i][0]-1:lr[i][1]]
    #t=[S for j in range(lr[i][0],lr[i][1])]
    #print(t)
    print(t.count('AC'))
    if i==Q:
        break


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
from collections import Counter
for lz in range(Q):
  l1,l2=map(int,input().split())
  s1=S[l1-1:l2]
  z=0
  flg=0
  for k in s1:
    if k == 'A':
      flg=1
      continue
    elif k == 'C' and flg == 1:
      z+=1
    flg=0
  print(z)

Submission status: Time Limit Exceeded

Solution code:
def solve(N, Q, S, L_R):
    answers = [None] * Q
    ac_index = [0] * len(S)
    for i in range(len(S) - 1):
        s = S[i:i + 2]
        if s == "AC":
            ac_index[i] = 1
    q = 0
    for l, r in L_R:
        arr = ac_index[l - 1:r]
        ans = sum(arr)
        if arr[-1] == 1:
            ans -= 1
        answers[q] = ans
        q += 1
    return answers


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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

  print(s.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import collections
import re
import copy

def main():
	N, Q = map(int, input().split(" "))
	S = input()
	S = list(S)
	pattern = r"AC"
	
	Qs = []
	for _ in range(Q):
		l, r = map(int, input().split(" "))
		Qs.append((l, r))
	
	ans = []
	for i, val in enumerate(Qs):
		l, r = val
		tmp = S[l-1:r]
		matchedList = re.findall(pattern, "".join(tmp))
		
		ans.append(len(matchedList))
	
	
	for i in ans:
		print(i)
	
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 _ in range(q)]

for lr_v in lr:
    _s = s[lr_v[0] - 1:lr_v[1]]
    print(_s.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)]

for i in range(Q):
    word_s = l[i][0] - 1
    word_e = l[i][1]
    print(S[word_s:word_e].count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(q):
  cnt = 0
  for h in range(int(ls[i][1]) - int(ls[i][0])):
    if s[h - 1] == 'A':
      if s[h] == 'C':
        cnt += 1
    else:
      pass
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, Q = [int(i) for i in input().split()]
S = input()
l, r = [[None] * Q for _ in range(2)]
for i in range(Q):
  l[i], r[i] = [int(i) for i in input().split()]
  
for i in range(Q):
  s = S[l[i]-1:r[i]]
  
  count = 0
  i = s.find('AC')
  while i >= 0:
    count += 1
    i = s.find('AC', i+2)
  
  print(count)

Submission status: Time Limit Exceeded

Solution code:
length = list(map(int,input().split()))	
string = input()
l_r = [list(map(int,input().split())) for i in range(length[1])]
answer = []

for i in range(length[1]):
  part_str = list(string[(l_r[i][0]-1):l_r[i][1]])
  for n in range(len(part_str)):
    answer.append(0)
    if part_str[n]=='A':
      if n != (len(part_str)-1):
        if part_str[n+1]=='C':
          answer[i] += 1
  print(answer[i])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import io
import math
import re

question_info = input().split()
question_string_num = question_info[0]
question_num = int(question_info[1])

datalist = input().split()
data = datalist[0]

answer_list= []
for num in range(question_num):
  data_info = input().split()
  start = int(data_info[0]) - 1
  end = int(data_info[1])
  answer = data[start:end].count('AC')
  answer_list.append(answer)

for num in answer_list:
    print(num)

Submission status: Time Limit Exceeded

Solution code:
NQ = list(map(int, input().split()))
word = input()
word_list = []
for i in word:
    word_list.append(i)

for i in range(0, NQ[1]):
    rl = list(map(int, input().split()))
    word = ''
    for loop in range(rl[0]-1, rl[1]):
        word += word_list[loop]
    print(word.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
li = []
s= S.replace("AC","re")
for i in range(Q):
    l,r = map(int,input().split())
    #print(S[l-1:r])
    #tmp = S[l-1:r].replace("AC","re")
    #tmp = S[l-1:r].split("AC")
    print(s[l-1:r].count("re"))

Submission status: Time Limit Exceeded

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

for i in range(q):
    count=0
    target_s=s[l_list[i]-1:r_list[i]]
    for j in range(len(target_s)-1):
        if target_s[j]=="A":
            if target_s[j+1]=="C":
                count=count+1
    print(count)

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]
  ans = 0
  for i in range(len(x) - 1):
    if x[i:i + 2] == 'AC':
      ans += 1
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,q = list(map(int,input().split()))
s = list(input())
num = list()
for i in range(0,q):
    num.append(list(map(int,input().split())))
check = list()
for i in range(0,n-1):
    if s[i] == "A" and s[i+1] == "C":
        check.append(i+1)
for i in range(0,q):
    count = 0
    for k in check:
        if num[i][1] <=k:
            break
        if num[i][0] <= k:
            count +=1
    print(count)

Submission status: Time Limit Exceeded

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

def hoge(s):
    l, r = map(int, input().split())
    print(s[l-1:r].count("AC"))

if __name__ == "__main__":
    for i in range(q):
        hoge(s)

Submission status: Time Limit Exceeded

Solution code:
N, M = list(map(int, input().split()))
S = input()
S1 =""
a = []
p=0
q=0
for i in range(M):
    a.append(list(map(int, input().split())))
for i in range(M):
  p=a[i][0]-1
  q=a[i][1]
  S1=S[p:q]
  print(S1.count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

    print(s.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
target_str = "AC"

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

target_list = [0 for i in range(N)]

for i in range(N - 1):
  if S[i: i + 2] == target_str:
    target_list[i] = 1

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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 = deque(a[nlist[0] - 1 : nlist[1]])
    while len(b) > 1:
        Aka = b.popleft()
        if Aka == 'A':
            Cka = b.popleft()
            if Cka == 'C':
                acnum += 1
    print(acnum)

Submission status: Time Limit Exceeded

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

for i in range(Q):
    l, r = lr[i]
    s = S[l-1:r]
    print(len(re.findall('AC', s)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for q in Q_LIST:
    left = q[0] - 1
    right = q[1] - 1
    target = S[left:right+1]
    before_was_a = False
    ans = 0
    for current_char in target:
        if before_was_a:
            if current_char == 'C':
                ans = ans + 1
            before_was_a = False
        before_was_a = current_char == 'A'
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
length,question = map(int, input().split())
string = input()
e = [[int(i) for i in input().split()] for i in range(question)]
c = 0
tmp = []
result = []
r = []
for i in e:
    s = ''
    for j in range(i[0],i[1]+1):
        s+=string[j-1]
    for n in range(len(s)):
        #print(s[n:n+2])
        if s[n:n+2] == "AC":
            c+=1
        else:
            pass
    r.append(c)
    c = 0
for i in r:
    print(i)
        
    
            
        
        
        
    







"""
string = input()
pattern = ["A","C","G","T"]

c = 0
result = []
for i in string:
    if i in pattern:
        c += 1
        if string[len(string)-1] == i:
            result.append(c)
    else:
        result.append(c)
        c = 0

if len(result) == 0:
    print(len(string))
else:
    print(max(result))
"""

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
for i in range(q):
    x,y=map(int,input().split())
    ans = 0
    for l in range(x,y):
        if s[l-1]=="A" and s[l]=="C": ans+=1
    print(ans)

Submission status: Time Limit Exceeded

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

for k in range(Q):
    l, r = lr[k]
    s2 = s1[l-1:r]
    flag = 0
    for i in range(len(s2)-1):
        if s2[i]=='A' and s2[i+1]=='C':
            flag += 1
    print(flag)

Submission status: Time Limit Exceeded

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

# ACがある場所の添字（エンド）
# pos_ = []
# last = "x"
# for i, si in enumerate(S):
#     if last == "A" and si == "C":
#         pos_.append(i)
#     last = si
# print(pos_)

import re
pos = [m.start() for m in re.finditer('AC', S)]
# print(pos)

for _ in range(Q):
    l, r = map(int, input().split())
    start = l - 1
    end = r - 1
    # print(start, end)
    count = 0
    for p in pos:
        if start <= p and end >= p + 1:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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

#print(N,Q,S)

for q in range(1,Q+1):
	ans=0
	l, r = map(int, input().split())		# 5 7
	s = S[l-1:r]
	#print(l,r,s, len(s))
	
	x=-1
	for i in range(len(s)):
		if i<x: continue
		x = s.find("AC",i)
		if x>=0:
			ans += 1
			x+=2
		#print(s,i,x,ans)

	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 += [li]
    r += [ri]

for ind in range(Q):
    substr = S[max(0, l[ind]-1) : min(r[ind], N)]
    print(substr.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
n,q = map(int,input().split())
s = input()
ans = 0

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

Submission status: Time Limit Exceeded

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


for i in range(q):
  c = 0
  h,f= map(int, input().split())

  # print(s)
  # print("f="+str(f))
  while s[h-1:f].find('AC') >= 0:
    # print("count")
    c+= 1
    # print("f="+str(f))
    # print(s[h-1:f])
    h+=  s[h-1:f].find('AC')+2
    # print("f="+str(f))
    if h >= f:
      # print(h,f)
      break
  print(c)

Submission status: Time Limit Exceeded

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



memo = {}
def init_memo():
    for start in range(N):
        for end in range(start,N):
            if start == end == 0:
                memo[(start,end)] = 0
            elif start == end:
                memo[(start,end)] = memo[(start-1,end)] - int(S[start-1:start+1]=="AC")
            else:
                memo[(start, end)] = memo[(start,end-1)] + int(S[end-1:end+1] == "AC")

init_memo()

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

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:
    print(sum(P[i[0]-1:i[1]-1]))

Submission status: Time Limit Exceeded

Solution code:
import sys

_ = input()
S = input().strip()
idx = [i+1 for i in range(len(S)-1) if S[i:i+2] == 'AC']

for line in sys.stdin:
  l,r = list(map(int, line.strip().split(' ')))
  print(sum([1 for i in idx if l <= i <= r-1]))

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

Submission status: Time Limit Exceeded

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

#import numpy as np
#tmp_list = np.zeros(N)

#for i in range(N-1):
#    if S[i] == 'A' and S[i+1] == 'C':
#        tmp_list[i] = 1

for i in range(Q):
    lr = input().split()
    l = int(lr[0])
    r = int(lr[1])
    tmp = S[l-1:r]
    tmp_num = 0
    for j in range(len(tmp)-1):
        if tmp[j] == 'A' and tmp[j+1] == 'C':
            tmp_num += 1
    print(str(tmp_num))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = list(input())
s = []
for i in range(Q):
    l,r = map(int,input().split())
    #c = 0
    #print(Q,i)
    s.append(0)
    #print(s)
    for j in range(l-1,r-1):
        #print(i,j)
        if S[j] == "A" and S[j+1] == "C":
            s[i] += 1
        #if c == 0 and S[j] == "A":
         #   c = 1
            #print("a")
        #elif c == 1 and S[j] == "C":
         #   c = 0
          #  s[i] = s[i]+ 1
            #print("b")
    #print(i)
for i in range(Q):
    print(s[i])

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int, input().split())
SS = input()
lrq = []
for i in range(N-1):
  if SS[i] == "A" and SS[i+1] == "C":
    lrq.append(1)
  else:
    lrq.append(0)
lrq.append(0)
for _ in range(Q):
  l,r = map(int, input().split())
  l -= 1
  r -= 1
  ans = sum(lrq[l:r+1])
  if lrq[r] == 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):
	count = 0
	l, r = map(int, input().split())
	Sr = S[l-1:r]
	for j in range(len(Sr)-1):
		if(Sr[j] == 'A' and Sr[j+1] == 'C'):
			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())
    S_tmp = S[l-1:r]
    tmp = []
    for j in range(0,len(S_tmp),1):
        tmp.append(S_tmp[j:j+2])
    print(tmp.count("AC"))

Submission status: Time Limit Exceeded

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

for i in range(q):
    count=0
    target_s=s[l_list[i]-1:r_list[i]]
    for i in range(len(target_s)-1):
        if target_s[i]=="A":
            if target_s[i+1]=="C":
                count=count+1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N, Q = (int(x) for x in input().split())
S = input()
lr = [[0 for i in range(2)] for j in range(Q)]
ans = []
for i in range(Q):
    # lr[i][0], lr[i][1] = (int(x) for x in input().split())
    l, r = (int(x) for x in input().split())
    l -= 1
    r -= 1
    num = 0
    for j in range(l, r):
        if S[j:j+2] == 'AC':
            num += 1
    ans.append(num)
for i in range(Q):
    print(ans[i])