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:
def countAC(s):
    index = []
    for i in range(N-1):
        if s[i] == 'A':
            if s[i+1] == 'C':
                index.append(1)
                continue
        index.append(0)
    return index

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

Submission status: Time Limit Exceeded

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

l=[[int(x) for x in input().split()] for _ in range(q)]

flag=False

for i in range(q):
    count=0
    ss=s[l[i][0]-1:l[i][1]]
    for i in ss:
        if i=='A':
            flag = True
        elif i =='C'and flag:
            count+=1
            flag=False
        else:
            flag=False
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N, Q = list(map(int, input().split()))
S = input()
ans = ''
for i in range(Q):
    l, r = list(map(int, input().split()))
    ans += str(S.count('AC', l-1, r)) + '\n'
print(ans, end='')

Submission status: Time Limit Exceeded

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

a_loc = set()
for i in range(len(S)):
    if S[i:i+2] == 'AC':
        a_loc.add(i)
ans = []
for i in range(Q):
    l, r = (int(x) for x in input().split())
    num = 0
    for j in range(l-1, r-1):
        if j in a_loc:
            num += 1
    ans.append(num)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
N,Q = map(int,sys.stdin.readline().split())
S = sys.stdin.readline()
f_string = "AC"
for i in range(Q):
    l,r = map(int,sys.stdin.readline().split())
    temp = S[l-1:r]
    print(temp.count(f_string))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def print_list(n, s, list_q):
    list_q[1] = n - list_q[1]
    for i in range(list_q[0] - 1):
        s = s[1:]
    for i in range(list_q[1]):
        s = s[:-1]
    s = s.split("AC")
    print(len(s) - 1)


n, q = map(int, input().split())
s = input()
for i in range(q):
    print_list(n, s, list(map(int, input().split())))

Submission status: Time Limit Exceeded

Solution code:
import re

i = int(input().split()[1])
s = input()
k = 0
result = []

while k < i:
    ft, et = map(int, input().split())
    result.append(s[ft - 1:et].count("AC"))
    #result.append(len(re.findall("AC", s[ft - 1:et])))
    k += 1

for kekka in result:
    print(kekka)

Submission status: Time Limit Exceeded

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

for j in range(Q):
    count = 0
    start = qa[j][0]-1
    end = qa[j][1]
    string = S[start:end]
    for i in range(len(string)-1):
        if string[i:i+2] == "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):
    l, r = map(int, input().split())
    print(S[l - 1:r].count("AC"))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
si = S.replace("AC","11")
si = si.translate(str.maketrans({"T":"0","G":"0","A":"0","C":"0"}))
for q in range(Q):
  l, r = map(int, input().split())
  if l>=2 and S[l-2:l]=="AC" and S[r-1:r+1]=="AC":
    print(int((sum(map(int,list(si[l-1:r])))-2)/2))
  elif l>=2 and S[l-2:l]=="AC":
    print(int((sum(map(int,list(si[l-1:r])))-1)/2))
  elif S[r-1:r+1]=="AC":
    print(int((sum(map(int,list(si[l-1:r])))-1)/2))
  else:
    print(int(sum(map(int,list(si[l-1:r])))/2))

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline

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

syori = [input() for i in range(num)]

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

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())
counter=[1 if (S[i]=="A")and(S[i+1]=="C") else 0 for i in range(len(S)-1)]
counter+=[0]
for j in range(Q):
  print(sum(counter[l[j]-1:r[j]-1]))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
S = input()
lr = [[int(i) for i in input().split()] for i in range(Q)]
C = []
for i in range(N-1):
    if S[i] == "A":
        if S[i+1] == "C":
            C.append(i)
for l,r in lr:
    AC = 0
    for j in C:
        if j >= l-1:
            if j < r-1:
                AC += 1
            else:
                break
    print(AC)

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 j in range(lr[i][1] - lr[i][0]):
        hoge += S[j]
    for k in range(len(list(hoge)) - 1):
        if hoge[k] == "A" and hoge[k + 1] == "C":
            cnt += 1
    print(cnt)
    hoge = ""
    cnt =0

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
l_li=[]
r_li=[]
for i in range(q):
    l,r=map(int,input().split())
    l_li.append(l)
    r_li.append(r)
    
