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:
import numpy as np
from collections import Counter
import collections
import numpy as np 
from scipy import sqrt, power, exp, log10
from scipy.fftpack import fft, ifft, fftfreq
import tarfile
import re
import os
import glob
from datetime import datetime
import time
import numpy.linalg as LA

round = lambda x:(x*2+1)//2
a,b = list(map(int,input().split()))
S = input()
sub= "AC"
l = np.array([])
for i in range(len(S)):
  S1 = S[:i+1]
  l = np.append(l,S1.count(sub))
for i in range(b):
    r,t = list(map(int,input().split()))
    n = l[t-1]-l[r-1]
    print(int(n))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import Counter
import collections
import numpy as np 
from scipy import sqrt, power, exp, log10
from scipy.fftpack import fft, ifft, fftfreq
import tarfile
import re
import os
import glob
from datetime import datetime
import time
import numpy.linalg as LA
 
round = lambda x:(x*2+1)//2
a,b = list(map(int,input().split()))
S = input()
sub= "AC"
for i in range(b):
    r,l = list(map(int,input().split()))
    S1 = S[r-1:l]
    n = S1.count(sub)
    print(n)

Submission status: Time Limit Exceeded

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

for i in range(q):
  start,end = map(int,input().split())
  Q = ''.join([s[i] for i in range(start,end+1)])
  c=Q.count("AC")
  print(c)

Submission status: Time Limit Exceeded

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

for i in range(q):
  flag,c=0,0
  start,end = map(int,input().split())
  for j in range(start,end+1):
    if s[j]=='A':
      flag=1
    if flag==1 and s[j]=='C':
      c+=1
  print(c)

Submission status: Time Limit Exceeded

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

def cnt_AC(n):
    return S[0:n].count("AC")

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

Submission status: Time Limit Exceeded

Solution code:
class Test:
    def __init__(self):
        pass

class CustomUtils:
    def __init__(self):
        pass
    def to_int(self, inputs, sp=' '):
        if sp == '':
            return [int(d) for d in list(inputs)]
        else:
            # return map(int,input().split())
            return [int(d) for d in inputs.split(sp)]
    def debug_print(self, inputs, debug=False):
        if debug:
            print(inputs)

# 引用　python する man,「Pythonでの再帰関数とメモ化」, PSM, ２０１７、７/４
# http://muromura.hatenablog.com/entry/2017/07/04/204908#%E3%83%A1%E3%83%A2%E5%8C%96
def memorize(f):
    table = {}
    def func(*args):
        if not args in table:
            table[args] = f(*args)
        return table[args]
    return func
debug = False

u = CustomUtils()

n, q = u.to_int(input())
s = input()

import re
# カウントに関わる要素が同時に起こることはない（独立でもある。）
ss = []
es = []
# 文字列をreで
# 先に処理, 同じことをなんどもやらんですむように
m = re.finditer('AC', s)
for match in m:
    s, e= match.span()
    ss.append(s)
    es.append(e - 1)
ss.sort()
es.sort()

for _ in range(q):
    # n文字目とindexがずれた。
    l, r = [int(x)  - 1 for x in input().split()]
    total = len(ss)
    candidates = len([x for x in ss if l <= x])
    larger = len([x for x in es if r < x])
    result =  (candidates - larger) if (candidates - larger) > 0 else 0
    print("{}".format(result))

Submission status: Time Limit Exceeded

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

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

for j in range(q):
    l, r = map(int, input().split())
    n = [i for i in idx if ((i >= l) & (i < r))]
    print(len(n))

Submission status: Time Limit Exceeded

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


for left, right in arr:
    word = s[left - 1: right]
    ans = word.count('AC')
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
s = s.replace("AC", "12")
idx = [i+1 for i, x in enumerate(s) if x in "1"]

for j in range(q):
    l, r = map(int, input().split())
    n = [i for i in idx if ((i >= l) & (i < r))]
    print(len(n))

Submission status: Time Limit Exceeded

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

isAC = [0] * len(S)
for x in range(len(S) - 1):
    if S[x] == "A" and S[x + 1] == "C":
        isAC[x] = 1

for x in range(Q):
    ans = 0
    for y in range(l[x] - 1, r[x] - 1):
        ans += isAC[y]
    print(ans)

Submission status: Time Limit Exceeded

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

