Problem:


Score : 300 points

Problem Statement

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

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

Notes

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

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

Constraints

2 \leq N \leq 10^5

1 \leq Q \leq 10^5

S is a string of length N.

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

1 \leq l_i < r_i \leq N

Input

Input is given from Standard Input in the following format:

N Q
S
l_1 r_1
:
l_Q r_Q

Output

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

Sample Input 1

8 3
ACACTACG
3 7
2 3
1 8

Sample Output 1

2
0
3

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

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

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



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


Sample output:
2
0
3

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S_temp = input()
L = [0] * (Q+1)
R = [0] * (Q+1)
S = [c for c in S_temp]
result = [0] * Q
flag = [0] * len(S)

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

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

for i in range(Q):
  result = sum(flag[L[i]-1:R[i]])
#  print(flag[L[i]-1:R[i]])
  if S[L[i]-1] == 'C' and flag[L[i]-1] == 1:
    result -= 1
  if S[R[i]-1] == 'A' and flag[R[i]-1] == 1:
    result -= 1
  print(result//2)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S_temp = input()
L = [0] * Q
R = [0] * Q
S = [c for c in S_temp]
result = [0] * Q

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

for i in range(Q):
  length = R[i]-L[i]+1
  for j in range(length-1):
    if S[L[i]-1+j] == 'A' and S[L[i]-1+j+1] == 'C':
      result[i] += 1
  print(result[i])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import re
prog = re.compile('AC')
N, Q = [int(x) for x in input().split()]
S = input()
result = prog.finditer(S)
#pos = np.array([res.start()+1 for res in result])
pos = [res.start()+1 for res in result]

for _ in range(Q):
  l, r = [int(x) for x in input().split()]
  ans = 0
  for p in pos:
    if p>=l and p<=r-1:
      ans += 1
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import re
prog = re.compile('AC')
N, Q = [int(x) for x in input().split()]
S = input()
result = prog.finditer(S)
pos = np.array([res.start()+1 for res in result])

for _ in range(Q):
  l, r = [int(x) for x in input().split()]
  print(np.count_nonzero(np.logical_and(pos>=l, pos<=r-1)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import re
prog = re.compile('AC')
N, Q = [int(x) for x in input().split()]
S = input()
result = prog.finditer(S)
pos = np.array([res.start()+1 for res in result])

for _ in range(Q):
  l, r = [int(x) for x in input().split()]
  print(len(pos[np.logical_and(pos>=l, pos<=r-1)]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def moji(s,a,b):
  s = s[a-1:b]
  re= s.count("AC")
  return re

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

s = input()

for i in range(M):
  a,b = map(int,input().split())
  ans = moji(s,a,b)
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re
n , q = list(map(int,input().split()))
s = input()
listL = []
listR = []
for i in range(q):
    l,r = list(map(int,input().split()))
    listL.append(l)
    listR.append(r)
    
for j in range(q):
    ans = re.findall(r'AC',s[listL[j] - 1:listR[j]])
    print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int,input().split())
s = input()
a = [0 for _ in range(m)]
for i in range(m):
    x, y = map(int,input().split())
    a[i] = s[x-1:y].count("AC")
print(*a,sep="\n")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

N,Q = map(int, input().split())
s = input()
point = [0]*N
for n in range(N):
    if s[n:n+2]=='AC':
        point[n]=1
for q in range(Q):
    l,r = map(int, input().split())
    print(sum(point[l-1:r-1]))

Submission status: Time Limit Exceeded

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

N,Q = map(int, input().split())
s = input()
point = []
for n in range(N):
    if s[n:n+2]=='AC':
        point.append(n)
for q in range(Q):
    l,r = map(int, input().split())
    count = 0
    for p in point:
        if l-1 <= p < r-1: 
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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

N,Q = map(int, input().split())
s = input()
for q 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()
acCount = [0]*len(S)

count = 0
for i in range(len(S)-1):
  if S[i]=='A' and S[i+1]=='C':
    count += 1
    acCount[i+1] = count

for i in range(Q):
  L,R = map(int, input().split())
  print(max(max(acCount[L:R]) - max(acCount[0:L]),0))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int, input().split())
S = input()
acCount = [0]*len(S)

count = 0
for i in range(len(S)-1):
  if S[i]=='A' and S[i+1]=='C':
    acCount[i+1] = 1

for i in range(Q):
  L,R = map(int, input().split())
  print(sum(acCount[L:R]))

Submission status: Time Limit Exceeded

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

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

for i in range(Q):
    start, end = map(lambda x:int(x)-1, input().split())
    ans = sum(AC[start:end+1])
    if AC[end] == 1 and ans != 0:
        ans -= 1
    print(ans)

Submission status: Time Limit Exceeded

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

for i in range(Q):
    start, end = map(int, input().split())
    print(S[start-1:end].count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

input=sys.stdin.readline

N,Q=map(int,input().split())
S=input()
A=[]
B=[]
l=[]

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

for i in range(Q):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

for i in range(Q):    
    count=0
    for item in l:    
        if A[i]<=item and (item+1)<=B[i]:
            count+=1
    print(count)

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

#print(N,Q,S)
#print(lr)

#print(S[0:5])

CC=[]
for _ in range(1,N+1):
    CC.append(S[0:_].count('AC'))

#print(CC)

for _ in range(Q):
    l = lr[_][0]
    r = lr[_][1]

    print(CC[r-1]-CC[l-1])

#for _ in range(Q):
#    l = lr[_][0]
#    r = lr[_][1]
    #print(_,S[0:r],S[0:(l-1)])
    #print(S[0:r].count('AC')-S[0:l].count('AC'))
    #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()

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

#print(N,Q,S)
#print(lr)

#print(S[0:5])

for _ in range(Q):
    l = lr[_][0]
    r = lr[_][1]
    #print(_,S[0:r],S[0:(l-1)])
    #print(S[0:r].count('AC')-S[0:l].count('AC'))
    #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()

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

#print(N,Q,S)
#print(lr)

#print(S[0:5])

for _ in range(Q):
    l = lr[_][0]
    r = lr[_][1]
    #print(_,S[0:r],S[0:(l-1)])
    print(S[0:r].count('AC')-S[0:l].count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(q):
    li, ri = map(int, input().split())
    tmp = s[li-1:ri]
    count = 0
    for j in range(len(tmp)-1):
        if tmp[j] == 'A' and tmp[j+1] == 'C':
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = list(input())
l = len(s)
for i in range(l-1):
  if s[i] == "A" and s[i+1] == "C":
    s[i]= "a"


lis = [0]*(l+1)
for i in range(l+1):
  lis[i] = s[:i].count("a")


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

Submission status: Time Limit Exceeded

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

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

for i in range(Q):
    a,b=map(int,input().split())
    A.append(a-1)
    B.append(b-1) 
    
for i in range(Q):    
    count=0
    for item in l:    
        if A[i]<=item and (item+1)<=B[i]:
            count+=1
    print(count)

Submission status: Time Limit Exceeded

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

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

ans = [S[LR[i][0]-1:LR[i][1]].count('AC') for i in range(Q)]

print(*ans, sep='\n')

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

Submission status: Time Limit Exceeded

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

for i in range(q):
  counter = 0
  a, b = map(int, input().split()) # 3 7
  for i in range(a-1,b-1):
    if 'A' in str[i]  and 'C' in str[i + 1]:
      counter += 1
  print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

t = [0] * n

for i in range(1, n):
    if s[i] == "C":
        if s[i-1] == "A":
            t[i-1] = 1

for i in range(q):
    l, r = lr[i][0]-1, lr[i][1]-1
    print(sum(t[l:r]))

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

import re

pat = "AC"

m_iter = re.finditer(pat, s)

import numpy as np
m_start = np.array([])
for m in m_iter:
    m_start = np.append(m_start, m.start())
    
for i in range(q):
    l = lr[i][0] - 1
    r = lr[i][1] - 1
    contain = (l <= m_start) * (m_start <= r-1)
    print(sum(contain))

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

import re

pat = "AC"

for i in range(q):
    s_part = s[lr[i][0]-1:lr[i][1]]
    m = re.findall(pat, s_part)
    print(len(m))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
c=[i for i in range(n-1) if (s[i]=="A" and s[i+1]=="C")]
d=[list(map(int,input().split())) for i in range(q)]
for i in range(q):
    e=0
    for j in c:
        if d[i][0]-1<=j and j+1<=d[i][1]-1:
            e+=1
    print(e)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(q):
    cnt = 0
    l, r = map(int, input().split())
    for i in range(l-1, r-1):
        if s[i] == 'A':
            if s[i+1] == 'C':
                cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

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

# 2文字の連続部分列はN-1個なので、N-1個のBooleanの配列を生成
b = [S[i]=='A' and S[i+1]=='C' for i in range(N-1)]

for _ in range(Q):
    l,r = map(int,input().split())
    # bのl番目からr-1番目までの和を出力
    print(sum(b[l-1:r-1]))

Submission status: Time Limit Exceeded

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

# 2文字の連続部分列はN-1個なので、N-1個のBooleanの配列を生成
b = [S[i:i+2]=="AC" for i in range(N-1)]

for _ in range(Q):
    l,r = map(int,input().split())
    # bのl番目からr-1番目までの和を出力
    print(sum(b[l-1:r-1]))

Submission status: Time Limit Exceeded

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

n,q = MAP()
s = list(input())
lr = [input().split() for _ in range(q)]
AC_place =[]

for i in range(n-1):
    if s[i]+s[i+1]=="AC":
        AC_place.append(i)

for i in lr:
    tmp=0
    for j in range(int(i[0])-1,int(i[1])-1):
        if j in AC_place:
            tmp+=1
    print(tmp)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
I = [list(map(int,input().split())) for i in range(q)]
AC = []
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        AC += [i]
for i in range(q):
    AC_q = [j for j in AC if I[i][0]-1 <= j <= I[i][1]-2]
    print(len(AC_q))

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=str(input())
now=0
ac=[0 for i in range(N)]
while "AC" in S:
  a=S.index("AC")
  S=S[a+2:]
  #print(S)
  now+=a+2
  ac[now-1]=1
#print(ac)
for i in range(Q):
  s,g=map(int,input().split())
  print(sum(ac[s:g]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count = [0] * (N+1)

for i in range(0, N-1):
    if S[i:i+2] == "AC":
        count[i] = 1

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

Submission status: Time Limit Exceeded

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

count = [0] * N

for i in range(0, N-1):
    if S[i:i+2] == "AC":
        count[i] = 1

for q in range(Q):
    l,r = map(int, input().split())
    print(sum(count[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())
    tmp_s = S[l-1:r]
    i = 0
    count = 0
    while i <= len(tmp_s)-2:
        if tmp_s[i] == 'A' and tmp_s[i+1] =='C':
            count+=1
            i += 2
        else:
            i += 1
    print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, Q = map(int, input().split())
    S = input()
    S_sum = [0] * (N+1)
    for i in range(1,N+1):
        S_sum[i] = S[:i].count('AC')

    for _ in range(Q):
        l, r = map(int, input().split())
        print(S_sum[r]-S_sum[l])


main()

Submission status: Time Limit Exceeded

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

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:
# coding: utf-8
# Your code here!
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(int,input().split())) for _ in range(q)]

for i in range(q):
    start = lr[i][0]-1
    end = lr[i][1]-1
    ans = 0
    for j in range(start,end):
        if s[j] == 'A':
            if s[j+1] == 'C':
                ans += 1
    print(ans)

Submission status: Time Limit Exceeded

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

N, Q = list(map(int, readline().split()))
S = list(readline())
lr = []
for i in range(Q):
    l, r = list(map(int, readline().split()))
    lr.append([l-1, r])

ac = 0
acs = [0 for i in range(N)]
for i in range(N):
    if S[i] == 'A' and ac == 0:
        ac += 1
    elif S[i] == 'C' and ac == 1:
        acs[i - 1] = 1
        ac = 0
    else:
        ac = 0

for i in range(Q):
    l, r = lr[i]
    print(acs[l:r-1].count(1))

Submission status: Time Limit Exceeded

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

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

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:
_, 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()
ans = [0] * q
for i in range(q):
    l, r = map(int, input().split())
    substr = str(s[l - 1:r])
    ans[i] = substr.count("AC")
print(*ans, sep='\n')

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n1, n2 = [int(i) for i in input().split()]
s1 = input()

na1 = [[0] * 2] * n2
 
for i1 in range(n2):
    na1[i1] = [int(j) for j in input().split()]

f1 = False
a1 = [0] * n2

c1 = 0

while True:
    t1 = s1.find("AC", c1)
    if t1 == - 1:
        break
    else:
        for i2 in range(n2):
            if na1[i2][0] <= (t1 + 1) and na1[i2][1] >= (t1 + 2):
                a1[i2] += 1
        c1 = t1 + 1

for i5 in range(n2):
    print(a1[i5])

Submission status: Time Limit Exceeded

Solution code:
import math
import copy
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, q = map(int, input().split())
inputStr = map(str, input())
condi = getSomeInputListInt(q)

string = list(inputStr)

tmpstring = []
for i in range(q):
    cnt = 0
    tmpstring = string[condi[i][0]-1 : condi[i][1]]

    for j in range(len(tmpstring)-1):
       if tmpstring[j]=="A" and tmpstring[j+1]=="C":
           cnt+=1

    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
A = [list(map(int,input().split())) for _ in range(Q)]
AC_list = []
for i in range(N-1):
    if S[i:i+2] == 'AC':
        AC_list.append(1)
    else:
        AC_list.append(0)
for a in A:
    check = AC_list[a[0]-1:a[1]-1]
    print(sum(check))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
A = [list(map(int,input().split())) for _ in range(Q)]
AC_list = []
for i in range(N-1):
    if S[i:i+2] == 'AC':
        AC_list.append(1)
    else:
        AC_list.append(0)
for a in A:
    check = AC_list[a[0]-1:a[1]-1]
    print(sum(check))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

s = s.replace("AC","aC")
t = [0]*(n+1)
i = 0
for i in range(1,n+1):
    t[i] = s[:i].count("a")

for i in range(q):
    a,b = map(int,input().split())
    print((t[b-1])-(t[a-1]))

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 = list(input())
ac = {i+1 for i in range(n-1) if s[i] + s[i+1] == "AC"}
for _ in range(q):
    l, r = map(int, input().split())
    lr = set(range(l, r))
    print(len(ac & lr))

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

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

Submission status: Time Limit Exceeded

Solution code:
def get_ac(n,q,s,l,r):
    pos = []

    for j in range(0,n-1):
        if s[j] == 'A' and s[j+1] == 'C':
            pos.append(j+1)

    p_len = len(pos)
    for i in range(q):
        left = l[i]
        right = r[i]
        count = 0
        for j in range(p_len):
            if left <= pos[j] and pos[j]+1 <= right:
                count += 1
        else:
            print count

if __name__ == '__main__':

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

    l = [0]*q
    r = [0]*q

    for i in range(q):
        l[i],r[i] = map(int,raw_input().split())

#    t2 = time.time()
#    print('{0:.9f}'.format(t2 - t1))
    get_ac(n,q,s,l,r)

Submission status: Time Limit Exceeded

Solution code:
import re
N,Q= [int(i) for i in input().split()]
S= input()
n=[]
for i in range(Q):
	n.append(list(map(int, input().split())))
for i in range(Q):
	print( len(re.findall('AC',S[n[i][0]-1:n[i][1]])) )

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(q):
    ss = ''.join(s[l[i]-1:r[i]])
    ans = ss.count('AC')
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def get_ac(n,q,s,l,r):

    for i in range(q):
        left = l[i]
        right = r[i]
        #print s[left-1:right]
        count = 0
        for j in range(left-1,right-1):
            if s[j] == 'A' and s[j+1] == 'C':
                count += 1
        else:
            print count

if __name__ == '__main__':
    n,q = map(int,raw_input().split())
    s = raw_input()

    l = [0]*q
    r = [0]*q

    for i in range(q):
        l[i],r[i] = map(int,raw_input().split())


    get_ac(n,q,s,l,r)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
text = input()
cnt = 0
for i in range(q):
    l, r = map(int, input().split())
    target = text[l-1:r]
    print(target.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
text = input()
cnt = 0
for i in range(q):
    l, r = map(int, input().split())
    target = text[l-1:r]
    for j in range(len(target)-1):
        if target[j]+target[j+1] == "AC":
            cnt += 1
    print(cnt)
    cnt = 0

Submission status: Time Limit Exceeded

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

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

for l, r in lr:
    print(len([x for x in indexes if l-1 <= x[0] and x[1] <= r-1]))

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

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

    print(p.replace('AC', 'x').count('x'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re

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

Submission status: Time Limit Exceeded

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

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

count = 0
i=0

for i in range(int(Q)):
  a=data_list[i][0]-1
  b=data_list[i][1]
  count = S[a:b].count("AC")
 # print(S[data_list[i][0]-1:data_list[i][1]])
 # print(S[a:b])
  print(count)

Submission status: Time Limit Exceeded

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

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

count = 0
i=0

for i in range(int(Q)):
  
  count = S[data_list[i][0]-1:data_list[i][1]].count("AC")
 # print(S[data_list[i][0]-1:data_list[i][1]])
  print(count)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = list(input())
cusum = [0] * n
c = 0
lr = [[int(x) for x in input().split()] for _ in range(q)]
for j in range(q):
    for i in range(n-1):
        cusum[i] = c
        if s[i:i+2] == ["A", "C"]:
            c += 1
            cusum[i+1] = c
    cusum[n-1] = c
    l, r = lr[j]
    print(cusum[r-1] - cusum[l-1])
    cusum = [0] * n
    c = 0

Submission status: Time Limit Exceeded

Solution code:
# ABC 122, c
n, q = [int(el) for el in input().split(' ')]
s = input()
T = [1 if s[i:i+2] == 'AC' else 0 for i in range(n-1)]


for i in range(q):
    l, r = [int(el) for el in input().split(' ')]
    print(sum(T[(l-1):(r-1)]))

Submission status: Time Limit Exceeded

Solution code:
# ABC 122, c
n, q = [int(el) for el in input().split(' ')]
s = input()
LR = [[int(el) for el in input().split(' ')] for i in range(q)]
T = [1 if s[i:i+2] == 'AC' else 0 for i in range(n-1)]


for l, r in LR:
    print(sum(T[(l-1):(r-1)]))

Submission status: Time Limit Exceeded

Solution code:
# ABC 122, c
n, q = [int(el) for el in input().split(' ')]
s = input()
LR = [[int(el) for el in input().split(' ')] for i in range(q)]

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
SC = [0] * (N - 1)
for i in range(N - 1):
    if S[i:i + 2] == "AC":
        SC[i] = 1

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
SC = [0] * (N - 1)
for i in range(N - 1):
    if S[i:i + 2] == "AC":
        SC[i] = 1

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

Submission status: Time Limit Exceeded

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

for i in range(Q):
    l, r = map(int, input().split())
    c = 0
    for j in range(l - 1, r - 1):
        if S[j:j + 2] == "AC":
            c += 1
    print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

for c in cnts:
	print(c)