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 sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,Q = Is()
S = S()
lis = [0]*(N-1)
for i in range(N-1):
    if S[i:i+2] == "AC":
        lis[i] = 1
for q in range(Q):
    l,r = Is()
    print(sum(lis[l-1:r-1]))

Submission status: Time Limit Exceeded

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


def is_acgt(s):
    if s=='A' or s=='C' or s=='G' or s=='T':
        return 1
    else: return 0


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

x = [raw_input() for i in range(q)]

for d in x:
    r = d.split(' ')
    ss = s[int(r[0])-1:int(r[1])]
    print ss.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)]

w =[0]*q

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

for i in w:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
A = "AC"
N, Q = map(int, input().split())
S = list(input())
for i in range(Q):
    l, r = map(int, input().split())
    tmp = S[l-1:r]
    cnt = 0
    for j in range(len(tmp) -1):
        tmp1 = tmp[j] + tmp[j+1]
        if tmp1 == A:
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

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

for a in A:
    tmp = S[a[0]-1:a[1]]
    print(tmp.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
s,q = input().split()
s = input()
q = int(q)
res = []

for i in range(q):
    l,r = [int(j)-1 for j in input().split()]
    res.append(str(s[l:r+1:].count('AC')))
print("\n".join(res))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

#print(string[2:7])
for i in range(Q):
    que=string[q[i][0]-1:q[i][1]]
    #print(que)
    que="".join(que)
    #print(que)
    print(que.count("AC"))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n,q = (int(x) for x in input().split())
s = input()

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

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache


@lru_cache(maxsize=None)
def find_word(word):
    return word.count('AC')


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

lr = []
for i in range(Q):
    li, ri = map(int, input().split())
    lr.append((li - 1, ri))

for l, r in lr:
    print(find_word(S[l:r]))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
l = [[] for _ in range(Q)]
r = [[] for _ in range(Q)]
for i in range(Q):
    l[i], r[i] = map(int, input().split())
    
def qst(S,l,r):
    count=0
    for i in range(l-1,r-1):
        if S[i]=="A" and S[i+1]=="C":
            count+=1
    print(count)
    
for k in range(Q):
    qst(S,l[k],r[k])

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

p = []
for i in range(int(N)):
  if S[i:i+2] == "AC":
    p.append(i)

for i in range(int(Q)):
  l,r = input().split()
  count = 0
  for x in p:
    if int(l)-1 <= x and x <= int(r)-2:
      count += 1
  print(count)

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

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

print(*A,sep="\n")

Submission status: Time Limit Exceeded

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


for l, r in lrs:
    print(S[l - 1:r].count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    ans = []
    for i in range(Q):
        ts = S[l[i]-1:r[i]].count('AC')
        # print(S[l[i]-1:r[i]])
        ans.append(ts)

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


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split())
S = list(input())
for i in range(b):
    count = 0
    x,y = map(int,input().split())
    S_a = S[x-1:y]
    #print(S_a)
    for i in range(y-x):
        if(S_a[i]=="A"):
            if(S_a[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())
    part = S[l-1:r]
    part_len = len(part)
    sub_len = len(part.replace('AC', ''))
    print((part_len-sub_len)//2)

Submission status: Time Limit Exceeded

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


N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
for ans in solve(N, Q, S, L_R):
    print(ans)

Submission status: Time Limit Exceeded

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

for l,r in lr:
    Smoji = S[l - 1 :r]
    ans = Smoji.count("AC")

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
for x in range(Q):
    a, b = map(int, input().split())
    print(S[a-1:b].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)]

w =[0]*q

for i in range(q):
    w[i] = s[(l[i][0]-1):(l[i][1])]
    
w_n = [0]*q

for i in range(q):
    w_n[i] = w[i].count('AC')

for i in w_n:
    print(i)

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

for lr in lr_list:
    print(S[lr[0] - 1:lr[1]].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import sys

l = raw_input().split()
N = int(l[0])
Q = int(l[1])
l = raw_input().split()
S = l[0]

L = [0]*Q
R = [0]*Q

ac = 'AC'

for i in range(Q):
    l = raw_input().split()
    L[i] = int(l[0])
    R[i] = int(l[1])

#print(N,Q,S,L,R)

def count(S):
    length = len(S)
    c = 0
    for i in range(length - 1):
        # print(S[i:i+2])
        if ac == S[i:i+2]:
            c += 1
    return c

for i in range(Q):
    p = S[L[i]-1:R[i]]
    # print(p)
    print(count(p))

Submission status: Time Limit Exceeded

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

for _ in range(q):
    l, r = map(int, input().rstrip().split())
    tmp = s[l-1:r]
    print(tmp.count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

L = [0]
for i,s in enumerate(S[1:]):
    if s == 'C' and S[i] == 'A':
        L.append(1)
    else:
        L.append(0)

for x in X:
    print(sum(L[x[0]:x[1]]))

Submission status: Time Limit Exceeded

Solution code:

def count(char):
  l, r = map(int, input().split())
  char1 = char[l-1:r]
  char1 = char1.split('AC')
  print(len(char1)-1)

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

for i in range(Q):
  count(char)

Submission status: Time Limit Exceeded

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())

def pne(n):
    print(n,end='')

rem = pow(10,9)+7

#n = ip()                                     #入力整数1つ
n,q= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
gatacca = ["A","C","T","G"]
pa = []
pc = []
for i in range(n-1):
    if a[i] == "A" and a[i+1] == "C":
        pa.append(i)
for i in range(q):
    dna = copy.copy(pa)
    left,right =  (int(i) for i in input().split())
    left-=1.5
    right-=1.5
    dna.append(left)
    dna.append(right)
    dna.sort()
    lp = dna.index(left)
    rp = dna.index(right)

    print(len(dna[lp:rp])-1)

Submission status: Time Limit Exceeded

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

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


for i in range(Q):
    ans = 0
    subseq = S[l[i]-1:r[i]]
    for j in range(len(subseq)-1):
        if (subseq[j] == 'A')and(subseq[j+1] == 'C'):
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, q = [int(elem) for elem in input().split()]
s = input()
out = []
for i in range(0, q):
    l, r = [int(elem) for elem in input().split()]
    part_s = s[l-1:r]
    res = part_s.split("AC")
    out.append(len(res) - 1)

for elem in out:
    print(elem)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
q=int(input().split()[1])
b=input()
ac=[0]*(len(b)-1)
for i in range(len(b)-1):
  ac[i] = 1 if b[i:i+2] == 'AC' else 0
for i in range(q):
  l,r = list(map(int,input().split()))
  print(sum(ac[l-1:r-1]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int,input().split())
s = input()
l = [[int(i) for i in input().split()] for i in range(q)]
for i in range(q):
    t = s[l[i][0]-1:l[i][1]]
    c = 0
    f = False
    for j in t:
        if f:
            if j=="C":
                c += 1
                f = False
            else:
                f = False
        if j=="A":
            f = True
    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())
    _s = s[l - 1:r]
    num_ac = 0
    ex_a = False
    for c in _s:
        if ex_a and c == "C":
            num_ac += 1
        if c == "A":
            ex_a = True
        else:
            ex_a = False
    print(num_ac)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


def readln():
    return list(map(int, read().split()))


N, Q = readln()
S = input()

L = []
R = []
for _ in range(Q):
    a, b = readln()
    L.append(a-1)  # indexでアクセスできるように
    R.append(b)

import re

for l, r in zip(L, R):
    s = S[l:r]
    regex = re.compile('AC')
    print(len(regex.findall(s)))

Submission status: Time Limit Exceeded

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


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

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

Submission status: Time Limit Exceeded

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


def question():
    n, q = list(map(int, input().split()))
    s = input()
    lr = [list(map(int, input().split())) for i in range(q)]
    a = [(s[i]=="A" and s[i+1] =="C") for i in range(n-1)]
    for i in range(q):
        print(sum(a[lr[i][0]-1:lr[i][1]-1]))


question()

Submission status: Time Limit Exceeded

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N, Q = LI()
S = input()
#  LR = []
#  for i in range(Q):
#      LR.append(LI())
#  N, Q = 10**5, 10**5
#  S = 'ACTCTTCGTG'*10**4
#  LR = []
#  for i in range(Q):
#      LR.append([3,9000])

#  for l, r in LR:
#      tmp = S[l-1:r]
#      print(tmp.count('AC'))

result = []
for _ in range(Q):
    l,r = LI()
    tmp = S[l-1:r]
    result.append(tmp.count('AC'))
for i in result:
    print(i)

Submission status: Time Limit Exceeded

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

S=input()

for q in range(Q):
	L,R=map(int,input().split())
	tmp=S[L-1:R]
	print(tmp.count("AC"))

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)

for i in range(q):
    ac = 0
	
    for j in range(l[i] - 1, r[i] - 1):
        if s[j : j + 2] == "AC":
            ac += 1
    
    print(ac)

Submission status: Time Limit Exceeded

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


for i in L:
    res=0
    S_ = S[i[0]-1:i[1]]
    for k, j in enumerate(S_[:-1]):
        if j=="A" and S_[k+1]=="C":
            res+=1
    print(res)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
listS = list(input())
index=0
listA=[]
listI=[]
index2=0
while index2 < len(listS)-1:
    if listS[index2]=="A" and listS[index2+1]=="C":
        listI.append(index2)
    index2+=1

while index < q:
    l, r = map(int, input().split())
    count=0
    index3=0
    while index3 < len(listI):
        if listI[index3] >= l-1 and listI[index3]+1 <= r-1:
            count+=1
        index3+=1
    listA.append(count)
    index+=1
for ans in listA:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
n,q = (int(i) for i in input().split())
s = input()
query = [0]*n
for i in range(n-1):
  if s[i] == 'A' and s[i+1] =='C': 
    query[i] = 1
for i in range(q):
  l,r = (int(i) for i in input().split())
  ans = sum(query[(l-1):r])
  if r >= 1:
   if s[r-1] == 'A' and s[r-2] =='C':

     ans -= 1
  print(math.floor(ans))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int, input().split())

A = input()

for i in range(b):
    x, y = map(int, input().split())
    B = A[x-1:y]
    print(B.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())
    cnt = 0
    prev_A = False
    for j in range(l - 1, r):
        if S[j] == 'A':
            prev_A = True
        elif prev_A == True and S[j] == 'C':
            cnt += 1
            prev_A = False
        else:
            prev_A = False
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
S = input()
for i in range(q):
    l,r = map(int,input().split())
    A = S[l-1:r]
    print(A.count('AC'))

Submission status: Time Limit Exceeded

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

lrCut = []
for i in range(0,q):
    lrCut.append(s[int(lr[i][0]) - 1:int(lr[i][1])])

for i in range(0,q):
    lrCut[i] = lrCut[i].replace("AC","Q")
    sum = 0
    for j in lrCut[i]:
        if j == "Q":
            sum += 1
    print(sum)

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(0,q):
    l[i], r[i] = map(int,input().split())
    l[i] = l[i] -1
    r[i] = r[i] -1

s_list = list(s)

ac_list = [0] * (n-1)

for i in range(0,n-1):
    if s_list[i] == "A" and s_list[i+1] == "C":
        ac_list[i] = 1

for i in range(0,q):
    print(sum(ac_list[l[i]:r[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(list(map(int,input().split())))
def f(l,r) :
    global s
    count = 0
    for i in range(l,r) :
        if s[i - 1] == "A" and s[i] == "C" :
            count += 1
    print(count)
for l,r in l :
    f(l,r)

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = list(map(int, input().split()))
S = input()
for n in range(Q):
    l, r = list(map(int, input().split()))
    s = S[(l-1):r]
    c = 0
    for a in range(len(s)):
        if s[a] == 'A':
            if a < (len(s) - 1):
                if s[a+1] == 'C':
                    c += 1
                    a += 1
                elif s[a+1] != 'A':
                    a += 1
    print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import numpy as np

count=np.array([0 for i in range(N)])
for i in range(N-1):
    if S[i]=="A" and S[i+1]=="C":
        count[i+1:]+=1

for i,j in lr:
    print(count[j-1]-count[i-1])

Submission status: Time Limit Exceeded

Solution code:
def ii():
    return list(map(int, input().split()))


[N, Q] = ii()
S = input()
Q_list = [ii() for _ in range(Q)]

for q in Q_list:
    sub_s = S[q[0] - 1:q[1]]
    print(sub_s.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
minians = []
for i in range(N-1):
    if S[i:i + 2] == "AC":
        minians.append(i)
# print(minians)
ans = [0]*Q
for i in range(Q):
    left, right = map(int, input().split())
    left -= 1
    right -= 1
    for j in range(len(minians)):
        if left <= minians[j] and minians[j] < right:
            ans[i] += 1
        elif minians[j] >= right:
            break
print('\n'.join(map(str, 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())
    s = S[l-1:r]
    print(s.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import re

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]
  pattern = r"AC"
  count = re.findall(pattern, tmp)
  print(len(count))

Submission status: Time Limit Exceeded

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

for i in range(Q):
    L,R = map(int,input().split(" "))
    temp = ""
    for j in range(L-1,R):
        temp += S[j]
    count = 0
    temp = list(temp)
    for k in range(R - L + 1 - 1):
        if temp[k] == 'A' and temp[k+1] == 'C':
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

S=input()


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

Submission status: Time Limit Exceeded

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

for i in range(Q):
  l = lr[i][0]
  r = lr[i][1]
  tmp = S[l-1:r]
  print(tmp.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())
    Si = S[l-1:r]
    s = 0
    while(s < len(Si) - 1):
        if(Si[s] == "A" and Si[s+1] == "C"):
            ans += 1
            s += 2
        else:
            s += 1

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
x = input()
y = x.split()
y = [int (i) for i in y]

length = y[0]
num    = y[1]

count  = 0
string = input()
for i in range(num):
    z = input()
    c = z.split()
    c = [int (i) for i in c]
    l = c[0] - 1
    r = c[1] - 1
    for j in range(l,r+1):
        if j+1 < r+1:
             if string[j] == "A" and string[j+1] == "C":
                 count +=1
    print(count)
    count = 0

Submission status: Time Limit Exceeded

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

for _ 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:
N,Q=map(int,input().split())
S=input()
l=[list(map(int,input().split())) for _ in range(Q)]
for lz in l:
  print(S[lz[0]-1:lz[1]].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
saisholist=input().split(' ')
n=int(saisholist[0])
q=int(saisholist[1])
s=input()
record=0
swit=0
countac=0
atgc=['A', 'T', 'G', 'C']
for i in range(q):
    toilist=input().split(' ')
    to1=int(toilist[0])
    to2=int(toilist[1])
    for ii in range(to1-1, to2):
        #print(s[to1-1:to2])
        if s[ii]=='A':
            swit=1
        elif swit==1:
            if s[ii]=='C':
                countac+=1
            swit=0
    print(countac)
    countac=0

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())
    res = re.findall("AC",S[l-1:r])
    print(0 if len(res)==0 else len(res))

Submission status: Time Limit Exceeded

Solution code:
import re
n, q = [int(i) for i in input().split()]
S = input()
for _ in range(q):
    l, r = [int(i) for i in input().split()]
    s = S[l-1:r]
    ans = sum(True for _ in re.finditer('AC', s))
    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())
    cnt=0
    for j in range(l-1,r-1):
        if s[j]=="A" and s[j+1]=="C":
            cnt+=1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s=list(input())	
	
flag = False
ans = 0
for i in range(q):
    ans = 0
    l,r = map(int,input().split())
    s2 = s[l-1:r]
    for word in s2:
        if word == "A":
            flag = True
        elif word == "C":
            if flag:
                ans += 1
                flag = False
        else:
            flag = False

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
L = []
R = []
ans = []
for _ in range(Q):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)

for i in range(Q):
	cnt = 0
	for j in range(L[i]-1, R[i]-1):
		if S[j] == 'A' and S[j+1] == 'C':
			cnt += 1
		else:
			j += 1
	ans.append(cnt)

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
query = [list(map(int, input().split())) for _ in range(Q)]
for left, right in query:
    T = S[left - 1:right]
    print(T.count('AC'))

Submission status: Time Limit Exceeded

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

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

    count = 0
    for j in range(l-1,r-1):
        if S[j] == "A":
            if S[j+1] == "C":
                count += 1
    c_list.append(count)

for c in c_list:
    print(c)

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())
  print(S[a-1:b].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
s = input()
lr = [list(map(lambda x: int(x)-1, input().split())) for _ in range(q)]
for x in lr:
    tmp = s[x[0]:x[1]+1]
    print(tmp.count('AC'))

Submission status: Time Limit Exceeded

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

ans_arr = []
for i in range(Q):
    l, r = map(int, input().split())
    tmp = S[l-1:r]
    tmp = tmp.replace("AC", "_")
    ans_arr.append(tmp.count("_"))

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