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 = list(input())
l = [list(map(int,input().split())) for i in range(q)]

count = [0]*(n-1)

for i in range(n):
  if s[i] != "A":
    continue
  elif i+1 < n-1 and s[i+1] == "C":
    count[i] = 1  
    
for j in range(q):
  print(sum(count[l[j][0]-1:l[j][1]-1]))

Submission status: Time Limit Exceeded

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

for i in range(q):
  strings = s[l[i][0]-1:l[i][1]]
#  print(strings)
  count = 0
  for j in range(len(strings)):
    if strings[j] != "A":
      continue
    elif j+1 < len(strings) and strings[j+1] == "C":
      count += 1
  print(count)

Submission status: Time Limit Exceeded

Solution code:
quest = []
N, Q = input().split()
N = int(N)
Q = int(Q)
S = input()
for _ in range(Q):
    cnt = 0
    start, end = input().split()
    start = int(start)
    end = int(end)
    for i in range(start-1, end):
        s = S[i]
        if s != 'C':
            continue
        elif S[i-1] == 'A' and i-1 >= start-1:
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
quest = []
N, Q = input().split()
N = int(N)
Q = int(Q)
S = input()
for _ in range(Q):
    tmp = []
    s, e = input().split()
    tmp.append(int(s))
    tmp.append(int(e))
    quest.append(tmp)

# for i in range(Q):
#     print(S.count('AC', quest[i][0]-1, quest[i][1]))
for i in range(Q):
    cnt = 0
    cc = 0
    for j in S[quest[i][0]-1: quest[i][1]]:
        if j != 'A' and j != 'C':
            continue
        elif j == 'A':
            cc = 1
        elif j == 'C' and cc == 1:
            cnt += 1
            cc = 0
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
quest = []
N, Q = input().split()
N = int(N)
Q = int(Q)
S = input()
for _ in range(Q):
    tmp = []
    s, e = input().split()
    tmp.append(int(s))
    tmp.append(int(e))
    quest.append(tmp)

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

Submission status: Time Limit Exceeded

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

