Problem:


Score : 300 points

Problem Statement

You are given a string S of length N consisting of A, C, G and T. Answer the following Q queries:

Query i (1 \leq i \leq Q): You will be given integers l_i and r_i (1 \leq l_i < r_i \leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does AC occurs as a substring?

Notes

A substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.

For example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and  (the empty string), but not AC.

Constraints

2 \leq N \leq 10^5

1 \leq Q \leq 10^5

S is a string of length N.

Each character in S is A, C, G or T.

1 \leq l_i < r_i \leq N

Input

Input is given from Standard Input in the following format:

N Q
S
l_1 r_1
:
l_Q r_Q

Output

Print Q lines. The i-th line should contain the answer to the i-th query.

Sample Input 1

8 3
ACACTACG
3 7
2 3
1 8

Sample Output 1

2
0
3

Query 1: the substring of S starting at index 3 and ending at index 7 is ACTAC. In this string, AC occurs twice as a substring.

Query 2: the substring of S starting at index 2 and ending at index 3 is CA. In this string, AC occurs zero times as a substring.

Query 3: the substring of S starting at index 1 and ending at index 8 is ACACTACG. In this string, AC occurs three times as a substring.



Sample input:
8 3
ACACTACG
3 7
2 3
1 8


Sample output:
2
0
3

Submission status: Time Limit Exceeded

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

for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        S[i], S[i+1] = 2, -1
    else:
        if type(S[i]) != int:
            S[i] = 0

if type(S[-1]) == str:
    S[-1] = 0

list_lr = [map(int, input().rstrip().split()) for i in range(Q)]

for i in list_lr:
    l, r = i
    s = S[l-1:r]
    if s[0] == -1 and s[-1] == 2:
        ans = sum(s)-1
    elif s[0] == -1 and (s[-1] == -1 or s[-1] == 0):
        ans = sum(s)+1
    elif s[-1] == 2 and (s[0] == 2 or s[1] == 0):
        ans = sum(s)-2
    else:
        ans = sum(s)

    print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
p,n=map(int,input().split())
s=input()
for _ in range(n):
  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().rstrip().split())
S = input()

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

list_lr = [map(int, input().rstrip().split()) for i in range(Q)]