isAC = [0] * len(S)
for x in range(len(S) - 1):
    if S[x] == "A" and S[x + 1] == "C":
        isAC[x] = 1

for x in range(Q):
    ans = 0
    cut_isAC = isAC[l[x] - 1:r[x] - 1]
    for y in range(len(cut_isAC)):
        ans += cut_isAC[y]
    print(ans)

Submission status: Time Limit Exceeded

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

isAC = [False] * len(S)
for x in range(len(S) - 1):
    if S[x] == "A" and S[x + 1] == "C":
        isAC[x] = True

for x in range(Q):
    ans = 0
    cut_isAC = isAC[l[x] - 1:r[x] - 1]
    for y in range(len(cut_isAC)):
        if cut_isAC[y]:
            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())
    c = s[l-1:r]
    print((len(c)-len(c.replace("AC", "")))//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())
    c = s[l-1:r]
    print(int((len(c)-len(c.replace("AC", "")))/2))

Submission status: Time Limit Exceeded

Solution code:
class Test:
    def __init__(self):
        pass

class CustomUtils:
    def __init__(self):
        pass
    def to_int(self, inputs, sp=' '):
        if sp == '':
            return [int(d) for d in list(inputs)]
        else:
            # return map(int,input().split())
            return [int(d) for d in inputs.split(sp)]
    def debug_print(self, inputs, debug=False):
        if debug:
            print(inputs)

# 引用　python する man,「Pythonでの再帰関数とメモ化」, PSM, ２０１７、７/４
# http://muromura.hatenablog.com/entry/2017/07/04/204908#%E3%83%A1%E3%83%A2%E5%8C%96
def memorize(f):
    table = {}
    def func(*args):
        if not args in table:
            table[args] = f(*args)
        return table[args]
    return func
debug = False


u = CustomUtils()

n, q = u.to_int(input())
s = input()

import re

for _ in range(q):
    l, r = map(int,input().split())
#     文字列をreで
    result = len(re.findall('AC', s[l-1:r]))
    print("{}".format(result))

Submission status: Time Limit Exceeded

Solution code:
N, Q = list(map(int, input().split()))
S = input()
l = [0] * Q
r = [0] * Q
for x in range(Q):
    l[x], r[x] = list(map(int, input().split()))
for x in range(Q):
    s_tmp = S[l[x] - 1:r[x]]
    countAC = 0
    flag_A = False
    for y in range(len(s_tmp)):
        if flag_A and s_tmp[y] == 'C':
            countAC += 1
        if s_tmp[y] == 'A':
            flag_A = True
        else:
            flag_A = False
    print(countAC)

Submission status: Time Limit Exceeded

Solution code:

class Test:
    def __init__(self):
        pass

class CustomUtils:
    def __init__(self):
        pass
    def to_int(self, inputs, sp=' '):
        if sp == '':
            return [int(d) for d in list(inputs)]
        else:
            return [int(d) for d in inputs.split(sp)]
    def debug_print(self, inputs, debug=False):
        if debug:
            print(inputs)

# 引用　python する man,「Pythonでの再帰関数とメモ化」, PSM, ２０１７、７/４
# http://muromura.hatenablog.com/entry/2017/07/04/204908#%E3%83%A1%E3%83%A2%E5%8C%96
def memorize(f):
    table = {}
    def func(*args):
        if not args in table:
            table[args] = f(*args)
        return table[args]
    return func
debug = False



# REVIEW:
# re
# 文字列の先頭がパターンにマッチするかを調べるmatch()
# 先頭に限らずパターンにマッチするかを調べるsearch()
# マッチする部分すべてをリストで返すfindall()
# マッチする部分すべてをイテレータで返すfinditer()
# マッチした部分を置換するsub()、subn()
# パターンで文字列を分割するsplit()
# 正規表現オブジェクトをコンパイルするcompile()


u = CustomUtils()

n, q = u.to_int(input())
s = input()

import re

for _ in range(q):
    l, r = u.to_int(input())
#     文字列をreで
    result = len(re.findall('AC', s[l-1:r], re.IGNORECASE))
    print("{}".format(result))

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 = 0
    j = l - 1
    while j < r-1:
#        print("{} : {}".format(j,S[j:j+2]))
        if( S[j:j+2] == "AC"):
            count += 1
            j += 1
        j += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
acgt = ["A","C","G","T"]
N,Q = map(int, input().split())
S = input()
for i in range(Q):
    l, r = map(int, input().split())
#    print(S[l-1:r])
    flg_a = 0
    count = 0
    for j in range (l-1, r):
        if (flg_a == 1):
            flg_a = 0
            if(S[j] == "C"):
                count += 1
        if S[j] == "A":
            flg_a = 1
    print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

idxes = []
i = 0
while True:
  try:
    i = S.index('AC', i)
  except:
    break
  else:
    idxes.append(i)
    i += 2

# print(idxes)

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

  # Failed 1
  # print(S[l-1:r].count('AC'))

  # Failed 2
  # filtered = list(filter(lambda e: e >= l-1 and e <= r-2, idxes))
  # print(filtered)
  # print(len(filtered))

  count = 0
  for j in idxes:
    if j < l-1:
      continue
    elif j > r-2:
      break
    else:
      count += 1
  print(count)

Submission status: Time Limit Exceeded

Solution code:
word_number, questions_number = map(int, input().split())
# words = list(input())
words = input()
questions = []
for question in range(questions_number):
    a,b = map(int, input().split())
    questions.append([a-1, b-1])

for i in range(len(questions)):
    counter = 0
    for j in range(questions[i][0], questions[i][1]):
        # if words[j] == "A" and words[j+1] == "C":
        if words[j: j+2] == "AC":
            counter += 1
    print(counter)

Submission status: Time Limit Exceeded

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

idxes = []
i = 0
while True:
  try:
    i = S.index('AC', i)
  except:
    break
  else:
    idxes.append(i)
    i += 2

# print(idxes)

for i in range(Q):
  l, r = map(int, input().split())
  # print(S[l-1:r].count('AC'))
  filtered = list(filter(lambda e: e >= l-1 and e <= r-2, idxes))
  # print(filtered)
  print(len(filtered))

Submission status: Time Limit Exceeded

Solution code:
word_number, questions_number = map(int, input().split())
words = list(input())
questions = []
for question in range(questions_number):
    a,b = map(int, input().split())
    questions.append([a-1, b-1])

for i in range(len(questions)):
    counter = 0
    for j in range(questions[i][0], questions[i][1]):
        if words[j] == "A" and words[j+1] == "C":
            counter += 1
    print(counter)

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:
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = [int(x) for x in input().split()]
S = input().strip()
idx = [i for i in range(N - 1) if S[i:i+2] == 'AC']

for i in range(Q):
    l, r = [int(x) for x in input().split()]
    print(sum([i >= l - 1 and i <= r - 2 for i in idx]))

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = [int(x) for x in input().split()]
S = input().strip()
idx = [S[i:i+2] == 'AC' for i in range(N - 1)]

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

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = [int(x) for x in input().split()]
S = input().strip()

for i in range(Q):
    l, r = [int(x) for x in input().split()]
    print(sum([S[i:i+2] == 'AC' for i in range(l - 1, r - 1)]))

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = [int(x) for x in input().split()]
S = input().strip()

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

Submission status: Time Limit Exceeded

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

carsol = 0
for i in range(Q):
  counter = 0
  s = S[l[i]-1:r[i]]
  for j in range(len(s)-1):
    if s[j] + s[j+1] == "AC":
      counter += 1
  print(counter)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = [int(x) for x in input().split()]
S = input().strip()
l, r = [0] * Q, [0] * Q

for i in range(Q):
    l[i], r[i] = [int(x) for x in input().split()]

for i in range(Q):
    res = 0
    for j in range(l[i] - 1, r[i] - 1):
        if S[j:j+2] == 'AC':
            res += 1
    print(res)

Submission status: Time Limit Exceeded

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

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

for l,r in lr:
	print(cnts[r-1]-cnts[l-1])

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
li = [0 for _ in range(n+1)]

for i in range(n+1):
    li[i] = s[0:i].count("AC")

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

Submission status: Time Limit Exceeded

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

for i in range(q):
	a, b = map(int, input().split())
	cnt = 0
	x = 'C'
	for t in range(a-1, b):
		if x == 'A' and s_list[t] == 'C':
			cnt += 1
		x = s_list[t]
		if t == b-1:
			print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(Q):
  head, tail = (int(s) for s in input().split())
  sub_s = S[head-1:tail]
  n_ac = 0

  for n in range(len(sub_s)-1):
    ss = sub_s[n:n+2]
    if ss == 'AC':
      n_ac += 1

  print(n_ac)

Submission status: Time Limit Exceeded

Solution code:
import re
n, q = map(int, input().split())
s = input()
lrlist = []
for i in range(q):
    lrlist.append(list(map(int, input().split())))
    
for i in range(q):
    #print(s[lrlist[i][0] - 1 :lrlist[i][1]].count('AC'))
    print(len(re.findall('AC', s[lrlist[i][0] - 1 :lrlist[i][1]])))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
qs = []
n, q = map(int, input().split())
s = input()
for i in range(q):
    qs.append(list(map(int, input().split())))
for i in range(q):
    que = deque(maxlen = 2)
    cnt = 0
    l = qs[i][0]
    r = qs[i][1]
    for a in s[l-1: r]:
        que.append(a)
        if que == deque(['A', 'C']):
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
S = input()
ac_list = []
question_list = []
for i in range(len(S)+1):
    ac_list.append(S[:i].count("AC"))
for _ in range(q):
    l, r = map(int,input().split())
    question_list.append([l,r])
for l,r in question_list:
    print(ac_list[r]-ac_list[l])

Submission status: Time Limit Exceeded

Solution code:
n,q = [int(i) for i in input().split()]
s = input()
l = []
r = []
for i in range(q):
  l_tmp, r_tmp = [int(j) for j in input().split()]
  l.append(l_tmp-1)
  r.append(r_tmp-1)
  
ac_loc = []
flag = False
for i in range(n-1):
  if flag:
    flag = False
    continue
  if s[i:i+2] == 'AC':
    ac_loc.append(i)
    flag = True
ac_cnt = len(ac_loc)

up_cnt = []
down_cnt = []
for i in range(n):
  up_cnt.append(sum(i<=j for j in ac_loc))
  down_cnt.append(sum(j+1<=i for j in ac_loc))
  
for i in range(q):
  ans = up_cnt[l[i]] + down_cnt[r[i]] - ac_cnt
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
S = input()
question_list = []
for _ in range(q):
    l, r = map(int,input().split())
    question_list.append([l,r])
for l,r in question_list:
    print(S[l-1:r].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n,q = [int(i) for i in input().split()]
s = input()
ac_loc = []
flag = False
for i in range(n-1):
  if flag:
    flag = False
    continue
  if s[i:i+2] == 'AC':
    ac_loc.append(i)
    flag = True

l = []
r = []
for i in range(q):
  l_tmp, r_tmp = [int(j) for j in input().split()]
  l.append(l_tmp-1)
  r.append(r_tmp-1)
  
for i in range(q):
  ans = sum((l[i]<=j and j+1<=r[i]) for j in ac_loc)
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,q = [int(i) for i in input().split()]
s = input()
ac_loc = []
flag = False
for i in range(n-1):
  if flag:
    flag = False
    continue
  if s[i:i+2] == 'AC':
    ac_loc.append(i)
    flag = True

for i in range(q):
  l, r = [int(j) for j in input().split()]
  l -= 1
  r -= 1
  ans = sum((l<=j and j+1<=r) for j in ac_loc)
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,q = [int(i) for i in input().split()]
s = input()
ac_loc = []
for i in range(n-1):
  if s[i] =='A':
    if s[i+1] == 'C':
      ac_loc.append(i)
      i+=1 

for i in range(q):
  l, r = [int(j) for j in input().split()]
  l -= 1
  r -= 1
  ans = sum((l<=j and j+1<=r) for j in ac_loc)
  print(ans)

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(j) for j in input().split()]
  l -= 1
  r -= 1
  s_tmp = s[l:r+1]
  print(s_tmp.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
Q=input()
S="B"+input()+"B"
Q_num = Q.split(" ")[1]
query = []
for q in range(int(Q_num)):
  qu = input().split(" ")
  print(len(S[int(qu[0]):(int(qu[1])+1)].split("AC"))-1)

Submission status: Time Limit Exceeded

Solution code:
Q=input()
S="B"+input()+"B"
Q_num = Q.split(" ")[1]
query = []
for q in range(int(Q_num)):
  query.append(input().split(" "))
  
#下のforを上に統合可
for q in query:
  print(len(S[int(q[0]):(int(q[1])+1)].split("AC"))-1)

Submission status: Time Limit Exceeded

Solution code:
a,s=map(int,input().split())
l=list(input())
for i in range(s):
  p,q=map(int,input().split())
  c=0
  for o in range(p,q):
    if l[o-1]=="A" and l[o]=="C":
      c+=1
  print(c)

Submission status: Time Limit Exceeded

Solution code:
a,s=map(int,input().split())
l=list(input())
for i in range(s):
  p,q=map(int,input().split())
  c=0
  for o in range(p,q):
    if l[o-1]=="A" and l[o]=="C":
      c+=1
  print(c)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
in_str = input()
AC_count = []
r = []
for i in range(Q):
    in1, in2 = map(int, input().split())
    AC_count.append(in_str.count("AC", in1-1, in2))

for i in range(Q):
    print(AC_count[i])

Submission status: Time Limit Exceeded

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

for i in range(Q):
    in_str = in_str_root[l[i]-1:r[i]]
    AC = "AC"
    AC_count = in_str.count(AC)
    print(AC_count)

Submission status: Time Limit Exceeded

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

for i in range(Q):
    in_str = in_str_root[l[i]-1:r[i]]
    #print(in_str)
    AC_count = 0
    searching_a = 1
    searching_c = 0
    if len(in_str) <= 1:
        print(0)
    else:
        for j in range(len(in_str)-1):
            if in_str[j] == "A":
                if in_str[j+1] == "C":
                    AC_count += 1
        
        print(AC_count)

Submission status: Time Limit Exceeded

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

for i in range(Q):
    in_str = in_str_root[l[i]-1:r[i]]
    #print(in_str)
    AC_count = 0
    searching_a = 1
    searching_c = 0
    for j in range(len(in_str)):
        if searching_a == 1 and in_str[j] == "A":
            searching_a =0
            searching_c = 1
        elif searching_c == 1 and in_str[j] == "C":
            AC_count +=1
            searching_a =1
            searching_c = 0
        else :
            searching_a =1
            searching_c = 0
    print(AC_count)

Submission status: Time Limit Exceeded

Solution code:
import re

target = 'AC'

N, Q = map(int, input().split())  # 長さNとQ個の問い

S = str(input())  # 文字列S

starts_ends = []

for _ in range(Q):
    starts_ends.append(list(map(int, input().split())))

for i in range(Q):
    start, end = starts_ends[i]
    portion_S = S[start-1:end]
    print(len(re.findall('AC', portion_S)))

Submission status: Time Limit Exceeded

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

b, t = 0, [0]*N
v = S.find('AC', b)
while v != -1:
    t[v] = 1
    b += 2
    v = S.find('AC', b)

for i in range(Q):
  st = lr[i][0] - 1
  if S[st] == 'C':
    k = sum(t[st:lr[i][1]]) - 1
  else:
    k = sum(t[st:lr[i][1]])
  print(k)

Submission status: Time Limit Exceeded

Solution code:
import re

NQ = [int(i) for i in input().split()]
N = NQ[0]
Q = NQ[1]
S = input()
LR = [[int(i) for i in input().split()] for j in range(Q)]
check = [0] * (N - 1)
for i in range(N - 1):
    check[i] = 1 if S[i:i + 2] == "AC" else 0

for j in range(Q):
    print(sum(check[LR[j][0] - 1:LR[j][1] - 1]))

Submission status: Time Limit Exceeded

Solution code:
import re

NQ = [int(i) for i in input().split()]
N = NQ[0]
Q = NQ[1]
S = input()
check = [0] * (N - 1)
answer = []
for i in range(N - 1):
    check[i] = 1 if S[i:i + 2] == "AC" else 0


for j in range(Q):
    lr = [int(i) for i in input().split()]
    answer.append(sum(check[lr[0] - 1:lr[1] - 1]))

for s in answer:
    print(s)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(Q):
    counter = 0
    l = LRs[i][0] - 1
    r = LRs[i][1]-1
    s = S[l:r + 1] + 'end'
    for i in range(len(s)):
        if s[i - 1] == 'A' and s[i] == 'C':
            counter += 1
    print(counter)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n,q = map(int, input().split())
s = input()
lr = []
for i in range(q):
    tmp = list(int(i) for i in input().split())
    tmp[0] -= 1
    tmp[1] -= 1
    lr.append((tmp))
t = list(s)
acs = []
while not s.find('AC') == -1:
    id = s.find('AC')
    acs.append(id + len(acs) * 2)
    t.pop(id)
    t.pop(id)
    s = ''.join(t)

for i in range(q):
    l = lr[i][0]
    r = lr[i][1]
    li = bisect.bisect_left(acs,l)
    ri = bisect.bisect_right(acs,r)
    if ri > 0:
        if acs[ri-1] == r:
            ri -= 1
    print(ri-li)

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_res = s[l-1:r]
	count = 0
	for i, str in enumerate(s_res):
		if i == len(s_res) -1:
			break
		elif s_res[i] == 'A':
			if s_res[i+1] == 'C':
				count += 1
	print(count)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
#S = S_raw.replace('AC', 'XC')
l = [0] * Q
r = [0] * Q

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

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
l = [0] * Q
r = [0] * Q
keyword = 'AC'

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

for i in range(Q):
    sub_str = S[l[i]-1:r[i]]
#    print(sub_str)

    match = 0
    for j in range(len(sub_str)-1):
        two_char = sub_str[j:j+2]
        if two_char == keyword:
            match += 1
#        print('two char =', two_char)

    print(match)

Submission status: Time Limit Exceeded

Solution code:
def main():

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

    res = [None]*q

    for i in range(q):

        l, r = map(int, input().split())
        count = 0

        for point in range(l-1, r-1):
            if s[point:point+2] == 'AC':
                count += 1

        res[i] = count

    for i in range(q):
        print(res[i])


main()

Submission status: Time Limit Exceeded

Solution code:
sentence_len, request_len = map(int, input().split())
sentence = input()
answer_table = [0 for i in range(sentence_len)]
for i in range(sentence_len-1):
    if sentence[i] == 'A' and sentence[i+1] == 'C':
        answer_table[i+1] = 1

for i in range(request_len):
    start, end = map(int, input().split())
    start, end = start-1, end
    answer = sum(answer_table[start:end])
    if sentence[start] == 'C':
        answer -= 1
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
import re

NQ = [int(i) for i in input().split()]
N = NQ[0]
Q = NQ[1]
S = input()
index = 0
answer = []
while(Q > 0):
    lr = [int(i) for i in input().split()]
    l = lr[0]
    r = lr[1]
    new_str = S[l-1:r]
    answer.append(len(re.findall("AC",new_str)))
    Q -= 1
    index += 1

for s in answer:
    print(s)

Submission status: Time Limit Exceeded

Solution code:
import re

NQ = [int(i) for i in input().split()]
N = NQ[0]
Q = NQ[1]
S = input()
index = 0
answer = []
while(Q > 0):
    lr = [int(i) for i in input().split()]
    l = lr[0]
    r = lr[1]
    new_str = S[l-1:r]
    answer.append(len(re.findall("AC",new_str)))
    Q -= 1
    index += 1

index2 = 0
while(index > 0):
    print(answer[index2])
    index2 += 1
    index -= 1

Submission status: Time Limit Exceeded

Solution code:
sentence_len, request_len = map(int, input().split())
sentence = input()
rule = 'AC'
for i in range(request_len):
    start, end = map(int, input().split())
    start, end = start-1, end
    target_sentence = sentence[start:end]
    answer = target_sentence.count(rule)
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
S = input()
d = [0] * n
for i in range(n - 1):
        if S[i]+S[i + 1] == 'AC':
                d[i+1] += 1
for i in range(q):
        r,l = map(int,input().split())
        su = 0
        for j in range(r-1,l):
                su += d[j]
        print(su-d[r-1])

Submission status: Time Limit Exceeded

Solution code:
def solve(memo, left, right):
    count = 0
    for num in memo:
        if left <= num <= right:
            count += 1
    return count


def main():
    length, questions = map(int, input().split())
    string = input()

    memo = []
    for key in range(length - 1):
        if string[key:key+2] == "AC":
            memo.append(key + 1)

    for question in range(questions):
        left, right = map(int, input().split())
        right -= 1
        ans = solve(memo, left, right)
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

AC_list = []
for i in range(len(S)):
    if S[i:i+2] == "AC":
        AC_list.append(i)
    else:
        pass
    
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)