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

Submission status: Time Limit Exceeded

Solution code:
import re
N,Q=[int(s) for s in input().split()]
S=input()
for i in range(Q):
    (li, ri)=[int(s) for s in input().split()]
    s=S[li-1:ri]
    print(len(re.findall("AC", s)))

Submission status: Time Limit Exceeded

Solution code:
#C問題
N,Q=map(int,input().split())
S=str(input())
Slist=list(S)
LR=[list(map(int,input().split())) for i in range(Q)]
for i in range(Q):
    karis=Slist[LR[i][0]-1:LR[i][1]]
    n=LR[i][1]-LR[i][0]+1
    count=0
    for j in range(n-1):
        if karis[j] == "A" and karis[j+1] == "C":
            count+=1
    print(count)

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:
import sys
input = sys.stdin.readline

N, Q = map(int,input().split())
S = input()
for _ 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:

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

S = input()

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

#print(S)

for x in A:
    # print(S[(x[0]-1):(x[1])])
    m = re.findall('AC', S[(x[0]-1):(x[1])])
    #print(m)
    print(len(m))

#print(A)

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

Submission status: Time Limit Exceeded

Solution code:
# 高速版input
import sys
input = sys.stdin.readline

n, q = (int(i) for i in input().split())
s = input()
e = [[int(i)-1 for i in input().split()] for i in range(q)]

mem = []
for i in range(len(s)-1):
    if s[i]+s[i+1] == "AC":
        mem.append(1)
    else:
        mem.append(0)

for x in e:
    res = sum(mem[x[0]:x[1]]) 
    print(max(0,res))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
lis = []
for _ in range(Q):
  lis.append(list(map(int, input().split())))
for temp in lis:
  strin = S[temp[0] - 1:temp[1]]
  Tlis = []
  for i in range(len(strin) - 1):
    Tlis.append(strin[i: i + 2])  
  print(Tlis.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
N,Q=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
data=[]
for i in range(Q):
    data.append([int(x) for x in stdin.readline().rstrip().split()])
for j in data:
    print(S[j[0]-1:j[1]].count("AC"))

Submission status: Time Limit Exceeded

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

S = input()

def func(S,l,r):
    ans = 0
    S = S[l-1:r]
    for i in range(len(S)):
        tmp = S[i:i+2]
        if tmp == 'AC':
            ans += 1
    print(ans)


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

Submission status: Time Limit Exceeded

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

res = []
for num in range(Q):
    l, r = (int(i) for i in input().split())
    S2 = S[l-1:r]
    flag = False
    cnt = 0
    for chr in S2:
        if chr == "A":
            flag = True
        elif chr == "C" and flag == True:
            cnt += 1
            flag = False
        else:
            flag = False
    res.append(cnt)

for i in res:
    print(i)

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

table = [0]*len(S)

for i in range(len(S)):
    table[i] = count(S[i:])

for i in range(Q):
    print(table[L[i]-1] - table[R[i]-1])

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

Submission status: Time Limit Exceeded

Solution code:
def countAC(s):
    counter = 0
    for i in range(len(s)):
        if i == len(s)-1:
            break
        if s[i] == 'A':
            if s[i+1] == 'C':
                counter += 1
    return counter



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]
    s = S[l-1:r]
    print(countAC(s))

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, Q = map(int, input().split())
    S = input('')
    ac_list = []
    for i in range(Q):
        l, r = map(int, input().split())
        S_cut = S[l - 1:r]
        result = S_cut.count('AC')
        ac_list.append(result)

    for i in range(len(ac_list)):
        print(ac_list[i])


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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

for l, r in l_r:
    print(S[l - 1:r].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)]
