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 = input()
l =[0] * Q
r = [0] * Q
for i in range(Q):
    l[i], r[i] = map(int, input().split())

total = 0
for i in range(N):
    total = S.count("AC")

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

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

left = [0] + left
left.append(0)
right = [0] + right
right.append(0)

for i in range(Q):
    res = total - (left[l[i]-1] + right[r[i]+1])
    if l[i] >= 2 and S[l[i]-2] == "A" and S[l[i]-1] == "C":
        res -= 1
    if r[i] <= N-1 and S[r[i]-1] == "A" and S[r[i]] == "C":
        res -= 1
    print(res)

Submission status: Time Limit Exceeded

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

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

total = 0
for i in range(N):
    total = S.count("AC")

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

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

left.insert(0,0)
left.append(0)
right.insert(0,0)
right.append(0)

for i in range(Q):
    res = total - (left[l[i]-1] + right[r[i]+1])
    if l[i] >= 2 and S[l[i]-2] == "A" and S[l[i]-1] == "C":
        res -= 1
    if r[i] <= N-1 and S[r[i]-1] == "A" and S[r[i]] == "C":
        res -= 1
    print(res)

Submission status: Time Limit Exceeded

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

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

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

for l, r in LR:
    ans = lst[r-1] - lst[l-1]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
#122c
N,Q = map(int, input().split())
S = str(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()
QL=[]
for i in range(Q):
    QL.append(list(map(int,input().split())))
    ans=0
    for n in range(QL[i][1] - QL[i][0] -1) :
        if S[n] == "A" and S[n+1] =="C" :
            ans+=1
    print(ans)

Submission status: Time Limit Exceeded

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

dp_list=[[-1 for i in range(N)] for j in range(N)]

def dp():
    for i in range(0,N)[::-1]:
        for j in range(N):
            if i>=j:
                dp_list[i][j]=0
            else:
                if S[i]=="A" and S[i+1]=="C":
                    dp_list[i][j]=dp_list[i+1][j]+1
                else:
                    dp_list[i][j]=dp_list[i+1][j]
    return dp_list

dp()

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

Submission status: Time Limit Exceeded

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

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

for i in range(Q):
    print(sum(A[LR[i][0]-1:LR[i][1]])\
          - int(A[LR[i][1]-1]==1))

Submission status: Time Limit Exceeded

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

dp=[[-1 for i in range(N)] for j in range(N)]

def func(i,j):
    if dp[i][j]>-1:
        ans=dp[i][j]
    else:
        if i>=j:
            ans=0
        else:
            if S[i]=="A" and S[i+1]=="C":
                ans=func(i+1,j)+1
            else:
                ans=func(i+1,j)
        dp[i][j]=ans
    return ans

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

Submission status: Time Limit Exceeded

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

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())
  count = 0
  pre = s[l-1]
  skip = False
  for j in range(l, r):
    if skip:
      skip = False
      pre = s[j]
      continue
    if pre == 'A' and s[j] == 'C':
      count += 1
    elif s[j] != 'A':
      skip = True
    pre = s[j]
  print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
s = input()
for _ in range(q):
    l,r = map(int,input().split())
    ss = s[l-1:r]
    cnt = len([e for e in ss.replace('AC', '1') if e == '1'])
    print(cnt)

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())
    ss = s[(l - 1):r]
    a = 0
    for i in range(len(ss) - 1):
        if ss[i:(i+2)] == "AC":
            a += 1
    print(a)

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# C - GeT AC
N, Q = map(int, input().split())
S = str(input())
A = [list(map(int, input().split())) for i in range(Q)]

for i in range(Q):
    count = 0
    for j in range(A[i][0]-1,A[i][1]-1):
        if S[j] == 'A' and S[j+1] == 'C':
            count += 1
        else:
            pass
    print(count)

Submission status: Time Limit Exceeded

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


def main():
    N, Q = map(int, input().split())
    S = input()[:-1]
    
    A = [[0]*(N+1) for _ in range(N+1)]
    for i in range(1, N-1):
        for j in range(i, N):
            if S[j-1:j+1]=='AC':
                A[i][j+1] = A[i][j] + 1
            else:
                A[i][j+1] = A[i][j]
    # for a in A:
    #     print(a)

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,q=[int(i) for i in input().split()]
s=input()
for i in range(q):
    c=0
    query = (lambda x: [x[0]-1, x[1]])([int(i) for i in input().split()])
    seq = s[query[0]:query[1]]
    for i in range(query[1]-query[0]-1):
        if seq[i:i+2] == "AC":
            c += 1
    print(c)

Submission status: Time Limit Exceeded

