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

judge = 0
AC_list = []
for i in range(len(S)):
    if S[i] == "A":
        judge = 1
    elif S[i] =="C":
        if judge == 1:
            judge = 0
            AC_list.append(i-1)
        else:
            pass
    else:
        judge = 0
        
for i in range(Q):
    l, r = map(int,input().split())
    ans = 0
    for j in AC_list:
        if l-1 <= j <= r-2:
            ans += 1
        elif j > r-2:
            break
    print(ans)

Submission status: Time Limit Exceeded

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

judge = 0
AC_list = []
for i in range(len(S)):
    if S[i] == "A":
        judge = 1
    elif S[i] =="C":
        if judge == 1:
            judge = 0
            AC_list.append(i-1)
        else:
            pass
    else:
        judge = 0
        
for i in range(Q):
    l, r = map(int,input().split())
    ans = sum(l-1 <= j <= r-2 for j in AC_list)
    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[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):
    lq,rq = map(int,input().split())
    s = S[lq-1:rq]
    count = 0
    while(s.find('A') != -1):
        j = s.find('A')
        if(s[j:j+2] == 'AC'):
            count+=1
            s = s[j+2:]
        else:
            s = s[j+1:]
    print(count)

Submission status: Time Limit Exceeded

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

for i in range(Q):
    lq,rq = map(int,input().split())
    s = S[lq-1:rq]
    count = 0
    for j in range(len(s)):
        if(s[j:j+2] == 'AC'):
            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 i in range(q):
    p=s[lr[i][0]-1:lr[i][1]]
    print(p.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
def search_atcg(s, l, r):
    return s[l-1:r].count('AC')


if __name__ == "__main__":
    n, q = map(int, input().split(' '))
    s = input()
    answer = []
    for _ in range(q):
        l, r = map(int, input().split(' '))
        answer.append(search_atcg(s, l, r))
    for s in answer:
        print(s)

Submission status: Time Limit Exceeded

Solution code:
a,b=int(input().split()[1]),input();import re
for i in range(a):c=input().split();print(len(re.findall('AC',b[int(c[0])-1:int(c[1])])))

Submission status: Time Limit Exceeded

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

# -*- coding: utf-8 -*-

# -*- coding: utf-8 -*-
from sys import stdin

###########################################


############################################
#from sys import stdin
import numpy as np

# read data for n sequences.
data = stdin.readline().split()
N = int(data[0])
Q = int(data[1])

data = str(stdin.readline().split()[0])

question = []
for _ in range(Q):
    a = stdin.readline().split()
    question.append([int(a[0]), int(a[1])])
    
#for x in [2, 4, 8, 16, 32, 64, 128]:
cache = []
for i,q in enumerate(question):
    mydata = data
    b = q[0]-1
    e = q[1]
    count=0    
    if not i==0:
        for c in cache:
            if c[0]>b and c[1]==e:
                e = c[1]
                count += c[2]
            elif c[0]==b and c[1]<e:
                b = c[0]
                count += c[2]                
    prev=0
    for d in data[b:e]:
        if d=="C" and prev=="A":
            count+=1
        prev=d
    print(count)
    if count > 0:
        cache.append([q[0],q[1],count])

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
k = [0] * N
for i in range(1,N):
  v = 1 if S[i-1]+S[i] == 'AC' else 0
  k[i-1] = v
for _ in range(Q):
  f,l = map(int,input().split())
  print(sum(k[f-1:l-1]))

Submission status: Time Limit Exceeded

Solution code:
def checker(s):
  l,r = map(int,input().split())
  s = s[l-1:r]
  s = s.count('AC')
  print(s)

n,Q = map(int, input().split())
S = input()
for i in range(Q):
	checker(S)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

AC_list=[0]

for i in range(1,N):
  if (S[i-1]=='A')&(S[i]=='C'):
    AC_list.append(AC_list[i-1]+1)
  else:
    AC_list.append(AC_list[i-1])

for l in range(Q): 
  S,E=[int(x) for x in input().split()]
  
  print(max(AC_list[S-1:E])-min((AC_list[S-1:E])))

Submission status: Time Limit Exceeded

Solution code:
import re
r = re.compile("AC")

N, Q = input().split()
A = input()[:int(N)]


for i in range(int(Q)):
  s, e = input().split()
  a = A[int(s)-1:int(e)]
  print(len(r.findall(a)))

Submission status: Time Limit Exceeded

Solution code:
import re
r = re.compile("AC")

N, Q = input().split()
A = input()


for i in range(int(Q)):
  s, e = input().split()
  a = A[int(s)-1:int(e)]
  print(len(r.findall(a)))

Submission status: Time Limit Exceeded

Solution code:
(N_str, Q_str) = input().split()
N = int(N_str)
Q = int(Q_str)
S = input()
for abc in range(1, Q+1):
  (l_str, r_str) = input().split()
  l = int(l_str)
  r = int(r_str)
  substr = S[l-1:r]

  count = 0
  i = 0
  ln = len(substr)
  while i < ln:
    if substr[i] == 'A':
      i += 1	
      if i<ln and substr[i] == 'C':
        i += 1
        count += 1
    else:
      i += 1
  print(count)

Submission status: Time Limit Exceeded

Solution code:
(N_str, Q_str) = input().split()
N = int(N_str)
Q = int(Q_str)
S = input()
for i in range(1, Q+1):
  (l_str, r_str) = input().split()
  l = int(l_str)
  r = int(r_str)
  substr = S[l-1:r]

  count = 0
  for i in range(0, N):
    if substr[i:i+2] == 'AC':
      count += 1
  
  print(count)

Submission status: Time Limit Exceeded

Solution code:
def how_many_AC(count_summary, str):
  index = str.find('AC')
  if index == -1:
  	return (count_summary, "")
  else:
    return (count_summary+1, str[index+2:])

def how_many_AC_recursive(count1, str1):
  (count2, str2) = how_many_AC(count1, str1)
  if len(str2) <= 1:
    return count2
  else:
    x = how_many_AC_recursive(count2, str2)
    return x

import sys
sys.setrecursionlimit(10000000)
(N, Q) = input().split()
S = input()
for i in range(1, int(Q)+1):
  (l_str, r_str) = input().split()
  l = int(l_str)
  r = int(r_str)
  substr = S[l-1:r]
  out = how_many_AC_recursive(0, substr)
  print(out)

Submission status: Time Limit Exceeded

Solution code:
def how_many_AC(count_summary, str):
  index = str.find('AC')
  if index == -1:
  	return (count_summary, "")
  else:
    return (count_summary+1, str[index+2:])

def how_many_AC_facade(str1, N):
  count = 0
  str2 = str1
  for i in range(0, N-1):
    (count, str2) = how_many_AC(count, str2)
  return count
  
(N_str, Q_str) = input().split()
N = int(N_str)
Q = int(Q_str)
S = input()
for i in range(1, Q+1):
  (l_str, r_str) = input().split()
  l = int(l_str)
  r = int(r_str)
  substr = S[l-1:r]
  out = how_many_AC_facade(substr, N)
  print(out)

Submission status: Time Limit Exceeded

Solution code:
text_length, question_num = [int(i) for i in input().split()]

text = input()


"""
sliceを使用
"""

for _ in range(question_num):
    ran1, ran2 = [int(i) for i in input().split()]
    target = text[ran1 - 1:ran2]
    count = 0
    while True:
        if 'AC' in target:
            target = target.replace('AC', '', 1)
            count += 1
        else:
            break
    print(count)

Submission status: Time Limit Exceeded

Solution code:
text_length, question_num = [int(i) for i in input().split()]

text = input()


"""
sliceを使用
"""

for _ in range(question_num):
    ran1, ran2 = [int(i) for i in input().split()]
    target = text[ran1 - 1:ran2]
    count = 0
    exist = False
    if 'AC' in target:
        exist = True
    if exist:
        for i in range(len(target) - 1):
            if target[i] + target[i + 1] == 'AC':
                count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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

## S中で、'AC'であるインデックスを求める
index = [0] * N
i = 0
while i < len(S)-1:
    if S[i]=='A' and S[i+1]=='C':
        index[i] = 1
        i += 2
    else:
        i += 1

#print('\n')
#print(index)

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

Submission status: Time Limit Exceeded

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

## S中で、'AC'であるインデックスを求める
index = [0] * N
i = 0
while i < len(S)-1:
    if S[i]=='A' and S[i+1]=='C':
        index[i] = 1
        i += 2
    else:
        i += 1

#print('\n')
#print(index)

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

Submission status: Time Limit Exceeded

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

for i in qlist:
    tmp = S[i[0]-1:i[1]]
    print(tmp.count(AC))

Submission status: Time Limit Exceeded

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

for i in range(Q):
    s, e = map(int, input().split())
    qlist.append([s-1, e])

for i in qlist:
    tmp = S[i[0]:i[1]]
    print(tmp.count(AC))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S =  input()
qlist = []
AC = 'AC'
for i in range(Q):
    s, e = map(int, input().split())
    qlist.append([s-1, e])

for i in qlist:
    tmp = S[i[0]:i[1]]
    print(tmp.count(AC))

Submission status: Time Limit Exceeded

Solution code:
#encoding: utf-8

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


for i in range(q):
    l, r = list(map(int, input().split()))

    print(s[l - 1:r].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
def get_answer(a, start, end):
    if start == end:
        return 0
    return sum(a[start: end])

def create_answer_array(s):
    result = []
    for i, c in enumerate(s):
        if i == len(s) - 1:
            result.append(0)
        elif c == "A" and s[i + 1] == "C":
            result.append(1)
        else:
            result.append(0)

    return result

n, q = map(int, input().split())
s = str(input())
questions = []
for _ in range(q):
    a, b = map(int, input().split())
    questions.append((a - 1, b - 1))

a = create_answer_array(s)

for question in questions:
    print(get_answer(a, question[0], question[1]))

Submission status: Time Limit Exceeded

Solution code:
def get_answer(a, start, end):
    if start == end:
        return 0
    return sum(a[start: end])

def create_answer_array(s):
    result = []
    for i, c in enumerate(s):
        if i == len(s) - 1:
            result.append(int(0))
        elif c == "A" and s[i + 1] == "C":
            result.append(int(1))
        else:
            result.append(int(0))

    return result

n, q = map(int, input().split())
s = str(input())
questions = []
for _ in range(q):
    a, b = map(int, input().split())
    questions.append((a - 1, b - 1))

a = create_answer_array(s)

for question in questions:
    print(get_answer(a, question[0], question[1]))

Submission status: Time Limit Exceeded

Solution code:
def get_answer(s):
    count = 0
    for i, c in enumerate(s):
        if i == len(s) - 1:
            return count
        if c == "A" and s[i + 1] == "C":
            count += 1

    return count

n, q = map(int, input().split())
s = str(input())
questions = []
for _ in range(q):
    a, b = map(int, input().split())
    questions.append((a - 1, b - 1))

for question in questions:
    print(get_answer(s[question[0]: question[1] + 1]))

Submission status: Time Limit Exceeded

Solution code:
import re

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

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

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())
    cnt =  s.count('AC',l-1,r)
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
Raw = input().split(' ')
N, Q = int(Raw[0]), int(Raw[1])
s = input()
for _ in range(Q):
  Raw = input().split(' ')
  L, R = int(Raw[0]) - 1, int(Raw[1])
  print(s[L:R].count('AC'))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
s_len, q_qua = map(int, input().split())
s = input()
res = []

def count_ac(s):
    c = 0
    for i in range(len(s)-1):
        if s[i] == "A" and s[i+1] == "C":
            c += 1
    return c

for _ in range(q_qua):
    b, e = map(int, input().split())
    res.append(count_ac(s[b-1:e]))

[print(i) for i in res]

Submission status: Time Limit Exceeded

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

for i in range(Q):
    cnt = 0
    flag = 0
    n = r[i]-l[i]+1
    rfix = l[i]-1
    for j in range(n):
        if flag==1 and S[rfix+j]=='C':
            cnt+=1
        if S[rfix+j]=='A':
            flag = 1
        else:
            flag = 0
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s_len, q_qua = map(int, input().split())
s = input()

def count_ac(s):
    if len(s) <= 1:
        return 0
    c = 0
    for i in range(len(s)-1):
        if s[i] == "A" and s[i+1] == "C":
            c += 1
    return c

for _ in range(q_qua):
    b, e = map(int, input().split())
    res = count_ac(s[b-1:e])
    print(res)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a, loop = input().split()
string = input()

import re
for i in range(int(loop)):
  j, k = input().split()
  #print(string[int(j)-1:int(k)].count('AC'))  # TLE
  print(len(re.findall('AC', string[int(j)-1:int(k)])))

Submission status: Time Limit Exceeded

Solution code:
a, loop = input().split()
string = input()

for i in range(int(loop)):
  j, k = input().split()
  print(string[int(j)-1:int(k)].count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = list(map(int, input().split()))
S = input()
for q 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()
for i in range(q):
    si,ei=map(int,input().split())
    print(s[si-1:ei].count("AC"))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, q = list(map(int, input().split(" ")))
s = input()
s = s.replace("AC", "ZC")
ac_index = [s[:i].count("Z") for i in range(len(s))]
num = 0
for _s in s:
    if _s == "Z":
        num += 1
    ac_index.append(num)

i = 0

for _ in range(q):
    l, r = list(map(int, input().split(" ")))
    print(ac_index[r-1] - ac_index[l-1])

Submission status: Time Limit Exceeded

Solution code:
n, q = list(map(int, input().split(" ")))
s = input()
s = s.replace("AC", "ZC")
ac_index = [s[:i].count("Z") for i in range(len(s))]
i = 0

for _ in range(q):
    l, r = list(map(int, input().split(" ")))
    print(ac_index[r-1] - ac_index[l-1])

Submission status: Time Limit Exceeded

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

index = {i for i in range(N-1) if (S[i] == 'A') and (S[i+1] == 'C')}

for i in range(Q):
  l, r = T[i][0], T[i][1]
  print(len(index & set(range(l-1, r-1))))

Submission status: Time Limit Exceeded

Solution code:
n, q = list(map(int, input().split(" ")))
s = input()
s = s.replace("AC", "Z")
ac_index = []
i = 0
for _s in s:
    if _s == "Z":
        ac_index.append(i)
        i += 2
    else:
        i += 1
for _ in range(q):
    l, r = list(map(int, input().split(" ")))
    print(len([x for x in ac_index if l - 1 <= x <= r - 2]))

Submission status: Time Limit Exceeded

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

index = {i for i, X in enumerate(S) if X == 'A'}

for i in range(Q):
  l, r = T[i][0], T[i][1]
  count = 0
  index1 = index & set(range(l-1, r-1))
  for j in index1:
    if S[j+1] =='C':
      count += 1
  print(count)

Submission status: Time Limit Exceeded

Solution code:
def count_ac(string):
    return string.replace("AC", "Z").count("Z")

n, q = list(map(int, input().split(" ")))
s = input()
for _ in range(q):
    l, r = list(map(int, input().split(" ")))
    print(count_ac(s[l-1: r]))

Submission status: Time Limit Exceeded

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

for i in range(Q):
  l, r = T[i][0], T[i][1]
  s = S[l-1:r]
  count = 0
  if r-l == 0:
    count = 0
  else:
    for j in range(r-l):
      if s[j] == 'A' and s[j+1] == 'C':
        count += 1
  print(count)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
point = [list(map(int,input().split())) for i in range(Q)]
ac_list = [0]*N
for i in range(N-1):
  if S[i] == 'A' and S[i+1] == 'C':
    ac_list[i] = 'a'
#print(ac_list)
for i in range(Q):
  print(ac_list[point[i][0]-1:point[i][1]-1].count('a'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = input()
st = input()

N = n.split(' ')[0]
Q = int(n.split(' ')[1])

for i in range(0, Q):
    n = input()
    l = int(n.split(' ')[0])
    r = int(n.split(' ')[1])
    partial = st[l-1:r]
    count = 0
    for i in range(0, len(partial) - 1):
        if partial[i] != 'A':
            continue

        AC = partial[i:i+2]
        if AC == 'AC':
            count += 1

    print(count)

Submission status: Time Limit Exceeded

Solution code:
n = input()
st = input()

N = n.split(' ')[0]
Q = int(n.split(' ')[1])

for i in range(0, Q):
    n = input()
    l = int(n.split(' ')[0])
    r = int(n.split(' ')[1])
    partial = st[l-1:r]
    count = 0
    for i in range(0, len(partial) - 1):
        AC = partial[i:i+2]
        if AC == 'AC':
            count += 1

    print(count)

Submission status: Time Limit Exceeded

Solution code:
n = input()
st = input()

N = n.split(' ')[0]
Q = int(n.split(' ')[1])

for i in range(0, Q):
    n = input()
    l = int(n.split(' ')[0])
    r = int(n.split(' ')[1])
    partial = st[l-1:r]
    count = 0
    while partial.find('AC') != -1:
        partial = partial.replace('AC', '', 1)
        count += 1
    print(count)

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()
for i in range(Q):
	l, r = map(int, input().split())
	S_part = S[(l-1):r]
	print(S_part.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())
	S_part = S[(l-1):r]
	count = 0
	while 'AC' in S_part:
		S_part = S_part.replace('AC', '', 1)
		count += 1
	print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for q in range(Q):
    l, r = list(map(lambda x: int(x), 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 = input()
#文字列のパターン
pattern = 'AC'

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

Submission status: Time Limit Exceeded

Solution code:
N,M=list(map(int,input().split(" ")))
str=input()
for i in range(M):
  start,finish=list(map(int,input().split(" ")))
  temp=str[start-1:finish]
  print(temp.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import re
N,Q = list(map(int,input().split(" ")))
S = input()
l = {}
r = {}
for i in range(Q):
    l[i],r[i] = list(map(int,input().split(" ")))

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

Submission status: Time Limit Exceeded

Solution code:
N,Q = list(map(int,input().split(" ")))
S = input()
l = {}
r = {}
for i in range(Q):
    l[i],r[i] = list(map(int,input().split(" ")))

answer = 0
answers = []

for i in range(Q):
    answer = 0
    M = 0
    while True:
        if "AC" in S[l[i]-1+M:r[i]]:
            answer += 1
            M += S[l[i]-1:r[i]].find("AC")+2
            continue
        break
    answers.append(answer)

for i in answers:
    print(i)

Submission status: Time Limit Exceeded

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

ans=[0]*n
for i in range(n-1):
    if s[i:i+2]=='AC':
        ans[i:i+2]=[1,2]

for i in range(q):
    l,r=map(int,input().split())
    cnt=0
    for j in range(l-1,r-1):
        if ans[j:j+2]==[1,2]:
            cnt+=1
    print(cnt)

Submission status: Time Limit Exceeded

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

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]"):
    dp = [[None for j in range(N)] for i in range(N)]
    for i in range(0, N-1):
        if S[i] == 'A' and S[i+1] == 'C':
            dp[i][i+1] = 1
        else:
            dp[i][i+1] = 0
    def count(li, ri):
        assert li >= 0 and ri >= 0, "li or ri < 0"
        if dp[li][ri] is not None:
            return dp[li][ri]
        else:
            c = count(li, ri-1) + count(ri-1, ri)
            dp[li][ri] = c
            return c
    for q in range(Q):
        print(count(l[q] - 1, r[q] - 1))

    return


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 = list(map(int,input().split(" ")))
S = input()
l = {}
r = {}
for i in range(Q):
    l[i],r[i] = list(map(int,input().split(" ")))

answer = 0
answers = []

for i in range(Q):
    answer = 0
    for k in range(r[i]-l[i]):
        if S[l[i]-1+k] == "A" and S[l[i]+k] == "C":
            answer += 1
    answers.append(answer)

for i in answers:
    print(i)

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())
    # spl = S[l - 1:r].split("AC")
    # print(len(spl) - 1)
    print(S.count("AC", l-1, r))

Submission status: Time Limit Exceeded

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

ac_flag = [0] * len(S)

for i in range(len(S)-1):
    if S[i: i + 2] == 'AC':
        ac_flag[i] = 1

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

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
answer_list=[]
word_list=list(S)
for i in range(Q):
  count=0
  flag =0
  l,r=map(int,input().split())
  box=word_list[l-1:r]
  if len(box)==0:
      count=0
  else:
      for i in box:
        if i == 'A':
          flag =1
        elif i!= 'C':
          flag=0
        elif flag == 0 and i=='C':
          flag = 0
        elif flag == 1 and i =='C':
          count += 1
          flag = 0
  answer_list.append(count)
for i in answer_list:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
answer_list=[]
word_list=list(S)
for i in range(Q):
  count=0
  flag =0
  l,r=map(int,input().split())
  box=word_list[l-1:r]
  for i in box:
    if i == 'A':
      flag =1
    elif i!= 'C':
      flag=0
    elif flag == 0 and i=='C':
      flag = 0
    elif flag == 1 and i =='C':
      count += 1
      flag = 0
  answer_list.append(count)
for i in answer_list:
  print(i)

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()
lst = []
for _ in range(Q):
    lst.append(list(map(int, input().split())))
# print(lst)
for each in lst:
    spl = S[each[0] - 1:each[1]].split("AC")
    print((len(spl) - 1))

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())
    spl = S[l - 1:r].split("AC")
    ans.append(len(spl) - 1)
for i in ans:
    print(i)

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())
    # print(S[l - 1:r])
    spl = S[l - 1:r].split("AC")
    print(len(spl)-1)
    # for num in range(l, r):
    #     # print(S[num-1:num + 1])
    #     if S[num-1:num + 1] == "AC":
    #         count += 1
    # print(count)

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())
    for num in range(l, r):
        # print(S[num-1:num + 1])
        if S[num-1:num + 1] == "AC":
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
answer_list=[]
word_list=list(S)
for i in range(Q):
  count=0
  flag =0
  l,r=map(int,input().split())
  box=word_list[l-1:r]
  for i in box:
    if i == 'A':
      flag =1
    elif i!= 'C':
      flag=0
    if flag == 0 and i=='C':
      flag = 0
    if flag == 1 and i =='C':
      count += 1
      flag = 0
  answer_list.append(count)
for i in answer_list:
    print(i)

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:
    l, r = lr[0], lr[1]
    s = S[l-1: r]
    i = 0
    I = len(s)
    cnt = 0
    while i < len(s) - 1 :
        if s[i] == "A" and s[i + 1] == "C":
            cnt += 1
            i += 2
        else:
            i += 1
    #cnt = s.count("AC")
    print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        t[i] = 1

for i in range(Q):
    kazu = t[li[i][0] - 1 : li[i][1] -1]
    print(kazu.count(1))