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()
ss = s
t = []
for i in range(s.count("AC")):
  t.append(ss.index("AC")+1)
  u = ss.index("AC")+2
  ss = 'Q'*u+ss[u:]
for i in range(q):
  l,r = map(int, input().split())
  print(len(["" for i in t if l <= i and i+1 <= r]))

Submission status: Time Limit Exceeded

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

def countAC(l, r):
    count = 0
    for i in range(l, r):
        if(S[i] == "A" and S[i+1] == "C"):
            count += 1
    return count

for i in range(Q):
    print(countAC(LR[i][0]-1, LR[i][1]-1))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
import numpy as np
input = sys.stdin.readline

N, Q = [int(i) for i in input().split()]
S = input()
is_AC = [S[i:i+2] == "AC" for i in range(N)]
AC_csum = np.cumsum(is_AC)

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

Submission status: Time Limit Exceeded

Solution code:
n, q = [int(i) for i in input().split()]
s = input()
for _ in range(q):
    l, r = [int(i) for i in input().split()]
    print(
        len([i for i in [a + b for a, b in zip(s[l-1: r-1], s[l: r+1])] if i == 'AC']))

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)]
ac_list = [1 if ''.join(s[i:i+2]) == 'AC' else 0 for i in range(len(s))]
for l,r in lr_list:
    print(sum(ac_list[l-1:r-1]))

Submission status: Time Limit Exceeded

Solution code:





N,Q = map(int,input().split())
S = []
for c in str(input()):
    S.append(c)


a = []
for i in range(N-1):
    if (S[i] == "A")and(S[i+1] == "C"):
        a.append(1)
    else:
        a.append(0)
for i in range(Q):
    l, r = map(int, input().split())
    print(sum(a[l-1:r-1]))

Submission status: Time Limit Exceeded

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

for i in range(1,len(S)+1):
    num=S[0:i].count('AC')
    num_count.append(num)
#print(num_count)
for j in range(Q):
    l,r=map(int,input().split())
    k=int(num_count[r-1])-int(num_count[l-1])
    print(k)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import math
import itertools
import re
import sys
sys.setrecursionlimit(10**8)
 
 
def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]
 
dp = {}
T = {}
 
def solve(input_string):
    S = input_string[1]
    intMatrix = makeIntMatrix(input_string[2:])
    #print(input_string[2:])
    for line in intMatrix:
        L, R = line
        #print(l, r)
        #print(S[l:r+1])
        #cnt = len(re.findall(r'AC', S[l-1:r]))
        D = R - L
        totalCnt = cntAC(R-1, R, D, S, 0)
        print(totalCnt)
    return
 

def cntAC(l, r, D, S, cnt):
    global dp
    global T
    if r-l == D+1:
        return cnt
    if str(l)+str(r) not in T:
        T[str(l)+str(r)] = S[l-1:r]
        t = T[str(l)+str(r)]
    if str(l)+str(r) not in dp:
        #print(t)
        dp[str(l)+str(r)] = len(t.split('AC'))-1
        cnt = dp[str(l)+str(r)]
        return cntAC(l-1, r, D, S, cnt)
    else:
        cnt = dp[str(l)+str(r)]
        return cntAC(l-1, r, D, S, cnt)
 
 
def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    #print(answer)
 
 
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N, Q = mi()
# print(N, Q)
S = li()
Alist = []
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        Alist.append(i)
AClist = [0]*(N+1)
for i in range(N - 1):
    if i in Alist:
        AClist[i + 2] = AClist[i+1] + 1
    else:
        AClist[i+2] = AClist[i+1]

# print(AClist)

for i in range(Q):
    l, r = mi()
    if AClist[l - 1] != AClist[l]:
        print(AClist[r] - AClist[l])
    else:
        print(AClist[r] - AClist[l-1])

Submission status: Time Limit Exceeded

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

ac_list  = [0]*N
for i in range(N-1):
    if S[i:i+2] == "AC":
        ac_list[i] = 1
        
for lr in lr_list:
    print(ac_list[lr[0] - 1:lr[1] - 1].count(1))

Submission status: Time Limit Exceeded

Solution code:
from sys import exit

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

S = input()

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

ans = []

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

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

Submission status: Time Limit Exceeded

Solution code:
import re
import sys
s = sys.stdin.readlines()
N, Q = map(int, s[0].split())
S = s[1]
acl = [0]*len(S)
ac_iter = re.finditer("AC", S)
for a in ac_iter:
    acl[a.span()[0]] = 1