ans=[]
for i in range(Q):
  s=S[L[i][0]-1:L[i][1]].replace("AC","")
  print((L[i][1]-L[i][0]+1-len(s))//2)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N, Q = [int(i) for i in input().split()]
S = input()
L = []
for j in range(Q):
    L.append([int(i) for i in input().split()])
for i in L:
    tar = S[i[0]-1:i[1]]
    print(tar.count("AC"))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
cast = lambda x: int(x) - 1
inputs = [list(map(cast, input().split())) for _ in range(Q)]

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

ans = 0
for item in inputs:
    for index in indexes:
        if index[0] >= item[0] and index[1] <= item[1]:
            ans += 1
    print(ans)
    ans = 0

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

def main():
    N, Q = map(int, input().split())
    S = input()
    LR = [tuple(map(int, input().split())) for _ in [0] * Q]

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

input = lambda: stdin.readline().rstrip()
main()

Submission status: Time Limit Exceeded

Solution code:
N, Q = [int(s) for s in input().split()]
S = input()
AC = []
for i in range(N-1):
    if S[i:i+2] == 'AC':
        AC.append(i)
for i in range(Q):
    l, r = [int(s)-1 for s in input().split()]
    n_AC = 0
    for j in AC:
        if j >= l and j+1 <=r:
            n_AC += 1
    print(n_AC)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main_(lst):
    a=s[lst[0]-1:lst[1]]
    b=a.count("AC")
    print(b)

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
for _ in range(Q):
    li, ri = map(int, input().split())
    substr = S[li - 1:ri]
    print(substr.count("AC"))

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

answers = [0 for k in range(q)]
for i in range(q):
    tmpStr = s[starts[i]-1:ends[i]]
    tmpAns = 0
    flag = True
    result = -1
    while(flag):
        tmpStr = tmpStr[result+1:]
        result = tmpStr.find("AC")
        if(result==-1):
            flag = False
        tmpAns += 1
    answers[i] = tmpAns-1

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

Submission status: Time Limit Exceeded

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

s = input()

cnt = []

for i in range(1,len(s)+1):
    temp = s[0:i]
    #print(temp)
    cnt.append(temp.count('AC'))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import numpy as np

def main():
  N, Q = map(int, input().strip().split(' '))
  S = input()
  ans = []
  ls = np.array([i for i in range(len(S)-1) if S[i:i+2] == 'AC'])
  for _ in range(Q):
    l, r = map(int, input().strip().split(' '))
    l -= 1
    _ls = ls[l<=ls]
    _ls = _ls[_ls<(r-1)]
    ans += [len(_ls)]
  [print(a) for a in ans]
  pass

if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:

from sys import exit
N,Q = [int(n) for n in input().split()]
S = str(input())

for i in range(Q):
    l,r = [int(n) for n in input().split()]
    p = S[l-1:r]
    ans = 0
    for i in range(1,len(p)):
        if p[i] == "C" and p[i-1] == "A":
            ans+=1
    print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())  # 複数数値入力
S = list(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):
    list = S[L[i]-1:]
    list = list[:R[i]-L[i]+1]
    flg = 0
    ans = 0

    for j in list:
        if j == "A":
            flg = 1
        elif j == "C" and flg == 1:
            ans += 1
            flg = 0
        else:
            flg = 0

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
a = [0]*n
for i in range(n-1):
    if s[i:i+2] == 'AC':
        a[i] = 1

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

Submission status: Time Limit Exceeded

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

for i in range(Q):
    l,r=map(int,input().split())
    l,r=l-1,r-1 #リストのインデックスとの整合
    counter=0
    for j in range(l,r): 
        if S[j] =='A' and S[j+1]=='C':
            counter+=1
    count_list.append(counter)
for k in count_list:
    print(k)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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)

l = []
r = []

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

for i in range(Q):
    count = 0
    for ac in AC:
        if ac < l[i] - 1 or r[i] - 1 < ac + 1:
            count += 1
    print(len(AC) - count)

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 m in l:
    T = S[m[0]-1:m[1]]
    print(T.count('AC'))

Submission status: Time Limit Exceeded

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

S = list(input())

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

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

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
N, Q = map(int, input().split())
S = input()

list = []

for i 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 = [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())
line = list(input())
count_s = []
for i in range(Q):
    l,r = map(int,input().split())
    count = 0
    for i in range(l-1,r-1):
        if line[i] == 'A' and line[i+1] == 'C':
            count += 1
    count_s.append(count)