dp =[[0 for i in range(n+2)] for j in range(n+2)]

for i in range(1):
    for j in range(i,n):
        t=0
        if s[j]=="C" and j!=i:
            if s[j-1]=="A":
                t=1
        
        dp[i][j]=dp[i][j-1]+t
        
for i in range(1,n):
    t=0
    if s[i]=="C" and s[i-1]=="A":   
        dp[i]=list(map(lambda x: x-1,dp[i-1]))
    else:
        dp[i]=dp[i-1]        
        
        
for i in range(q):
    print(dp[l_li[i]-1][r_li[i]-1])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
NQ = input().split(" ")
S = str(input())
N = int(NQ[0])
Q = int(NQ[1])
result_list = []

for i in range(0, Q):
  lr = input().split(" ")
  l = int(lr[0])
  r = int(lr[1])
  subStr_S = str(S[l-1:r])
  result_list.append(subStr_S.count("AC"))

for result in result_list:
  print(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())
  l -= 1
  print(s[l: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())
    m=0
    for j in range(l-1,r-1):
            if s[j]=="A" and s[j+1]=="C":
                m+=1
    print(m)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n, q = [int(elem) for elem in input().split()]
s = input()
new_s = [0]
for st1, st2 in zip(s[:-1], s[1:]):
    if st1 == "A" and st2 == "C":
        new_s.append(1)
    else:
        new_s.append(0)

out = []
for i in range(0, q):
    l, r = [int(elem) for elem in input().split()]
    out.append(sum(new_s[0:r]) - sum(new_s[0:l]))  

for elem in out:
    print(elem)

Submission status: Time Limit Exceeded

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

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

cl = [0 for i in range(len(S))]

for i in range(1,len(S)):
    if S[i] == 'C' and S[i-1] == 'A':
        cl[i] = cl[i-1] + 1
    else:
        cl[i] = cl[i-1]


#print(cl) 
#print(S)

for l,r in lr:
    sub = cl[l-1:r]
    res = cl[r-1] - cl[l-1] 
    print(res)

Submission status: Time Limit Exceeded

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

for i in range(Q):
    count = 0
    for j in range(pos_list[i][0], pos_list[i][1]):
        if "AC" == S[j-1:j+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):
    a, b = map(int, input().split())
    seq = S[a-1:b]
    seq2 = seq.replace("AC","")
    ans = (len(seq) - len(seq2)) / 2
    print(int(ans))

Submission status: Time Limit Exceeded

Solution code:

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

length = len(lrs)
count = [0] * length
for i in range(len(S) - 1):
    if S[i] != 'A':
        continue
    if S[i+1] != 'C':
        continue
    for j in range(length):
        if lrs[j][0] <= i+1 and i < lrs[j][1] and i+1 != lrs[j][1]:
            count[j] += 1

for c in count:
    print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re

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

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

# ACの場所を探す
p_list = [0] * (N - 1)
i = 0
while i < N - 1:
    if S[i:i + 2] == "AC":
        p_list[i] = 1
        i += 2
    else:
        i += 1

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

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

Submission status: Time Limit Exceeded

Solution code:

import sys
input = sys.stdin.readline
def C():
    N, Q = input().split()
    N = int(N)
    Q = int(Q)
    S = input()

    ans = []
    ac = 'AC'
    for q in range(Q):
        lq, rq = input().split()
        S_sub = S[int(lq) -1 : int(rq)]
        ans.append(str(S_sub.count(ac)) + '\n')

    # solve
    print(''.join(ans), end="")
            


if __name__ == '__main__':
    C()

Submission status: Time Limit Exceeded

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

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 in range(l-1, r-1):
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
nq=input().split()
N=int(nq[0]);Q=int(nq[1])
S=input()
ls=[];rs=[]
for i in range(Q):
    lr=input().split()
    l=int(lr[0]);r=int(lr[1])
    ls.append(l)
    rs.append(r)
for j in range(Q):
    s=S[(ls[j]-1):(rs[j])]
    n=0
    a=False
    for k in s:
        if k=="A":
            a=True
        elif a:
            if k=="C":
                n+=1
            else:
                a=False
        else:
            pass
    print(n)

Submission status: Time Limit Exceeded

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

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):
    l1, r1 = [int(i) for i in input().split()]
    l.append(l1)
    r.append(r1)