for i in list_lr:
    l, r = i
    s = S[l-1:r]

    print(s.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
import re
import sys
input = sys.stdin.readline
pat = r'AC'
repat = re.compile(pat)
N,Q = map(int,input().split())
S = input()
lr = [list(map(int,input().split())) for i in range(Q)]
res = [len(repat.findall(S[l[0]-1:l[1]])) for l in lr]
for r in res:
    print(r)

Submission status: Time Limit Exceeded

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

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

list_lr = [map(int, input().rstrip().split()) for i in range(Q)]

for i in list_lr:
    l, r = i
    s = S[l-1:r]
    count = 0
    for i in range(len(s)-1):
        if s[i] == 'A' and s[i+1] == 'C':
            count += 1

    print(count)

Submission status: Time Limit Exceeded

Solution code:
import re

pat = r'AC'
repat = re.compile(pat)
N,Q = map(int,input().split())
S = input()
lr = [list(map(int,input().split())) for i in range(Q)]
res = [len(repat.findall(S[l[0]-1:l[1]])) for l in lr]
for r in res:
    print(r)

Submission status: Time Limit Exceeded

Solution code:
import re

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

Submission status: Time Limit Exceeded

Solution code:
import re

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

Submission status: Time Limit Exceeded

Solution code:
import re
ls,n = [int(i) for i in input().split(' ')]
s = input()
for i in range(n):
    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:
ls,n = [int(i) for i in input().split(' ')]
s = input()
count = 0
for i in range(n):
    l,r = [int(i) for i in input().split(' ')]
    st = s[l-1:r]
    for x in range(len(st)):
        try: 
            if st[x]+st[x+1] == "AC":
                count += 1
        except:
            pass
    print(count)
    count = 0

Submission status: Time Limit Exceeded

Solution code:
import re
def count_ac(s):
    p = re.compile('AC')
    return len(p.findall(s))

N, Q = input().split(' ')
s = input()

for i in range(int(Q)):
  a,b = map(int,input().split(' '))
  #print(s[a-1:b])
  if b-a <=1 :
    print(0)
  else :
    print(count_ac(s[a-1:b]))#, s[a-1:b])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

check = [False for i in range(len(S))]
for i in range(len(S)-1):
    if S[i:i+2] == "AC":
        check[i] = True

output = []
for i in range(Q):
    start, end = map(int, input().split(" "))
    output.append(check[start-1:end-1].count(True))

for i in output:
    print(i)

Submission status: Time Limit Exceeded

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

s=input()+'0'
X=[0]*(len(s)+1)
for i in range(len(s)-1):
    if s[i]=='A' and s[i+1]=='C':
        X[i+1]+=1
Y=[]
for i in range(n):
    Y.append(sum(X[:i+1]))

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

Submission status: Time Limit Exceeded

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

s=input()+'0'
X=[0]*len(s)
for i in range(len(s)):
    if s[i]=='A' and s[i+1]=='C':
        X[i]+=1

A=[]

for i in range(q):
    l,r=map(int,input().split())
    ans=sum(X[l-1:r])
    if s[r-1]=='A' and s[r]=='C':
        A.append(ans-1)
    else:
        A.append(ans)
        
for x in A:
    print(x)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
L = list(input())
count = 0
for i in range(Q):
  l, r = map(int, input().split())
  S = L[l-1:r]
  for i in range(len(S)):
    if S[i] == 'A' and i < len(S)-1:
      if S[i+1] == 'C':
        count += 1
      i += 1
  print(count)
  count = 0

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
s=input()
A=[]
for i in range (0,N-1):
  if s[i]=="A" and s[i+1]=="C":
    A.append(i+1)
    i += 2
  elif s[i]=="A" and (s[i+1]=="G" or s[i+1]=="T"):
    i += 2
  else:
    i += 1
    
for j in range (0,Q):
  l,r=map(int,input().split())
  print(len([k for k in A if k >= l and k <= r-1]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

atgc_list= []

flag = 0
for i in range (len(S)):
    if S[i]=='A':
        flag = 1
    if flag == 1 and S[i] == 'C':
        atgc_list.append(i)
    if S[i] in ['T','G']:
        flag = 0
        
atgc_list_np = np.array(atgc_list)

for j in range (Q):
    l, r = map(int,input().split())
    low = np.sum(l>(atgc_list_np))
    high = np.sum(r>(atgc_list_np))
    print(high - low)

Submission status: Time Limit Exceeded

Solution code:
import re
q = int(input().split(' ')[1])
s = input()

for i in range(q):
    lr = [int(i) for i in input().split(' ')]
    print(len(re.findall('AC', s[lr[0] - 1:lr[1]])))

Submission status: Time Limit Exceeded

Solution code:
_, 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=[int(i) for i in input().split()]
S=input()
lr=[]
for i in range(Q):
  lr.append(tuple(int(i) for i in input().split()))

def AC(l,r):
  count=0
  ss=S[l-1:r]
  for i in range(len(ss)-1):
    if ss[i]+ss[i+1]=="AC":
      count+=1
  return count

for i in range(Q):
  print(AC(lr[i][0],lr[i][1]))

Submission status: Time Limit Exceeded

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

list1 = []
count = 0
for i in range(Q):
    l,r = map(int,input().split())
    l = l - 1
    w_string = S[l:r]
    for j, k in enumerate(w_string):
        if 'AC' in w_string[j:j+2]:
            count = count + 1
    list1.append(count)
    count = 0

for i in list1:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split(' '))
s = input()
A = []
for _ in range(q):
  A.append(list(map(int, input().split(' '))))
ac = [0]*n  # AC index search
for i in range(n):
  if s[i:i+2] == 'AC':
    ac[i] = 1

for l,r in A:
  ans = sum(ac[l-1:r])
  if ac[l-1:r][-1] == 1:
    ans -= 1
  print(ans)

Submission status: Time Limit Exceeded

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

for l,r in A:
  sub = s[l-1:r]
  ans = 0
  for i in range(len(sub)-1):
    if sub[i:i+2] == 'AC':
      ans += 1
  print(ans)

Submission status: Time Limit Exceeded

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

list1 = []

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

for i in list1:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N,Q = [int(strint) for strint in input().split(" ")]
S = input()
L = list(range(Q))
R = list(range(Q))
for q in range(Q):
  L[q], R[q] =  [int(strint) for strint in input().split(" ")]

def countAC(seq):
  ctr = 0
  length = len(seq)
  for l in range(length):
    if l>0:
      if seq[l-1]=="A" and seq[l]=="C":
        ctr += 1
  return ctr
for q in range(Q):
  l=L[q]-1
  #print(l)
  r=R[q]
  #print(r)
  print(countAC(S[l:r]))

Submission status: Time Limit Exceeded

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

list1 = []

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

for i in range(Q):
    print(S[list1[i][0]:list1[i][1]].count('AC'))

Submission status: Time Limit Exceeded

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

check = []
for i in range(len(s)-1):
    temp = s[i:i+2]
    if temp == "AC":
        check.append(i)

for quest in quests:
    cnt = 0
    begin = quest[0]-1
    end = quest[1]-1
    for c in check:
        if begin <= c and (c+1) <= end:
            cnt += 1
    
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = list(input())
ans_lst = []
# cumulative = [S[:i] for i in range(N)]
for i in range(Q):
    l, r = map(int, input().split())
    s = S[l-1:r]
    num = 0
    for j in range(len(s)-1):
        if "".join(s[j:j+2]) == "AC":
            num += 1
    ans_lst.append(num)

for ans in ans_lst:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
ans = []
N, Q = map(int, input().split())
s = input()
for i in range(Q):
    l, r = map(int, input().split())
    s_q = s[l-1:r]
    ans.append( \
        (len(s_q) - len(s_q.replace('AC', '')) ) \
            // 2)

print('\n'.join(map(str, ans)))

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 left,right in L :
    left -= 1
    ans = S[left:right].count("AC")
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Apr  5 17:16:14 2019

@author: adachi-lab
"""

input_1 = input()
S = input()
l = []
r = []


N = input_1.split()[0]
Q = input_1.split()[1]

for i in range(int(Q)):
    input_3 = input()
    l.append(int(input_3.split()[0]))
    r.append(int(input_3.split()[1]))

W = [(S[x-1:y]).count('AC') for (x, y) in zip(l, r)]

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Apr  5 17:16:14 2019

@author: adachi-lab
"""

input_1 = input()
S = input()
l = []
r = []


N = input_1.split()[0]
Q = input_1.split()[1]

for i in range(int(Q)):
    input_3 = input()
    l.append(int(input_3.split()[0]))
    r.append(int(input_3.split()[1]))

W = [S[x-1:y] for (x, y) in zip(l, r)]
for i in range(len(W)):
    print(W[i].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Apr  5 17:16:14 2019

@author: adachi-lab
"""

input_1 = input()
input_2 = input()
l = []
r = []

N = input_1.split()[0]
Q = input_1.split()[1]


for i in range(int(Q)):
    input_3 = input()
    l.append(int(input_3.split()[0]))
    r.append(int(input_3.split()[1]))



list_3 = []
list_4 = []

for w in range(int(Q)):
    word = input_2[(l[w]-1):(r[w])]
    word1 = ''.join(word)
    

    print(word.count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

x = input().split()
n = int(x[0]) # n == 比較文字列の長さ
q = int(x[1]) # q == 検討する回数
s = input()

def ind_Multi(a,b): #a,b == 検索範囲   
    global n
    global s 
    index_L = []
    for i in range(a,b):
        if s[i] == "A":
            index_L.append(i)
    return index_L

            
        

def sc():
    global s
    global n
    global q
    global idbox
    maxx = 0
    count = 0
    com = [int(s)-1 for s in input().split()]
    idbox = ind_Multi(com[0],com[1])
    if not idbox:
        print(0)
        return None
        
    

    
    for i in range(idbox[0],idbox[-1]+1): # i == 先頭の文字
        
        if (s[i+1]) == "C":
            count += 1
            
            
    print(count)

for i in range(q):
    
    sc()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
l=list(S)
n=[0]*(N-1)
for i in range(N-1):
    if l[i]=='A':
        if l[i+1]=='C':
            n[i]=1
o=['']*Q
for i in range(Q):
    l,r=map(int,input().split())
    o[i]=str(sum(n[l-1:r-1]))
print('\n'.join(o))

Submission status: Time Limit Exceeded

Solution code:

x = input().split()
n = int(x[0]) # n == 比較文字列の長さ
q = int(x[1]) # q == 検討する回数
s = input()
def sc():
    global s
    global n
    global q
    maxx = 0
    count = 0
    com = [int(s)-1 for s in input().split()]
    if "A" not in  s[com[0]:com[1]]:
        print(0)
        return None
    if "C" not in s[com[0] +1:com[1] + 1]:
        print(0)
        return None
    for i in range(com[0],com[1]): # i == 先頭の文字
        if (s[i] == "A") and(s[i+1] == "C"):
            count += 1      
    print(count)

for i in range(q):
    sc()

Submission status: Time Limit Exceeded

Solution code:

x = input().split()
n = int(x[0]) # n == 比較文字列の長さ
q = int(x[1]) # q == 検討する回数
s = input()
maxx = 0
count = 0
data = ["A","C","T","G"]

def sc():
    global s
    global n
    global q
    maxx = 0
    count = 0
    com = [int(s)-1 for s in input().split()]
    for i in range(com[0], com[1] ): # i == 先頭の文字
        if (s[i] == "A") and(s[i+1] == "C"):
            count += 1
        
            
    print(count)

for i in range(q):
    sc()

Submission status: Time Limit Exceeded

Solution code:

x = input().split()
n = int(x[0]) # n == 比較文字列の長さ
q = int(x[1]) # q == 検討する回数
s = input()
maxx = 0
count = 0
data = ["A","C","T","G"]

def sc():
    global s
    global n
    global q
    maxx = 0
    count = 0
    com = [int(s)-1 for s in input().split()]
    for i in range(com[0], com[1] + 1): # i == 先頭の文字
        for j in range(i,com[1] ): # j == 動かす文字
            if (s[j] == "A") and(s[j+1] == "C"):
                count += 1
                
            else:
                break
        

    print(count)

for i in range(q):
    sc()

Submission status: Time Limit Exceeded

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

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 = int(input().split()[1])
s = input()

iter = re.finditer('AC', s)

indexes = []
for i in iter:
  indexes.append(i.start())
  
counts = []
for r in range(len(s)):
  c = sum(i < r for i in indexes)
  counts.append(c)

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

Submission status: Time Limit Exceeded

Solution code:
import re
n = int(input().split()[1])
s = input()
for i in range(n):
  l, r = map(int, input().split())
  ma = re.findall('AC', s[l-1: r])
  print(len(ma))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int, input().split())
S = input()
List = []
for i in range(N-1):
  if S[i] == "A":
    if S[i+1] == "C":
      List.append(1)
    else:
      List.append(0)
  else:
    List.append(0)

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

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int, input().split())
S = input()
for i in range(Q):
  l_i, r_i = map(int, input().split())
  A_i = S[l_i - 1 : r_i]
  count_i = 0
  for j in range(len(A_i) - 1):
    if A_i[j] == "A":
      if A_i[j+1] == "C":
        count_i = count_i + 1
  print(count_i)

Submission status: Time Limit Exceeded

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

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())
  tmp = S[l-1:r]
  cnt = 0
  for j in range(len(tmp)-1):
    if tmp[j] == 'A' and tmp[j+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())
  tmp = S[l-1:r]
  print((r - l + 1 - len(tmp.replace('AC', '')))//2)

Submission status: Time Limit Exceeded

Solution code:
try:
    N, Q = map(int, input().split())
except:
    print('2つのパラメータを入力してください')
    exit(0)
try:
    S = input()
    if len(S) != int(N):
        raise
except:
    print('Nと文字数が一致していません')

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

for j in inputArray:
    _string = S[ int(j[0])-1:int(j[1]) ]
    print(_string.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)]

for i in range(Q):
  tmp = S[L[i][0]-1:L[i][1]]
  print((len(tmp) - len(tmp.replace('AC', '')))//2)

Submission status: Time Limit Exceeded

Solution code:
import re
ACGT = ['A', 'C', 'G', 'T']
try:
    N, Q = input().split()
except:
    print('2つのパラメータを入力してください')
    exit(0)
try:
    S = input()
    if len(S) != int(N):
        raise
except:
    print('Nと文字数が一致していません')

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

for j in inputArray:
    _string = S[ int(j[0])-1:int(j[1]) ]
    print(_string.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
import re
ACGT = ['A', 'C', 'G', 'T']
try:
    N, Q = input().split()
except:
    print('2つのパラメータを入力してください')
    exit(0)
try:
    S = input()
    if len(S) != int(N):
        raise
    # 文字列がACGTのみであること
except:
    print('Nと文字数が一致していません')

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

for j in inputArray:
    # lからrまでの区間を抽出
    _string = S[ int(j[0])-1:int(j[1]) ]
    # 抽出した文字列の中にACがいくつ含まれるか
    print(_string.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
_, num_query = list(map(int,input().split()))
string = input()
for _ in range(num_query):
  left, right = list(map(int,input().split()))
  sub_string = string[left-1:right]
  print(sub_string.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
_, num_query = list(map(int,input().split()))
string = input()
import re
pa = re.compile(r"(AC)")
for _ in range(num_query):
  left, right = list(map(int,input().split()))
  sub_string = string[left-1:right]
  print(len(pa.findall(sub_string)))

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())
  s=S[l-1:r]
  #print(s)
  c=0
  for j in range(len(s)-1) :
    if s[j]=='A'  and s[j+1]=='C' :
      c+=1
  print(c)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = str(input())
l,r = [0]*Q,[0]*Q
for i in range(Q):
    l[i],r[i] = map(int,input().split())
    
count_list = []
for i in range(1,N-1):
    if S[i-1] == "A" and S[i] == "C":
        count_list.append(1)
    else:
        count_list.append(0)
    
for j in range(Q):
    sub_count = count_list[l[j]-1:r[j]-1]
    print(sum(sub_count))
        

a = [1,2,3,4]
b = a[0:2]

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())
  s=S[l-1:r]
  c=0
  for j in range(len(s)-1) :
    if s[j]=='A' :
      if s[j+1]=='C' :
        c+=1
  print(c)

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)]
for i in range(q):
    l,r=lr[i][0]-1,lr[i][1]-1
    ans=0
    s_parts = S[l:r+1]
    ans=s_parts.count("AC")
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Apr  4 14:43:20 2019

@author: fumito
"""

def count(lr,S):
    sub = S[int(lr[0])-1:int(lr[1])]
    sub = [i for i in sub]
    A_index = [i for i,x in enumerate(sub) if x == 'A']
    count = 0
    for i in A_index:
        if i == len(sub)-1:
            pass
        elif sub[i+1] == 'C':
            count += 1
        else:
            pass
    return count

if __name__ == "__main__":
    N,Q = map(int,input().split())
    S = str(input())
    lr = [input().split() for i in range(Q)]
    

    for i in range(Q):
        Count = count(lr[i],S)
        print(Count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Apr  4 14:43:20 2019

@author: fumito
"""

def create_sub(lr,S):
    sub = S[int(lr[0])-1:int(lr[1])]
    list = [i for i in sub]
    return list

def A_index(sub):
    A_index = [i for i,x in enumerate(sub) if x == 'A']
    return A_index

def count(sub,index):
    count = 0
    for i in index:
        if i == len(sub)-1:
            pass
        elif sub[i+1] == 'C':
            count += 1
        else:
            pass
    return count

if __name__ == "__main__":
    N,Q = map(int,input().split())
    S = str(input())
    lr = [input().split() for i in range(Q)]
    
    ans = []
    for i in range(Q):
        Sub = create_sub(lr[i],S)
        Index = A_index(Sub)
        Count = count(Sub,Index)
        ans.append(Count)
    for j in ans:
        print(j)

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())
ac_index = []
for i in range(n - 1):
    if s[i] + s[i + 1] == 'AC':
        ac_index.append(i)
for i in range(0, q):
    count = 0;
    for j in ac_index:
        if l[i] - 1 <= j <  r[i] - 1:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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

for i  in range(N-1):
    if S[i]=='A' and S[i+1]=='C':
        A.append(i+2)
for i in range(Q):
    L=list(map(int,input().split()))
    print(sum(L[0]< x <=L[1] for x in A))

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())
ac_index = [False] * n
for i in range(n - 1):
    if s[i] + s[i + 1] == 'AC':
        ac_index[i] = True
for i in range(0, q):
    count = 0;
    for j in range(l[i] - 1, r[i] - 1):
        if ac_index[j]:
            count += 1
    print(count)

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
t = [0] * (N-1)
for n in range(N-1):
    if S[n:n+2] == "AC":
        t[n] = 1
for q in range(Q):
    l, r = map(int, input().split())
    print(sum(t[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())
    s = S[l-1:r]
    print(s.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Apr  4 14:43:20 2019

@author: fumito
"""

def create_sub(lr,S):
    sub = S[int(lr[0])-1:int(lr[1])]
    return sub

def trans(sub):
    trans_list = []
    for i in sub:
        if i == "A":
            trans_list.append(0)
        elif i == 'C':
            trans_list.append(1)
        else:
            trans_list.append(2)
    return trans_list

def count(trans):
    count = 0
    flg = 0
    for j in trans:
        if j ==0:
            flg = 1 
        elif j == 1:
            if flg == 1:
                count += 1
                flg = 0
            else:
                flg = 0
        else:
            flg = 0
    return count


if __name__ == "__main__":
    N,Q = map(int,input().split())
    S = str(input())
    lr = [input().split() for i in range(Q)]
    
    ans = []
    for i in range(Q):
        Sub = create_sub(lr[i],S)
        Trans = trans(Sub)
        Count = count(Trans)
        ans.append(Count)
    for j in ans:
        print(j)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque


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

Submission status: Time Limit Exceeded

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

for i in range(n + 1):
    a.append(s[:i].count('AC'))

for i in range(q):
    print(a[d[i][1]]-a[d[i][0]])

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = str(input())
a = []
b = []
for i in range(q):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

for i in range(q):
    print(s[a[i]-1:b[i]].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = str(input())
a = []
b = []
for i in range(q):
    x, y = map(int, input().split())

    c = s[x-1:y]
    d = c.count('AC')
    print(d)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = str(input())
a = []
b = []
for i in range(q):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

    c = s[a[i]-1:b[i]]
    d = c.count('AC')
    print(d)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = str(input())
a = []
b = []
for i in range(q):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

ss = []
ll = []
for i in range(q):
    c = s[a[i]-1:b[i]]
    d = c.count('AC')
    print(d)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = str(input())
a = []
b = []
for i in range(q):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

for i in range(q):
    c = s[a[i]-1:b[i]]
    d = c.replace('AC','A')
    print(len(c)-len(d))

Submission status: Time Limit Exceeded

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

for s_w in w:
	count = 0
	for index in range(int(s_w[0])-1,int(s_w[1])-1):
		if(s[index:index+2] == "AC"):
			count += 1
	print(count)

Submission status: Time Limit Exceeded

Solution code:

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

for s_w in w:
	print(s[int(s_w[0])-1:int(s_w[1])].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
o=[''] * Q
for i in range(Q):
    l,r=map(int,input().split())
    o[i]=str(S[l-1:r].count('AC'))
print('\n'.join(o))