for i in range(q):
  l,r=map(int,input().split())
  print(sum(dp[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())
  d=s[l-1:r]
  print(d.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())
    t = s[a-1:b]
    cnt = 0
    for i in range(len(t)-1):
        if t[i] == "A" and t[i+1] == "C":
            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 = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for i in range(Q)]

ans_cnt = 0
ans_idx = []
for i in range(1, N):
    if S[i - 1] + S[i] == 'AC':
        ans_cnt += 1
        ans_idx.append(i)

#print(ans_idx)
for lr in LR:
    cnt = 0
    for idx in ans_idx:
        if lr[0] <= idx < lr[1]:
            cnt += 1
        if lr[1] <= idx:
            break
    print(cnt)

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)]
for i in lr:
  print(s[i[0]-1:i[1]].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]
    ss_rep = ss.replace('AC', '')
    print((len(ss) - len(ss_rep)) // 2)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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

for i in range(Q):
    l, r = lr_list[i]
    l -= 1
    r -= 1
    count = sum(new_S[l:r+1])

    if new_S[l] == 1 and new_S[l+1] == 0:
        count -= 1
    if new_S[r-1] == 0 and new_S[r] == 1:
        count -= 1    
    count = count / 2

    if r - l == 1:
        if S[l] == 'A' and S[r] == 'C':
            count = 1
        else:
            count = 0

    print(int(count))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,Q = (int(X) for X in input().split())
S = input()
AIndex = np.array([Ind for Ind,Str in enumerate(S) if S[Ind:Ind+2]=='AC'])
if len(AIndex)==0:
    print('\n'.join(['0']*Q))
else:
    for T in range(0,Q):
        L,R = (int(X) for X in input().split())
        print(sum(((L-1)<=AIndex)&((R-1)>=AIndex+1)))

Submission status: Time Limit Exceeded

Solution code:
N,Q = (int(X) for X in input().split())
S = input()
AIndex = [Ind for Ind,Str in enumerate(S) if S[Ind:Ind+2]=='AC']
if len(AIndex)==0:
    print('\n'.join(['0']*Q))
else:
    CIndex = [X+1 for X in AIndex]
    for T in range(0,Q):
        L,R = (int(X) for X in input().split())
        if (L-1)>AIndex[-1] or (R-1)<CIndex[0]: print('0')
        else: print(sum([(L-1)<=X and (R-1)>=Y for X,Y in zip(AIndex,CIndex)]))

Submission status: Time Limit Exceeded

Solution code:
N,Q = (int(X) for X in input().split())
S = input()
for T in range(0,Q):
    L,R = (int(X) for X in input().split())
    print(S[L-1:R].count('AC'))

Submission status: Time Limit Exceeded

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

import io
import sys
import math
from functools import lru_cache

def solve(ac_lst,l,r):
    # implement process
    cnt = sum(ac_lst[l-1:r])
    if ac_lst[r-1]==1:
        cnt -= 1
    return cnt

def make_ac_lst(s):
    ac_lst = [0] * len(s)
    for i in range(len(s)-1):
        if s[i] == "A" and s[i+1] == "C":
            ac_lst[i] = 1
    if _DEB: logd(f"{ac_lst}")
    return ac_lst

def main():
    # input
    n,q = map(int, input().split())
    s = input()
    
    # process
    ans = ""
    ac_lst = make_ac_lst(s)

    for _ in range(q):
        l,r = map(int, input().split())
        ans += str( solve(ac_lst,l,r) ) + "\n"
         
    # output    
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
8 3
ACACTACG
3 7
2 3
1 8
"""
_EXPECTED = """\
2
0
3

"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Submission status: Time Limit Exceeded

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

import io
import sys
import math
from functools import lru_cache

@lru_cache(maxsize=None)
def solve(s,l,r):
    # implement process
    str = s[l-1:r]
    return str.count("AC")

def main():
    # input
    n,q = map(int, input().split())
    s = input()
    
    # process
    ans = ""
    for _ in range(q):
        l,r = map(int, input().split())
        ans += str( solve(s,l,r) ) + "\n"
         
    # output    
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
8 3
ACACTACG
3 7
2 3
1 8
"""
_EXPECTED = """\
2
0
3

"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Submission status: Time Limit Exceeded

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

import io
import sys
import math

def solve(s,l,r):
    # implement process
    str = s[l-1:r]
    return str.count("AC")

def main():
    # input
    n,q = map(int, input().split())
    s = input()
    
    # process
    ans = ""
    for _ in range(q):
        l,r = map(int, input().split())
        print(str( solve(s,l,r) ))
         
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
8 3
ACACTACG
3 7
2 3
1 8
"""
_EXPECTED = """\
2
0
3

"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    main()

Submission status: Time Limit Exceeded

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

import io
import sys
import math

def solve(s,l,r):
    # implement process
    str = s[l-1:r]
    return str.count("AC")

def main():
    # input
    n,q = map(int, input().split())
    s = input()
    
    # process
    ans = ""
    for _ in range(q):
        l,r = map(int, input().split())
        ans += str( solve(s,l,r) ) + "\n"
         
    # output    
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
8 3
ACACTACG
3 7
2 3
1 8
"""
_EXPECTED = """\
2
0
3

"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Submission status: Time Limit Exceeded

Solution code:
import copy

N, Q = map(int, input().split())
S = input()
ANSlist = [0]*Q
for i in range(Q):
    l ,r = map(int, input().split())
    SS = copy.deepcopy(S)
    SS = SS[l-1:r]
    for j in range(1,len(SS)):
        if SS[j] == "C" and SS[j-1] == "A":
            ANSlist[i] += 1
    
for i in range(len(ANSlist)):
    print(ANSlist[i])

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:

def solve():
    for i in range(Q):
        cnt = S[lr[i][0]-1:lr[i][1]].count("AC")
#        print(S[lr[i][0]-1:lr[i][1]])
        print(cnt)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
import sys
input = sys.stdin.readline
N,Q = list(map(int,input().split()))
s = input().rstrip()
lis=[]
 
 
for i in range(len(s)):
    count = len(re.findall(r'AC', s[:i+1]))
    lis.append(count)
for i in range(Q):
    l,r = list(map(int,input().split()))
    print(lis[r-1]-lis[l-1])

Submission status: Time Limit Exceeded

Solution code:
import re

N,Q = list(map(int,input().split()))
s = input()
lis=[]


for i in range(len(s)):
    count = len(re.findall(r'AC', s[:i+1]))
    lis.append(count)
for i in range(Q):
    l,r = list(map(int,input().split()))
    print(lis[r-1]-lis[l-1])

Submission status: Time Limit Exceeded

Solution code:
import re

N,Q = list(map(int,input().split()))
s = input()
lis=[]


for i in range(len(s)):
    count = 0
    for m in re.findall(r'AC', s[:i+1]):
        count += 1
    lis.append(count)
for i in range(Q):
    l,r = list(map(int,input().split()))
    print(lis[r-1]-lis[l-1])

Submission status: Time Limit Exceeded

Solution code:
import re

N,Q = list(map(int,input().split()))
s = input()

for q in range(Q):
    l,r = list(map(int,input().split()))
    count = 0
    for m in re.findall(r'AC', s[l-1:r]):
        count += 1
    print(count)

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+1]=="C" and s[i]=="A":
        num[i]+=1
def rtn(num1,num2):
    return sum(num[num1:num2])
for i in range(q):
    l,r=map(int,input().split())
    print(rtn(l-1,r-1))

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

Submission status: Time Limit Exceeded

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