Solution code:
n,q=[int(i) for i in input().split()]
s=list(input())
for i in range(q):
    c=0
    query = (lambda x: [x[0]-1, x[1]])([int(i) for i in input().split()])
    seq = s[query[0]:query[1]]
    for i in range(query[1]-query[0]-1):
        if seq[i]+seq[i+1] == "AC":
            c += 1
    print(c)

Submission status: Time Limit Exceeded

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

for i in range(q):
    l, r = map(int, input().split())
    ans = 0
    for num in li:
        if l <= num and num+1 <= r:
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
s = input()
li = []
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        li.append(i+1)
for i in range(q):
    l, r = map(int, input().split())
    ans = 0
    for num in li:
        if l <= num and num+1 <= r:
            ans += 1
    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())
    print(S[l-1:r].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
x,y = map(int,input().split())
str=input()
for i in range(y):
 a,b = map(int,input().split())
 print(str[a-1:b].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import accumulate
input = sys.stdin.readline

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

count = [0]
for i in range(0,n-1):
    if s[i] == 'A' and s[i+1] == "C":
        count.append(1)
    else:
        count.append(0)
count.append(0)

for slr in lr:
    l = slr[0]
    r = slr[1]
    print(sum(count[l:r]))

Submission status: Time Limit Exceeded

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

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

for slr in lr:
    l = slr[0]
    r = slr[1]
    if r<n:
        cs = s[l-1:r]
        print(cs.count("AC"))
    else:
        cs = s[l-1:]
        print(cs.count("AC"))

Submission status: Time Limit Exceeded

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

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

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


for slr in lr:
    l = slr[0]
    r = slr[1]
    res = [i for i in count if i >= l and i < r]

    print(len(res))

Submission status: Time Limit Exceeded

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

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

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


for slr in lr:
    l = slr[0]
    r = slr[1]
    res = 0
    for c in count:
        if c >= l and c < r:
            res += 1
    print(res)

Submission status: Time Limit Exceeded

Solution code:
N, Q =map(int,input().split())
S =input()
LR = [list(map(int,input().split())) for i in range(Q)]
isACinit =[0]*N
for i in range(N-1):
    if S[i]=="A" and S[i+1]=="C":
        isACinit[i] = 1
#ans = [0]*Q
#print(isACinit)
ACsum = sum(isACinit)
for i in range(Q):
    if LR[i][1]-LR[i][0]<N//2:
        print(sum(isACinit[LR[i][0]-1:LR[i][1]-1]))
    else:
        print(ACsum-sum(isACinit[:LR[i][0]-1])-sum(isACinit[LR[i][1]-1:]))

Submission status: Time Limit Exceeded

Solution code:
N, Q =map(int,input().split())
S =input()
LR = [list(map(int,input().split())) for i in range(Q)]
isACinit =[0]*N
for i in range(N-1):
    if S[i]=="A" and S[i+1]=="C":
        isACinit[i] = 1
#ans = [0]*Q
#print(isACinit)
ACsum = sum(isACinit)
for i in range(Q):
    if LR[i][1]-LR[i][0]>N//2:
        print(sum(isACinit[LR[i][0]-1:LR[i][1]-1]))
    else:
        print(ACsum-sum(isACinit[:LR[i][0]-1])-sum(isACinit[LR[i][1]-1:]))

Submission status: Time Limit Exceeded

Solution code:
N, Q =map(int,input().split())
S =input()
LR = [list(map(int,input().split())) for i in range(Q)]
isACinit =[0]*N
for i in range(N-1):
    if S[i]=="A" and S[i+1]=="C":
        isACinit[i] = 1
#ans = [0]*Q
#print(isACinit)
for i in range(Q):
#    ans[i] = sum(isACinit[LR[i][0]:LR[i][1]])
    print(sum(isACinit[LR[i][0]-1:LR[i][1]-1]))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
some=input()
lists=[]
    
for _ in range(q):
    add=list(map(int,input().split()))
    lists.append(add)
for j in range(q):
    nums=0
    nums+=some[lists[j][0]-1:lists[j][1]].count("AC")
    print(nums)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
cnt = []
for i in range(1, len(s)+1):
    cnt.append(s[:i].count('AC'))
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:
n, q = map(int, input().split())
s = input()
cnt = 0
for i in range(q):
    l, r = map(int, input().split())
    for j in range(l - 1, r - 1):
        if s[j] == "A" and s[j + 1] == "C":
            cnt += 1
    print(cnt)
    cnt = 0

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())
  st=s[l-1:r]
  ans = st.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())
  count = 0
  ans = 0
  for st in s[l-1:r]:
    if st=="A":
      count=1
    elif count==1 and st=="C":
      ans+=1
    else:
      count=0
  print(ans)