for c in count_s:
    print(c)

Submission status: Time Limit Exceeded

Solution code:
N, Q = list(map(int, input().split()))
S = input()
w = []
for a in range(len(S)-1):
    if S[a] == 'A' and S[a+1] == 'C':
        w.append(1)
    else:
        w.append(0)
  
for n in range(Q):
    l, r = list(map(int, input().split()))
    v = w[(l-1):(r-1)]
    print(sum(v))

Submission status: Time Limit Exceeded

Solution code:
def count(s):
    num = 0
    check = False
    for i in s:
        if i == 'A' and not(check):
            check = True
        elif i == 'C' and check:
            num += 1
            check = False
        else:
            check = False
    return num


n, q = map(int, input().split())
s = input()
s = ''.join([i if i == 'A' or i == 'C' else ' ' for i in s])
inds = [list(map(int, input().split())) for _ in range(q)]
for ind in inds:
    ss = s[ind[0]-1:ind[1]].split(' ')
    print(sum(map(count, ss)))

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())
    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()
l = [0] * N
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        l[i] = 1
        l[i + 1] = -1
for _ in range(Q):
    ans = 0
    a, b = map(int, input().split())
    for i in range(a - 1, b - 1):
        if l[i] == 1 and l[i + 1] == -1:
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re
 
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):
    m = re.findall("AC", s[l[i] - 1 : r[i]])
    print(len(m))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n, q = map(int, input().split())
s = input()
lr = [tuple(map(int, input().split())) for _ in range(q)]

for l, r in lr:
    print(s[l-1:r].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
    for j in range(len(t)-1):
        if t[j] == "A":
            if t[j+1] == "C":
                c += 1
        else:
            continue
    print(c)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

# なんこか入力
n,q = map(int, input().split())

# 文字列を一文字ずつのリストに代入 test は['t', 'e', 's', 't']
s = list(input())

# n行の複数列ある数値を二次元配列へ。x[n][?]
x = [[int(i) for i in input().split()] for i in range(q)] 

for i in range(q):
    count = 0
    for j in range(x[i][0]-1,x[i][1]-1):
        if s[j] == "A" and s[j+1] == "C":
            count += 1
#            print(x[i][0],x[i][1],j)
    print(count)

Submission status: Time Limit Exceeded

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

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:


tmp = input().split(" ")
n = tmp[0]
q = int(tmp[1])

s = input()

for i in range(q):
    tmp = input().split(" ")
    a = int(tmp[0]) - 1
    b = int(tmp[1])
    sub = s[a:b]
    arr = sub.split("AC")
    print(len(arr) - 1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = list(input())
start_pair = [-1]
for j in range(N-1):
    if S[j] == 'A' and S[j+1] == 'C':
        start_pair.append(j)
for i in range(Q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    Flag = [1 for x in start_pair if l <= x < r]
    print(sum(Flag))

Submission status: Time Limit Exceeded

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

pos = []
for i in range(Q):
    pos.append(list(map(int, input().split())))
    
def countAC(S, r, l):
    data = S[r-1:l]
    cnt = 0
    for i in range(len(data)-1):
        if data[i]=='A':
            if data[i+1] == 'C':
                cnt+=1
    return cnt
  
for it in pos:
    cnt = countAC(S, it[0], it[1])
    print(cnt)

Submission status: Time Limit Exceeded

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

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

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

for i in range(Q):
    print( sum( lst[ lr[i][0] - 1 : lr[i][1] - 1 ] ) )

Submission status: Time Limit Exceeded

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

for q in range(Q):
  Ss = S[lr[q][0]-1:lr[q][1]]
  sums = 0
  for i in range(len(Ss)-1):
    if Ss[i:i+2] == "AC":
      sums += 1
  print(sums)

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]
    ans = Si.count("AC")
    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())
    num = list(S[l-1:r].replace("AC", "@")).count("@")
    print(num)

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]"):
    # ACがある場所を記録する
    buf = None
    mem = []
    for i, c in enumerate(S):
        if buf is None and c == 'A':
            buf = 'A'
        elif buf == 'A' and c == 'C':
            mem.append(i-1)
            buf = None
    for i in range(Q):
        tot = 0
        for m in mem:
            if l[i]-1 <= m and m < r[i]-1:
                tot += 1
        print(tot)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    l = [int()] * (Q)  # type: "List[int]"
    r = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = []

for q in range(Q):
    l, r = map(int, input().split())
    ans.append(S[l-1:r].count('AC'))

for a in ans:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
# 2019/03/24
# AtCoder Beginner Contest 122 - C

# Input
n, q = map(int,input().split())
s = input()
sab = list()

for i in range(q):
    l, r = map(int,input().split())
    ans = 0
    
    for j in range(l-1, r-1, 1):
        if j == n:
            break
        else:
            if s[j] == "A" and s[j+1] == "C":
                ans += 1
    # Output
    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())
    t = S[l-1:r]
    print(t.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import re

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(Q):
  ans = 0
  tmp = input().split()
  l = int(tmp[0])
  r = int(tmp[1])
  
  deleted = S[l-1:r]

  for j in range(len(deleted)-1):  
    if deleted[j] == 'A' and deleted[j+1] == 'C':
      ans += 1
  
  print(ans)
  ans = 0

Submission status: Time Limit Exceeded

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

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

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
    ans[i] = sum(left <= mini < right for mini in minians)
    """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() 
data = [ tuple(map(int, input().split())) for _ in range(Q) ] 

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

Submission status: Time Limit Exceeded

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

ans=[]
for l, r in D:
    s = S[l-1:r]
    ans.append(s.count("AC"))

for a in ans:
    print(a)

Submission status: Time Limit Exceeded

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

def find_ac(s):
    return s.count('AC')

main()

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]
    ans = 0
    for s1, s2 in zip(s[:-1], s[1:]):
        if s1 == 'A' and s2 == 'C':
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = list(str(input()))
dp = [0] * n
for j in range(n-1):
  if s[j] == "A" and s[j+1] == "C":
      dp[j] = 0.4
      dp[j+1] = 0.6
for i in range(q):
  l, r = map(int, input().split())
  c = dp[l-1: r]
  if c[0] == 0.6:
    c[0] = 0
  if c[-1] == 0.4:
    c[-1] = 0
  print(int(sum(c)))

Submission status: Time Limit Exceeded

Solution code:




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

S=input()

L=[]
R=[]
for i in range(Q):
	l,r=input().split(" ")
	L.append(int(l))
	R.append(int(r))







count=[0 for i in range(N)]
last="X"
for i in range(N):
	if(S[i]=="C"):
		if(last=="A"):
			count[i]+=1
	last=S[i]


for i in range(Q):
	c=sum(count[L[i]-1:R[i]])
	if(L[i]-2>=0):
		if(S[L[i]-1]=="C" and S[L[i]-2]=="A"):
			c-=1
	print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
_ = input()
S = input().strip()
for line in sys.stdin:
  l,r = list(map(int, line.strip().split(' ')))
  print(S[l-1:r].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = list(str(input()))
agct = {'A', 'C', 'G', 'T'}

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

    ans = 0
    fa = 0
    for i in range(l-1, r):
        if S[i] == 'A' and fa == 0:
            fa = 1
        elif S[i] == 'C' and fa == 1:
            fa = 0
            ans += 1
        else:
            fa = 0
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,q=[int(i) for i in input().split()]
s=input()
for i in range(q):
    l,r=[int(j) for j 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()
rui_count = []
count = []
for i in range(N):
    rui_count.append(S[0:i+1].count('AC'))
for i in range(Q):
    l,r = map(int,input().split())
    count.append(rui_count[r-1]-rui_count[l-1])
    
for i in count:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
L=[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(sum(L[l-1:r-1]))

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8

n, q = map(int, raw_input().split())
s = raw_input()
for i in range(q):
    a, b = map(int, raw_input().split())
    print(s[a-1:b].count("AC"))