for j in range(Q):
    U = S[l[j]-1:r[j]]
    T = U[1:]
    u = [U[i: i+2] for i in range(0, len(U), 2)]
    t = [T[i: i+2] for i in range(0, len(T), 2)]
    f = u +[0]+ t
    print(f.count('AC'))

Submission status: Time Limit Exceeded

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

n,q=map(int,input().split())
s=input()
lr=[input() for __ in range(q)]

ans=[]

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

print('\n'.join(ans))

Submission status: Time Limit Exceeded

Solution code:
def MKNUMBER(S,l,r):
    slice = S[l-1:r]
    A=list(slice)
    number=[]
    for i in A:
        if i == "A":
            number.append(1)
        elif i == "C":
            number.append(2)
        else:
            number.append(0)
    return(number)
  
def countAC(number):
    count = 0
    flg = 0
    for i in number:
        if i == 0:
            flg = 0
        if i == 1:
            flg = 1
        if i == 2:
            if flg == 1:
                count = count + 1
            flg = 0
    print(count) 
    
N,Q = input().split()
N = int(N)
Q = int(Q)
S = input()

for i in range(0,Q):
    l,r = input().split()
    l = int(l)
    r = int(r)
    number = MKNUMBER(S,l,r)
    countAC(number)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, q = map(int, input().split())
s = input()

mask = np.zeros(n)
for i in range(n-1):
  if s[i:i+2] == "AC":
    mask[i:i+2] = 1

for _ in range(q):
  a, b = map(int, input().split())
  if s[a-1] == "C" and s[b-1] == "A":
    print(int((np.sum(mask[a-1:b]) - 2)/ 2))
  elif s[a-1] == "C" or s[b-1] == "A":
    print(int((np.sum(mask[a-1:b]) - 1)/ 2))
  else:
    print(int((np.sum(mask[a-1:b]))/ 2))

Submission status: Time Limit Exceeded

Solution code:
def main():
    line = input()
    line = line.split(' ')
    n = int(line[0])
    q = int(line[1])
    s = input()
    for i in range(0,q):
        line = input() 
        line = line.split(' ')
        print(find_ac(s[int(line[0])-1:int(line[1])]))

def find_ac(s):
    cnt = 0
    b_s2 = 'B'
    if len(s)%2 != 0:
        s = s+'B'
    for s1, s2 in zip(s[0::2],s[1::2]):
        if s1 == 'A' and s2 == 'C':
            cnt += 1
        if b_s2 == 'A' and s1 == 'C':
            cnt += 1
        b_s2 = s2

    return cnt

main()

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
l,r=[],[]
for i in range(Q):
    l0,r0=map(int,input().split())
    l.append(l0)
    r.append(r0)
c=[]
for i in range(N):
    c.append(0)
for i in range(N-1):
    if (S[i]=='A') and (S[i+1]=='C'):
        c[i]+=1
for i in range(Q):
    print(sum(c[l[i]-1:r[i]-1]))

Submission status: Time Limit Exceeded

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

cntli = []
for i in range(q):
    si = s[lr[i][0]-1:lr[i][1]]
    si.strip("G")
    si.strip("T")
    cntli.append(si.count("AC"))

for p in cntli:
    print(p)

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())
    for j in range(l-1,r-1):
        if s[j:j+2] == "AC":
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, q = map(int, input().split())
s = input()
L = np.array([0]*n)
for i in range(n-1):
    if(s[i:i+2] == 'AC'):
        L[i] = 1