for i in s[2:]:
    a, b = map(int, i.split())
    minus = 1 if acl[b-1] == 1 else 0
    print(sum(acl[a-1:b]) - minus)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
input = sys.stdin.readline

N, Q = [int(i) for i in input().split()]
S = input()
is_AC = [S[i:i+2] == "AC" for i in range(N)]

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N, Q = map(int, input().split())
S = input()
question_list = []

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

cut_s = S
index_list = []
for i in range(1, N):
    if S[i] == 'C' and S[i - 1] == 'A':
        index_list.append(i - 1)

for lr in question_list:
    l = lr[0]
    r = lr[1]
    num = 0
    for i in range(l - 1, r - 1):
        if i in index_list:
            num += 1
    print(num)

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(sum([substr[ind:ind+2] == "AC" for ind in range(r[ind]-l[ind]+1)]))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N, Q = mi()
# print(N, Q)
S = li()
Alist = []
l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i], r[i] = mi()
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        Alist.append(i)
AClist = [0]*(N+1)
for i in range(N - 1):
    if i in Alist:
        AClist[i + 2] = AClist[i+1] + 1
    else:
        AClist[i+2] = AClist[i+1]

# print(AClist)

for i in range(Q):
    if AClist[l[i] - 1] != AClist[l[i]]:
        print(AClist[r[i]] - AClist[l[i]])
    else:
        print(AClist[r[i]] - AClist[l[i]-1])

Submission status: Time Limit Exceeded

Solution code:
import re
if __name__ == '__main__':
  N, Q = map(int, input().split())
  l = input()
  m = re.finditer('AC', l)
  anslist = []
  for match in m:
    anslist.append(match.start())
  for i in range(Q):
    left, right = map(int, input().split())
    counter = 0
    for j in anslist:
      if j >= left-1 and j < right-1:
        counter += 1
      elif j >= right:
        break
    print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

N, Q = [int(i) for i in input().split()]
S = input()
is_AC = [S[i:i+2] == "AC" for i in range(N)]

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

Submission status: Time Limit Exceeded

Solution code:
import re
n, q = map(int,input().split())
s = input()
li = []
idx = -1

while True:
  idx = s.find('AC',idx+1)
  li.append(idx)
  if idx == -1:
    break
#print(li)
#cnt = 0
for i in range(q):
  cnt = 0
  l, r = map(int,input().split())
  for j in li:
    if j == -1:
      break
    elif l-1 <= j < r-1:
      cnt += 1
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,Q = (int(x) for x in input().split())
S = input()
tmp = []
for i in range(Q):
    a,b = (int(x) for x in input().split())
    tmp.append(S[a-1:b].count("AC"))
for j in range(Q):
    print(tmp[j])

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
ans = []
for _ 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:
# coding: utf-8

N, Q = [int(i) for i in input().split()]
S = input()
is_AC = [False] * N

for i in range(N):
  if S[i:i+2] == "AC":
    is_AC[i] = True

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

n = [int(i) for i in input().split()]
s = input()
t = [0] *(n[0])
for i in range(n[0]-2):
    
    if s[i:i+2] == "AC":
        t[i] = 1
        i += 1
    elif s[i+1:i+2] !="A":
        if s[i+2:i+3] !="A":
            i += 2
        else:
            i +=1      
for i in range(n[1]):
    m = [int(j) for j in input().split()]
    
    print(sum(t[j-1] for j in range(m[0],m[1])))

    """ a = 0
    for j in range(m[0],m[1]):
        a += t[j-1]"""

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N, Q = map(int, input().split())
S = input()
question_list = []

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

cut_s = S
index_list = []
while True:
    index = cut_s.find('AC')
    if index != -1:
        if index_list == []:
            index_list.append(index)
        else:
            index_list.append(index + index_list[-1] + 1)
        cut_s = cut_s[index + 1:]
    else:
        break

for lr in question_list:
    l = lr[0]
    r = lr[1]
    num = 0
    for i in range(l - 1, r - 1):
        if i in index_list:
            num += 1
    print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def solve(N, Q, S, L_R):
    answers = [0] * Q
    for i in range(len(S) - 1):
        if S[i] == "A" and S[i + 1] == "C":
            for j in range(len(L_R)):
                l, r = L_R[j]
                if l <= i + 1 < r:
                    answers[j] += 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, q = input().strip().split(' ')
n, q = [int(n), int(q)]
s = input()
index = -1
idxlist = []
cond = True
while cond:
        index = s.find('AC',index +1)
        if index == -1:
                cond = False
        else :
                idxlist.append(index)