Submission status: Time Limit Exceeded

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

ss = [0] * (n+1)

for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        for j in range(i, n):
            ss[j+1] += 1


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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, Q=map(int, input().split())
S=input()
indexs=[]
for i in range(N-1):
  if S[i:i+2]=='AC':
    indexs.append(i+1)
    
indexs=np.array(indexs)
    
for i in range(Q):
  l, r=map(int, input().split())
  r-=1
  
  print(np.sum((indexs-l)*(indexs-r)<=0))

Submission status: Time Limit Exceeded

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

num=[0]*N

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(Q):
    start, end = map(int, input().split())
    count = 0
    for j in range(start-1, end-1):
        if S_list[j] == "A" and S_list[j+1] == "C":
            count += 1
        else:
            pass
    print(count)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
A = [0 for _ in range(n-1)]
for i in range(n-1):
  if s[i:i+2] == 'AC':
    A[i] = 1
LR = []
for i in range(q):
  LR.append(list(map(int, input().split())))
  print(sum(a for a in A[LR[i][0]-1:LR[i][1]-1]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################


N, Q = map(int, input().split())
S = input().rstrip()
for i in range(Q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1

    count = 0
    for j in range(l+1, r+1):
        if S[j-1] == 'A' and S[j] == 'C':
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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


if __name__ == "__main__":
    test()

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
S=input()
L=[]
for i in range(n):
    a=S[:i+1].count('AC')
    L.append(a)
for j in range(q):
    s,e=map(int,input().split())
    print(L[e-1]-L[s-1])

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=[i for i in input()]
L=[list(map(int, input().split())) for _ in range(Q)]
d=[]
for j in range(len(S)-1):
  if S[j]=='A' and S[j+1]=='C':
    d.append(j)
for i in L:
  m=0
  for j in range(len(d)):
    if d[j]>=i[0]-1 and d[j]+1<=i[1]-1:
      m+=1
  print(m)

Submission status: Time Limit Exceeded

Solution code:
## C - GeT AC(ABC122)
N,Q=map(int, input().split())
S1=input()
ANS=[]
for i in range(Q):
    l,r=map(int, input().split())
    ANS.append(S1[l-1:r].count("AC"))
for i in range(Q):
    print(int(ANS[i]))

Submission status: Time Limit Exceeded

Solution code:
#C - GeT AC(ABC122)
N,Q=map(int, input().split())
S1=input()
l=0
r=0
ANS=[]
for i in range(Q):
    l,r=map(int, input().split())
    S2=S1[l-1:r].replace("AC","")
    ANS.append((len(S1[l-1:r])-len(S2))/2)
for i in range(Q):
    print(int(ANS[i]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

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

score = [x+y == 'AC' for x, y in zip(s, s[1:])]

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

Submission status: Time Limit Exceeded

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

a = []
for _ in range(q):
    l, r = map(int, input().split())
    a.append(s[l-1:r])

print(*(x.count('AC') for x in a), sep='\n')

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
S=input()
L = []
for i in range(n-1):
    if S[i:i+2]=='AC':
        L.append(i)

for j in range(q):
    c=0
    s,e=map(int,input().split())
    for n in L:
        if s-1<=n<=e-2:
            c+=1
    print(c)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
s = input()
count = []
for i in range(1,n):
  if s[i-1] == 'A' and s[i] == 'C':
    count.append(i-1)

for _ in range(q):
  ans = 0
  l,r = map(int, input().split())
  for j in range(len(count)):
    if l-1 <= count[j] and count[j] < r-1:
      ans += 1
  print(ans)

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

for i in range(q):
  temp_s = s[l[i]-1:r[i]]
  count = 0
  for i in range(1, len(temp_s)):
    if temp_s[i-1] == 'A' and temp_s[i] == 'C':
      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 i in range(q)]

import numpy as np
for i,j in lr:
  print(s[i-1:j].count("AC"))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

lr = []
for _ in range(q):
    l, r = map(int, input().split())
    lr.append([l, r])

for temp in lr:
    l, r = temp
    string = S[l-1:r]

    cnt = 0
    for i in range(len(string)-1):
        if string[i] == "A" and string[i+1] == "C":
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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):
    l,r=map(int,input().split())
    ss = s[l-1:r]
    print(ss.count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def find_AC(S):
  ret = []
  for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
      ret.append(i)
  return ret

N, Q = [int(x) for x in input().split()]
S = input()
result = find_AC(S)
pos = [res+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:
n,q = map(int,input().split())
s = input()
s = s.replace('AC','aC')
ac = []
for i in range(len(s)):
  if s[i] == 'a':
    ac.append(i)

lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  cnt = 0
  for j in range(len(ac)):
    if lr[i][0]-1 <= ac[j] <= lr[i][1] - 2:
      cnt += 1
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
s = s.replace('AC','aC')
lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  temp = list(s[lr[i][0]-1:lr[i][1]])
  cnt = temp[:-1].count('a')
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  temp = list(s[lr[i][0]-1:lr[i][1]])
  cnt = 0
  while len(temp) > 1:
    x = temp.pop()
    y = temp[-1]
    if x == 'C' and y == 'A':
      cnt += 1
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  temp = list(reversed(s[lr[i][0]-1:lr[i][1]]))
  cnt = 0
  while len(temp) > 1:
    x = temp.pop()
    y = temp[-1]
    if x == 'A' and y == 'C':
      cnt += 1
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  temp = s[lr[i][0]-1:lr[i][1]]
  cnt =0
  j = -1
  while True:
    j = temp.find('AC')
    temp = temp[j+1:]
    if j == -1:
      break
    cnt += 1
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  temp = s[lr[i][0]-1:lr[i][1]]
  cnt =0
  j = -1
  while True:
    j = temp.find('AC', j+1)
    if j == -1:
      break
    cnt += 1
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#Ngram
n,q = map(int,input().split())
s = input()
      
def n_gram(target, n): # 基準を1文字(単語)ずつ ずらしながらn文字分抜き出す
  return [ target[idx:idx + n] for idx in range(len(target) - n + 1)]

cut = n_gram(s,2)
  
for i in range(q):
  l,r = map(int,input().split())
  temp = cut[l-1:r-1]
  ans = temp.count("AC")
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
#Ngram
n,q = map(int,input().split())
s = input()
list_s = [i for i in s]
      
def n_gram(target, n): # 基準を1文字(単語)ずつ ずらしながらn文字分抜き出す
  return [ target[idx:idx + n] for idx in range(len(target) - n + 1)]
  
for i in range(q):
  l,r = map(int,input().split())
  temp = "".join(list_s[l-1:r])
  cut = n_gram(temp,2)
  ans = cut.count("AC")
  print(ans)

Submission status: Time Limit Exceeded

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

#元の文字列で"AC"がいくつあるか
ac_list = []
for i in range(n-1):
  if list_s[i]=="A" and list_s[i+1]=="C":
    ac_list.append(1)
  else:
    ac_list.append(0)
      
for i in range(q):
  l,r = map(int,input().split())
  temp = ac_list[l-1:r-1]
  print(sum(temp))

Submission status: Time Limit Exceeded

Solution code:
n,q = [int(i) for i in input().split()]
s = input()
l = [[int(i) for i in input().split()] for _ in range(q)]
for i in l:
    ss = s[i[0]-1:i[1]]
    ss2 = ss.replace('AC','')
    print((len(ss)-len(ss2))//2)

Submission status: Time Limit Exceeded

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

s = input()

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

for i in l:
    ct = 0
    ss = s[i[0]-1:i[1]]
    while ss.find('AC') > -1:
        ss = ss.replace('AC','',1)
        ct += 1
    print(ct)

Submission status: Time Limit Exceeded

Solution code:
import re
x,y  = map(int,input().split())
string = input()

while y>0:
  y-=1
  a,b = map(int,input().split())
  print(string.count("AC",a-1,b))

Submission status: Time Limit Exceeded

Solution code:
import re
x,y  = map(int,input().split())
string = input()

while y>0:
  y-=1
  a,b = map(int,input().split())
  print(string[a-1:b].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import re
x,y  = map(int,input().split())
string = input()

while y>0:
  y-=1
  a,b = map(int,input().split())
  print(len(re.findall('AC',string[a-1:b])))

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
count = [1 if S[i:i+2] =='AC' else 0 for i in range(0,N-1)]
for i in range(0,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 i in range(0,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()
l = []
r = []
for i in range(Q):
    l_, r_ = map(int, input().split())
    l.append(l_)
    r.append(r_)
    
for i in range(Q):
  print(S[l[i]-1:r[i]].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
import re
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(len(re.findall("AC",s)))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S_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(len(S)-1):
  if S[i] == 'A' and S[i+1] == 'C':
    flag[i] = 1
    flag[i+1] = 1

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


  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 and S[R[i]-1] == 'A' and flag[R[i]-1] == 1:
    result -= 2
  print(result//2)

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(len(S)-1):
  if S[i] == 'A' and S[i+1] == 'C':
    flag[i] = 1
    flag[i+1] = 1

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


  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)