for i in range(q):
    l, r = map(int, input().split())
    print(np.sum(L[l-1:r-1]))

Submission status: Time Limit Exceeded

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

for i in range(Q):
    l, r = map(int, input().split())
    bubun = S[l - 1:r]
    cnt = 0
    for j in range(len(bubun)):
        if j >= len(bubun) or j + 1 >= len(bubun):
            continue
        elif bubun[j] == "A" and bubun[j + 1] == "C":
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import re
pattern = r"AC"
N, Q = map(int, input().split(" "))
T = input()

for q in range(Q):
    i = 0
    count = 0
    start, end = map(int, input().split(" "))
    while True:
        m = re.search(pattern, T[start-1+i:end])
        if m:
            count += 1
            i += int(m.end())
        else:
            break
    print(count)

Submission status: Time Limit Exceeded

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


lst = [0] * N

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

ans = 0
for i in range(Q):
    ans = sum(lst[index[i][0]-1:index[i][1]])
    if lst[index[i][0]-1] == 1:
        ans -= 1
    print(ans)
    ans = 0

Submission status: Time Limit Exceeded

Solution code:
import re
num,que = map(int,input().split(" "))
word = input()

for i in range(que):
    s,e = map(int,input().split(" "))
    ex_word = word[s-1:e]
    answer = len(re.findall("AC",ex_word))
    print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def c(num):
    return S[:num].count('AC')

for m in l:
    print(c(m[1])-c(m[0]))

Submission status: Time Limit Exceeded

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