for i in range(q):
        l, r = input().strip().split(' ')
        l, r = [int(l), int(r)]
        ans = len(idxlist)

        for j in range(len(idxlist)):
                if l > idxlist[j] + 1:
                       ans = ans - 1
                if r < idxlist[j] + 2:
                        ans = ans - 1
        print(ans)

Submission status: Time Limit Exceeded

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

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

lst = [0] * N
for i in range(int(N/2)):
    try:
        if S[i*2] == "C" and S[i*2-1] == "A":
            lst[i*2] = 1
        elif S[i*2] == "A" and S[i*2+1] == "C":
            lst[i*2+1] = 1
    except:
        continue

ans = 0
for i in range(Q):
    head,tail = map(int,input().split())
    ans = sum(lst[head:tail])
    print(ans)
    ans = 0

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N, Q = mi()
S = li()
Alist = []
l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i], r[i] = mi()
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        Alist.append(i)
AClist = [0]*(N+1)
for i in range(N - 1):
    if i in Alist:
        AClist[i + 2] = AClist[i+1] + 1
    else:
        AClist[i+2] = AClist[i+1]

# print(AClist)

for i in range(Q):
    if AClist[l[i] - 1] != AClist[l[i]]:
        print(AClist[r[i]] - AClist[l[i]])
    else:
        print(AClist[r[i]] - AClist[l[i]-1])

Submission status: Time Limit Exceeded

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

# In[78]:


N,Q=map(int,input().split())
S=input()
lr=[list(map(int,input().split())) for l in range(Q)]
ct=0
l=list()
import re
i = 0
pAC=re.compile("AC")
while i >= 0:
    m = pAC.search(S, i)
    if m:
        l.append(m.start()+1)
        #l.append(m.end())
        i = m.start() + 1
    else:
        break
#print(l)
for i in range(Q):
    print(sum(x >= lr[i][0] and x<lr[i][1] for x in l))


# In[ ]:

Submission status: Time Limit Exceeded

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

starts = [0 for k in range(q)]
ends = [0 for k in range(q)]
for i in range(q):
    starts[i], ends[i] = map(int, input().split())

target = 'AC'
index = -1
for i in range(q):
    index = starts[i]-2
    ans = 0
    while (index<ends[i]):
        index = s.find(target, index + 1)
        if index == -1:
            break
        elif index >= ends[i]-1:
            break
        else:
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

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

s_count_t = s.count("AC")

for _ in range(q):
    l, r = map(int, input().split())
    if l - r + 1 > len(s) // 2:
        s_count_before = s[:l].count("AC")
        s_count_after = s[r - 1:].count("AC")
        print(s_count_t - s_count_before - s_count_after)
    else:
        print(s[l - 1:r].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
l = []
r = []
n,q = input().split()
N = int(n)
Q = int(q)
S = input()
for i in range(Q):
    L,R = input().split()
    l.append(int(L)-1)
    r.append(int(R)-1)
for j in range(Q):
    count = 0
    for i in range(l[j],r[j]):
        if((S[i] == "A")&(S[i+1] == "C")):
            count = count + 1
    print(count)

Submission status: Time Limit Exceeded

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

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 = list(datalist[0])

data_new = []
flag = 0
for num in data:
    if num == 'A' and flag == 0:
        flag = 1
    elif num == 'C' and flag == 1:
        data_new.append(0.7)
        data_new.append(0.3)
        flag = 0
    elif flag == 1:
        data_new.append(0)
        data_new.append(0)
        flag = 0
    else:
        data_new.append(0)
        flag = 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 = int(sum(data_new[start:end]))
    if data_new[start] == 0.3:
        answer -= 1
    answer_list.append(answer)

for num in answer_list:
    print(num)

Submission status: Time Limit Exceeded

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


for i in range(q):
  h,f= map(int, input().split())
  sgt= s[h-1:f].replace('G',"").replace('T',"")
  print(sgt.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = list(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]]
    si2 = [n for n in si if n in ("A","C")]
    si3 = "".join(si2)
    so= si3.count("AC")
    cntli.append(so)

for p in cntli:
    print(p)

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

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]]
  f = False
  count = 0
  for n in s:
    if n == 'A':
      if not f:
        f = True
    elif n == 'C':
      if f:
        count += 1
        f = False
    else:
      f = False
  print(count)

Submission status: Time Limit Exceeded

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

s_count_t = s.count("AC")