for x in X:
    print(x.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 = 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 _ 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()

positions = []
for i in range(len(S)-1):
    if S[i] == 'A':
        if S[i+1] == 'C':
            positions.append(i)
            i+=1

for i in range(Q):
  L, R = map(int,input().split())
  c =0
  for p in positions:
    if L <= p+1 and p+2 <= R:
        c +=1
  print(c)

Submission status: Time Limit Exceeded

Solution code:
#ABC 122 C - GeT AC 18:47

n, q = map(int, input().split())
s = input()
memo = [0]*(n) #与えられた文字列の何文字目にACが現れるかメモ
for i in range(n-1):
    if s[i:i+2] == 'AC':
        memo[i] = 1

for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    temp = memo[l:r+1]
    res = sum(temp)
    if temp[-1] == 1:
        res -= 1
    print(res)

Submission status: Time Limit Exceeded

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

positions = []
for i in range(len(S)-1):
    if S[i] == 'A':
        if S[i+1] == 'C':
            positions.append(i)
            i+=1

for i in range(Q):
  L, R = map(int,input().split())
  c = 0
  for p in positions:
    if L-1 <= p and R-1 >= p+1:
        c+=1
  print(c)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int,input().split())
S = input()
for i in range(Q):
  L, R = map(int,input().split())
  ps = S[L-1:R]
  print(ps.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:
N,Q=map(int,input().split())
S=input()
for i in range(Q):
    a,b=map(int,input().split())
    print(S[a-1:b].replace('AC','0').count('0'))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(q):
  ans = 0
  l,r=list(map(int,input().split()))
  t=s[l-1:r]
  for j in range(len(t)-1):
    if t[j:j+2] == "AC":
      ans += 1
  print(ans)

Submission status: Time Limit Exceeded

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


n,q=mi()
s=list(input())
dp=[0]*(len(s)-1)
for i in range(len(s)-1):
  if s[i]=='A' and s[i+1]=='C':
    dp[i]=1

ans=[]
for i in range(q):
  l,r=mi()
  ans_=sum(dp[l-1:r-1])
  ans.append(ans_)

[print(i) for i in ans]

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
qlist = []
for i in range(Q):
    t = tuple(map(int, input().split()))
    nt = tuple((t[0] - 1, t[1]))
    qlist.append(nt)

for q in qlist:
    print(S.count('AC', q[0], q[1]))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int, input().split())
s=input()
a=[0]*q
b=[0]*q
for i in range(q):
    a[i], b[i] = map(int, input().split())
    
lst=[0]*(n-1)

for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        lst[i]=1

for i in range(q):
    c=lst[a[i]-1:b[i]-1]
    print(c.count(1))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
l=[list(map(int,input().split())) for _ in range(q)]
d=[0]*n
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    d[i]=1
for j in range(q):
  sm=0
  d2=d[l[j][0]-1:l[j][1]-1]
  print(sum(d2))

Submission status: Time Limit Exceeded

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

import re
pos = [m.end() for m in re.finditer(r'AC', s)]

def cnt(at):
    ret=0
    for p in pos:
        if p>at:
            break
        ret+=1
    return ret

ans=[]    
for _ in range(Q):
    l,r = list(map(int, input().split()))
    ans.append(cnt(r)-cnt(l))

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict 
n,q=map(int,input().split())
s=input()
l=[list(map(int,input().split())) for _ in range(q)]
d= defaultdict(int)
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    d[i]=1
for j in range(q):
  sm=0
  for k in range(l[j][0]-1,l[j][1]-1):
    sm+=d[k]
  print(sm)

Submission status: Time Limit Exceeded

Solution code:
import collections
a,b=map(int,input().split())
c=input()
d=[]
for _ in range(b):
    n,m=map(int,input().split())
    d.append([n,m])
n=len(d)

for i in range(n):
    r=c[d[i][0]-1:d[i][1]]
    print(r.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
def cnt_ac(S,l,r):
    N = len(S)
    T = [0]*(N+1)
    for i in range(N):
        T[i+1] = T[i] + (1 if S[i : i+2] == 'AC' else 0)
    return T[r-1] - T[l-1]


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

for i in range(Q):
    L, R = map(int,input().split())
    print(cnt_ac(S,L,R))

Submission status: Time Limit Exceeded

Solution code:
def cnt_ac(S):
    N = len(S)
    L = []
    R = []
    for i in range(0,N-1,2):
        L.append(S[i]+S[i+1])
    for i in range(1,N-1,2):
        R.append(S[i]+S[i+1])
    return L.count('AC')+R.count('AC')

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

for i in range(Q):
    L, R = map(int,input().split())
    T = S[L-1 : R]
    ans.append(cnt_ac(T))

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())
  l -= 1
  ans = 0
  for j in range(r-l-1):
    if( s[l+j:l+j+2] == "AC" ):
      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:
N,Q = map(int,input().split())

s = list(input())

ans = 0

for _ in range(Q):
    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)
    ans = 0

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
B = []
for s in range(len(S)):
    B.append(S[s])
A = []
for q in range(Q):
    l, r = map(int, input().split())
    cnt = 0
    C = []
    C = S[l-1:r]
    for c in range(len(C)-1):
        if C[c] + C[c+1]  == 'AC':
            cnt += 1
    A.append(cnt)
for a in A:
    print(a)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
x = input().split()  
n,q = int(x[0]), int(x[1])  
a = input() 
l = [] 

for i in range(1,n+1):
  x = a[:i] 
  cnt = x.count('AC') 
  l.append(cnt) 

for i in range(q):
  y = input().split()  
  le,ri = int(y[0]),int(y[1])  
  print(l[ri-1]-l[le-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=str(input())
a=[]
for i in range(n-1):
    if s[i]=='A' and s[i+1]=='C':
        a.append(1)
    else:
        a.append(0)
        
for i in range(q):
    ans=0
    li,ri=map(int,input().split())
    for j in range(li-1,ri-1):
        ans+=a[j]
    print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
l=0
r=0
s=[0 for i in range(N+1)]
s[0]=0

for i in range(1,N+1):
    s[i]=S[0:i].count('AC')

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




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

s=[0 for i in range(N+1)]
s[0]=0

for i in range(1,N+1):
    s[i]=S[0:i].count('AC')

for i in range(Q):
    print(s[r[i]]-s[l[i]])
'''

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

s=[0 for i in range(N+1)]
s[0]=0

for i in range(1,N+1):
    s[i]=S[0:i].count('AC')

for i in range(Q):
    print(s[r[i]]-s[l[i]])

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:
#!/usr/bin/env python3
n, q = map(int, input().split())
s = input()
for i in range(q):
    a, b = map(int, input().split())
    x = s[a-1:b].replace('AC', 'X')
    print(x.count('X'))

Submission status: Time Limit Exceeded

Solution code:
N, Q, S, *_LR = open(0).read().split()
N = int(N)
Q = int(Q)
LR = list(zip(*[map(int, iter(_LR))]*2))

AC = []

for i in range(1, N):
    if S[i-1: i+1] == "AC":
        AC.append(1)
    else:
        AC.append(0)
        
for L,R in LR:
    print(sum(AC[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())
    print(s[l-1:r].count('AC'))

Submission status: Time Limit Exceeded

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

def f(X):
  if len(X) < 2:
    return(0)
  else:
    count = 0
    for i in range(len(X)-1):
      if [X[i],X[i+1]] == ["A","C"]:
        count += 1
      else:
        pass
    return(count)

for i in range(q):
  print(f(s[LR[i][0]-1:LR[i][1]]))

Submission status: Time Limit Exceeded

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

for i in range(n-1):
    if s[i] == "A":
        if s[i+1] == "C":
            ac.append(i)

for _ in range(q):
    l,r = map(int,input().split())
    l -= 1
    r -= 1
    ans = 0
    
    for i in ac:
        if r <= i:
            break
            
        if l <= i < 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:
n,q = map(int,input().split())
s = str(input())
ls = [list(map(int,input().split())) for _ in range(q)]
c = 0
a = [-1]*10**5
for i in range(n-1):
    if s[i] == "A":
        if s[i+1] == "C":
            a[i] = i
a = list(set(a))
a.sort()
del a[0]
for j in range(q):
    (u,t) = (ls[j][0],ls[j][1])
    for k in a:
        if (k >= u-1) and (k <= t-2):
            c += 1
    print(c)
    c = 0

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

n, q = map(int, readline().split())
s = readline().decode().rstrip()

lis = [0]*n
for i in range(n - 1):
    if s[i] + s[i + 1] == 'AC':
        # l.append(i+1)
        lis[i] = 1

for _ in range(q):
    l, r = map(int, readline().split())
    print(sum(lis[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())
    print(s[l-1:r].count("AC"))

Submission status: Time Limit Exceeded

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

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

for i in range(Q):
    a, b = map(int, input().split())
    print(sum(A[:b])-sum(A[:a]))

Submission status: Time Limit Exceeded

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

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

for i in range(Q):
    a, b = map(int, input().split())
    B[i] += sum(A[:b])-sum(A[:a])

for a in B:
    print(a)

Submission status: Time Limit Exceeded

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

for a,b in zip(L,R):
    print(sum(A[:b])-sum(A[:a]))

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

Submission status: Time Limit Exceeded

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

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):
    cnt=0
    S=s[lr[i][0]-1:lr[i][1]]
    for j in range(len(S)-1):
        if S[j]=="A" and S[j+1]=="C":
            cnt+=1
    print(cnt)