for i in range(q):
    l, r = map(int, input().split())
    moji = s[l-1:r]
    print(moji.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 = S[l-1:r]
  print(s.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
import re
N, Q = map(int, input().split())
S = list(input())
qs = [list(map(int, input().split())) for _ in range(Q)]
pattern = 'AC'
repatter = re.compile(pattern)
for q in qs:
    string = ''.join(S[q[0]-1:q[1]])
    result = repatter.findall(string)
    print(len(result))

Submission status: Time Limit Exceeded

Solution code:
inr = lambda: list(map(int, input().split()))
inn = lambda: input()

N,Q = inr()
S = inn()
for q in range(Q):
    l,r = inr()
    bubun = S[l-1:r]

    bbb = ""
    for b in bubun:
        if b in ["A","C"]:
            bbb += b
        
    print(bbb.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
def print_list(n, s, list_q):
    tmp = 0
    count = 0
    list_q[1] = n - list_q[1]
    for i in range(list_q[0] - 1):
        s = s[1:]
    for i in range(list_q[1]):
        s = s[:-1]
    s = s.split("AC")
    print(len(s) - 1)


n, q = map(int, input().split())
s = input()
for i in range(q):
    print_list(n, s, list(map(int, input().split())))

Submission status: Time Limit Exceeded

Solution code:
N, Q = input().split(" ")
S = input()
index_list_all = []
for i in range(int(Q)):
    lQ, rQ = input().split(" ")
    index_list_all.append([int(lQ), int(rQ)])

for index_list in index_list_all:
    print(len(S[index_list[0] - 1: index_list[1]].split("AC")) - 1)

Submission status: Time Limit Exceeded

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

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

ans = []
for _ in range(Q):
    a,b = [int(i) for i in input().split()]
    ans.append(S[a-1:b].count('AC'))

[print(i) for i in ans]

Submission status: Time Limit Exceeded

Solution code:
n,p=map(int,input().split())
s=list(input())
for i in range(1,p+1):
    lists=[]
    l,r=map(int,input().split())
    for j in range(l,r+1):
        lists.append(s[j-1])
    a=''.join(lists)
    t=a.count("AC")
    print(t)

Submission status: Time Limit Exceeded

Solution code:
import re

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

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:
#coding:utf-8
n,q = map(int,input().split())
s = input()
a = list()

last_s = 'l'

for j in s:
  if last_s == 'A' and j=='C':
    a.append(1)
  else:
    a.append(0)
  last_s = j
#print(a)

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

Submission status: Time Limit Exceeded

Solution code:
nq=input().split()
N=int(nq[0]);Q=int(nq[1])
S=input()
ls=[];rs=[]
for i in range(Q):
    lr=input().split()
    l=int(lr[0]);r=int(lr[1])
    ls.append(l)
    rs.append(r)
ans=[]
for j in range(Q):
    s=S[(ls[j]-1):(rs[j])]
    n=0
    a=False
    for k in s:
        if k=="A":
            a=True
        elif a:
            if k=="C":
                n+=1
            else:
                a=False
        else:
            pass
    ans.append(n)
for w in ans:
    print(str(w))

Submission status: Time Limit Exceeded

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

for l, r in l_r_list:
    S_lr = S[l - 1:r]
    print(S_lr.count("AC"))

Submission status: Time Limit Exceeded

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

for i in range(Q):
	count = 0
	l, r = map(int, input().split())
	Sr = S[l-1:r]
	j = 0
	while (j < (len(Sr)-1)):
		if(Sr[j] == 'A' and Sr[j+1] == 'C'):
			count += 1
			j += 1
		elif(Sr[j+1] != 'A'):
			j += 1
		j += 1
	print(count)

Submission status: Time Limit Exceeded

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

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

ans=[]

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

print('\n'.join(ans))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 24 20:23:42 2019

@author: SCREAM
"""

count = 0;
maxnum=0;
n,m = input().split();

s = input();




for j in range(int(m)):
    x,y = input().split();
    i =int(x)-1
    while(i<int(y)-1):
        if(s[i]=='A' and s[i+1] == 'C'):
            count = count +1;
            i = i+2;
        else:
            i = i+1;
    print(count);  
    count = 0;

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = list(input())
S.append(0)
tmp_input = []
count = 0
Ans = []

for i in range(Q):
    x,y = map(int,input().split())
    count = 0
    tmp_List = S[x-1:y]
    tmp_List.append(0)
    for j in range(len(tmp_List)-1):
        if (tmp_List[j] == 'A') & (tmp_List[j+1] == 'C') ==True:
            count += 1
    Ans.append(count)
for i in range(len(Ans)):
    print(Ans[i])

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
ans = []
import re
# for i in range(Q):
#     l, r = map(int, input().split())
#     ans.append(len(re.findall("AC", S[l-1:r])))
# for i in ans:
#     print(i)
# TLE
index = []
for i in range(N):
    if S[i:].find("AC") != -1:
        index.append(S[i:].find("AC") + i)
index = list(set(index))
import numpy as np
for i in range(Q):
    l, r = map(int, input().split())
    # l-1 ~ rまで
    ans.append(sum(l-1<=x and x<=r-2 for x in index))
for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def C():
    N, Q = input().split()
    N = int(N)
    Q = int(Q)
    S = input()

    ans = []
    ac = 'AC'
    cnt = Q
    while cnt >0:
        lq, rq = input().split()
        S_sub = S[int(lq) -1 : int(rq)]
        ans.append(str(S_sub.count(ac)) + '\n')
        cnt -= 1

    # solve
    print(''.join(ans), end="")
            


if __name__ == '__main__':
    C()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
nq=input().split()
N=int(nq[0]);Q=int(nq[1])
S=input()
ls=[];rs=[]
for i in range(Q):
    lr=input().split()
    l=int(lr[0]);r=int(lr[1])
    ls.append(l)
    rs.append(r)
ans=[]
for j in range(Q):
    s=S[(ls[j]-1):(rs[j])]
    n=0
    a=False
    for k in s:
        if k=="A":
            a=True
        elif a:
            if k=="C":
                n+=1
            else:
                a=False
        else:
            pass
    ans.append(n)
for w in ans:
    print(str(w))

Submission status: Time Limit Exceeded

Solution code:
a = input().split() 
n = a[0]
q = a[1]
s = input()
s = list(s)
cnt = []
l = []
r = []
for i in range(int(q)):
  a,b=map(int,input().split())
  l.append(a)
  r.append(b)
  cnt.append(0)
for i in range(int(q)):
  for j in range(int(l[i]), int(r[i])):
    if j == len(s)-1:
      break
    if s[j-1] == 'A' and s[j] == 'C':
      cnt[i] += 1
for i in range(len(cnt)):
  print(cnt[i])

Submission status: Time Limit Exceeded

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

L=[]
for i in range(Q):
	L.append(map(int, input().split()))


from collections import defaultdict

for i in L:
	count=0
	i=list(i)
	Sq=S[i[0]-1:i[1]]

	for j in range(len(Sq)-1):
		#print(Sq)
		if (Sq[j:j+2])=="AC":
			count+=1
	print(count)

Submission status: Time Limit Exceeded

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

for k in range(len(S) - 1):
    if S[k] == 'A':
            if S[k+1] == 'C':
                    cnt.append(1)
    else:
            cnt.append(0)



for lr in lrs:
    print(sum(cnt[lr[0]-1:lr[1]-1]))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import re

N,Q = map(int, input().split())
S = input()
itr = re.finditer("AC",S)
li = []
for i in itr :
    li.append(i.span())
    

for i in range(Q):
    l, r = map(int, input().split())
    cnt = 0
    for match in li:
    	if l <= int(match[0]) + 1 and int(match[1]) <= r :
            cnt+=1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
nq = input().split()
n, q = int(nq[0]), int(nq[1])
s = list(input())
r_li = []
l_li = []
a_renzoku = 0
ac_count = 0
ac_li = []
for i in range(q):
    rl = input().split()
    l_li.append(int(rl[0]))
    r_li.append(int(rl[1]))
for i in range(q):
    count = 0
    j = l_li[i] - 1
    while True:
        if j == r_li[i]:
            break
        else:
            if s[j] == "A":
                if j == r_li[i] - 1:
                    break
                else:
                    if s[j + 1] == "C":
                        count += 1
                        j += 2
                    else:
                        j += 1
            else:
                j += 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())
    start = s[l-1:r].find('A')
    end = s[l-1:r].rfind("C")
    if start == -1 or end== -1 or end <= start:
        print(0)
        continue
    cand = s[l-1:r][start:end+1]
    print(cand.count("AC"))

Submission status: Time Limit Exceeded

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

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

for p in cntli:
    print(p)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
i = input()
n, q = int(i.split()[0]), int(i.split()[1])
s = input()
_list = []
u = 0
while True:
    i = input()
    u += 1
    _list.append((int(i.split()[0]), int(i.split()[1])))
    if u == q:
        break

for x in _list:
    _str = s[x[0]-1:x[1]]
    n = _str.count("AC")
    print(n)

Submission status: Time Limit Exceeded

Solution code:

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

length = len(lrs)
count = [0] * length
for i in range(len(S) - 1):
    c = S[i] == 'A'
    nc = S[i+1] == 'C'
    if c and nc:
        for j in range(length):
            if lrs[j][0] <= i+1 and i < lrs[j][1] and i+1 != lrs[j][1]:
                count[j] += 1

for c in count:
    print(c)

Submission status: Time Limit Exceeded

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

N, M = (int(i) for i in input().split())
moji = input()
e = [[int(i) for i in input().split()] for i in range(M)]

if moji.count('AC') == None:
    print(0)
    exit()

for idx in e:
    n = moji[idx[0]-1:idx[1]].count('AC')
    if n:
        print(n)
    else:
        print(0)

Submission status: Time Limit Exceeded

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

for i in range(num):
  wakeru = input().split(" ")
  a = int(wakeru[0])
  b = int(wakeru[1])
  tmp = word[a-1:b]
  tmp_split = tmp.split("AC")
  hikaku = ("").join(tmp_split)
  print(int((len(tmp)-len(hikaku))/2))