for _ in range(q):
    l, r = map(int, input().split())
    if l - r + 1 < len(s) // 2:
        s_count_before = s[:l].count("AC")
        s_count_after = s[r - 1:].count("AC")
        print(s_count_t - s_count_before - s_count_after)
    else:
        print(s[l - 1:r].count("AC"))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#n=int(input())
#li=input().split()
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math

lis=[]
#N Q
li=list(map(int,input().split()))
S=input()
for i in range(li[1]):
    lr=list(map(int,input().split()))
    lis.append(lr)
L=[0]*(li[0]-1)
for i in range(li[0]-1):
    if S[i:i+2]=="AC":
        L[i]+=1
for i in range(li[1]):
    ans=sum(L[lis[i][0]-1:lis[i][1]-1])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sy = sys.stdin.readlines()
_,Q = map(int, sy[0].split())
S = sy[1]

for i in range(Q):
  l, r = map(int, sy[2+i].split())
  s = S[l-1:r]
  print(s.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import re
N, Q = (int(i) for i in input().split())
s = input()
lr = [[int(i) for i in input().split()] for i in range(Q)]
ms = re.finditer("AC", s)
ml = list(ms)
for i in range(Q):
    count = 0
    for j in range(len(ml)):
        a, b = ml[j].span()
        #print(a, b)
        #print("q", lr[i])
        if lr[i][0]-1 <= a and b <= lr[i][1]:
            count = count +1
            #print("counted")
        if lr[i][1] < a:
            break

    print(count)

Submission status: Time Limit Exceeded

Solution code:
""" AtCoder """

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

l = []
pos = 0

for i in range(N):
    if S[i] + S[i + 1] == "AC":
        l.append(1)
    else:
        l.append(0)

for i in range(Q):
    tmp = l[lr[i][0] - 1:lr[i][1]]
    ans = sum(tmp)
    if tmp[-1] == 1:
        ans -= 1
    print(ans)

Submission status: Time Limit Exceeded

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

S = input()
ls = []
for i in range(len(S)-1):
    if S[i]+S[i+1]=='AC':
        ls.append(1)
    else:
        ls.append(0)
ls.append(0)

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

Submission status: Time Limit Exceeded

Solution code:

n,q = map(int, input().split())
s = input()
a = [0 for i in range(q)]
for k in range(q):
    i,j = map(int, input().split())
    a[k] = [i,j]
for nums in a:
    check = s[nums[0]-1:nums[1]]
    count = 0
    for i in range(len(check)-1):
        if check[i]+check[i+1] == "AC":
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

a, b = map(int, input().split())

str = stdin.readline().rstrip()

k = 0

for i in range(b):
    k = 0
    c, d = map(int, input().split())
    arr = []
    snt = ""
    
    aaaa = str[c-1:d]

    for j in aaaa:
        snt = snt + j.replace('\n','')
        
        if len(snt)== 2:
            #print(snt)
            
            if snt == "AC":
                k = k + 1
            snt = snt[-1]
        
        else:
            snt = snt[-1]
            pass
        
    print(k)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
re = input()
res = list(map(str,re))
l = [0]*Q
r = [0]*Q
count = [0]*Q
for i in range(Q):
  l[i], r[i] = map(int, input().split())
  for j in range(l[i], r[i]):
    if res[j-1] == "A":
      if res[j] == "C":
             count[i] += 1
  print(count[i])

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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

for i in range(A[1]):
    Q = list(map(int, input().split(" ")))
    S = str[Q[0]-1:Q[1]]
    for j in range(len(S)):
        if S[j:j+2] == 'AC' :
            count = count+1
            J = j+1
    print(count)
    count = 0

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from sys import stdin

N, Q = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()

def func(Str):
  idx = Str.find("AC")
  return idx

i = 0
ac_idx = []
while i<N:
  a = func(S[i:])
  if a != -1:
    ac_idx.append(a+i)
    i = a+i+2
  else:
    break

ac_idx = np.array(ac_idx)
for j in range(Q):
  l,r = [int(x) for x in stdin.readline().rstrip().split()]
  print(np.sum((ac_idx>=l-1)&(ac_idx<r-1)))

Submission status: Time Limit Exceeded

Solution code:
import re
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(len(re.findall("AC", substr)))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
NQ = input().split(" ")
S = str(input())
N = int(NQ[0])
Q = int(NQ[1])
for dummy in range(0, Q):
  lr = input().split(" ")
  l = int(lr[0])
  r = int(lr[1])
  print(S[l-1:r].count("AC"))

Submission status: Time Limit Exceeded

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

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 = [i for i in range(len(s)) if s[i:i+2]=="AC"]
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()
for i in range(q):
    tmp = s
    list_q = list(map(int, input().split()))
    tmp = tmp[list_q[0]-1:list_q[1]]
    tmp = tmp.split("AC")
    print(len(tmp) - 1)

Submission status: Time Limit Exceeded

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

ACpos = []
i = 0
while(i < N - 1):
    if("AC" == S[i:i+2]):
        ACpos.append(i + 1)
        i += 1
    i += 1
#print("ACpos = {}".format(ACpos))

for idx in lr:
    cnt = 0
    for pos in ACpos:
        if((idx[0] <= pos) & (pos < idx[1])):
            cnt += 1
#    print("cnt = {}, idx = {}".format(cnt, idx))
    print(str(cnt))

Submission status: Time Limit Exceeded

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

AC_list = [0] * N
 
for i in range(N-1):
    if(S[i+1]=="C"):
        if(S[i]=="A"):
            AC_list[i] = 1

for i in range(Q):
    l, r = (int(_) for _ in input().split())
    if(AC_list[r-1]==1 and S[r]=="C"):
        print(sum(AC_list[l-1:r])-1)
    else:
        print(sum(AC_list[l-1:r]))

Submission status: Time Limit Exceeded

Solution code:
import sys

hajime = input().split(" ")
num = int(hajime[1])
word = input()

syori = [i for i in sys.stdin]

for i in syori:
  wakeru = i.split(" ")
  a = int(wakeru[0])
  b = int(wakeru[1])
  tmp = word[a-1:b]
  hikaku = tmp.replace("AC","")
  print(int((len(tmp)-len(hikaku))/2))

Submission status: Time Limit Exceeded

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

for i in range(Q):
    lr = input().split()
    tmp = S[int(lr[0])-1:int(lr[1])]
    j = -1
    for j, m in enumerate(re.finditer('AC', tmp)):
        pass
    j += 1
    print(str(j))

Submission status: Time Limit Exceeded

Solution code:
def have_AC(str):
    count=0
    for i in range(len(str)):
        if(str[i:i+2]=="AC"):
            count=count+1
    return count

n,q=input().split() #nは文字の長さ　qは質問数
s=input() #Sは文字列
n=int(n)
q=int(q)
num=[]

for i in range(q):
    a,b=input().split()
    a=int(a) -1
    b=int(b)
    num.append(have_AC(s[a:b]))

for j in range(len(num)):
    print(num[j])

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
Slis = [i for i in S]
output = []
for i in range(Q):
	l, r = map(int, input().split())
	Slr = Slis[l - 1:r]
	Slr = ''.join(Slr)
	output.append(Slr.count('AC'))
for i in output:
	print(i)

Submission status: Time Limit Exceeded

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

S = input()

for i in range(Q):
  inp = input().split(' ')
  li = int(inp[0]) - 1
  ri = int(inp[1]) - 1
  
  maxCnt = 0
  for j in range(li, ri):
    if S[j : j + 2] == "AC": maxCnt += 1
  
  print(maxCnt)

Submission status: Time Limit Exceeded

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

AC = []

for k in range(N-1):
    if (S[k] in "A") and (S[k+1] in "C"):
        AC.append(1)
    else:
        AC.append(0)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

res = [s[ls[i][0] - 1:ls[i][1]].count('AC') for i in range(q)]

for h in res:
  print(h)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

index = []
result = re.finditer('AC', S)
for r in result:
    index.append(r.start())

for i in range(Q):
    count = 0
    l, r = lr[i]
    for ind in index:
        if ind >= l-1 and ind <= r-2:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
def tonum(s):
    if s=='A':
        return 0
    if s=='C':
        return 1
    else:
        return 2

def count(S,l,r):
    s = S[l-1:r]
    ans=0
    for i in range(1,len(s)):
        if tonum(s[i])+tonum(s[i-1])==1 and s[i-1]=='A':
            ans+=1
    return ans
            
N,Q = map(int,input().split())
S=list(input())
li=[list(map(int,input().split())) for i in range(Q)]
for i in range(Q):
    print(count(S, li[i][0], li[i][1]))

Submission status: Time Limit Exceeded

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

T = list(S)
hoge = ""
cnt = 0

for i in range(Q):
    for k in range(lr[i][1] - lr[i][0]):
        if T[k + lr[i][0] - 1] == "A" and T[k  + lr[i][0]] == "C":
            cnt += 1
    print(cnt)
    hoge = ""
    cnt =0