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:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, Q = MAP()
S = input()

L = []
R = []

for i in range(Q):
    l, r = MAP()
    L.append(l)
    R.append(r)

for i in range(Q):
    bubun_S = S[L[i]-1:R[i]]
    print(bubun_S.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
# C
n, q = map(int, input().split())
a = input()
s = [0]*(n+1)

for i in range(n+1):
    s[i] = a[:i].count('AC')
    
ans = []
for j in range(q):
    l, r = map(int, input().split())
    ans.append(s[r]-s[l])
    
for v in ans:
    print(v)

Submission status: Time Limit Exceeded

Solution code:
# C
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'))
    
for v in ans:
    print(v)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N, Q = map(int,input().split())
S = input()
ls = []
rs = []
for i in range(Q) :
    l, r = map(int,input().split())
    ls.append(l)
    rs.append(r)

for i in range(Q) :
    print(S[ls[i]-1:rs[i]].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import re
# input
n, q = map(int, input().split())
#a = [0 for i in range(n)]
a = []
s = input()
for k in range(n):
    a.append(1) if s[k:k+2] == 'AC' else a.append(0)
# for m in re.finditer('AC', s):
#    a[m.start()] = 1
for i in range(q):
    l, r = map(int, input().split())
    print(sum(a[l-1:r-1]))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import re
# input
n, q = map(int, input().split())
a = [0 for i in range(n)]
s = input()
for m in re.finditer('AC', s):
    a[m.start()] = 1
for i in range(q):
    l, r = map(int, input().split())
    print(sum(a[l-1:r-1]))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import re
# input
n, q = map(int, input().split())
a = [0 for i in range(n)]
s = input()
for m in re.finditer('AC', s):
    a[m.start()] = 1
for i in range(q):
    l, r = map(int, input().split())
    output = 0
    for j in range(l-1, r-1):
        output += a[j]
    print(output)

Submission status: Time Limit Exceeded

Solution code:
A,B = list(map(int,input().split()))
C = input()
for i in range(B):
    M,R = list(map(int,input().split()))
    print(C[M-1:R].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
def acNumberInString(word):
  count = 0
  while len(word) > 0:
    index = word.find('AC')
    if index == -1:
      return count

    count += 1
    word = word[index+2:]
  return count

N, Q = map(int, input().split())
S = input()
for q in range(Q):
  start, end = map(int, input().split())
  tmp_word = S[start-1:end]
  print(acNumberInString(tmp_word))

Submission status: Time Limit Exceeded

Solution code:
def acNumberInString(word):
  count = 0
  for i in range(len(word) - 1):
    if word[i] == 'A' and word[i+1] == 'C':
      count += 1
  return count


N, Q = map(int, input().split())
S = input()
for q in range(Q):
  start, end = map(int, input().split())
  tmp_word = S[start-1:end]
  print(acNumberInString(tmp_word))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import re
# input
n, q = map(int, input().split())
s = input()
startPosition = [m.start() for m in re.finditer('AC', s)]
for i in range(q):
    l, r = map(int, input().split())
    print(len([j for j in startPosition if (j >= l-1 and j <= r-2)]))

Submission status: Time Limit Exceeded

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

for i,j in lr:
    tmp_S = S[i:j+1]
    cnt = tmp_S.count('AC')
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import re
N, Q = map(int, input().split())
S = input()
l, r = [0]*Q, [0]*Q
for i in range(Q):
    l[i], r[i] = map(int,input().split())
    l[i] -= 1
    r[i] -= 1
lr = zip(l,r)

for i,j in lr:
    tmp_S = S[i:j+1]
    cnt = len(re.findall('AC',tmp_S))
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
  n,q=map(int,input().split())
  s=input()
  lr=[list(map(int,input().split())) for _ in [0]*q]
  for i in range(q):
    print(s[lr[i][0]-1:lr[i][1]].count('AC'))

if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter

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

for i in range(Q):
    num = 0
    l,r = map(int,input().split())
    ans.append(S.count("AC",l-1,r))
for j in ans:
    print(j)

Submission status: Time Limit Exceeded

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

for i in range(q):
    first, last = map(int, input().split())
    print(s.count("AC", first - 1, last))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
tg="AC"
n,q=map(int,input().split())
text=input()
ans=[]

def check():
    l,r=map(int,input().split())
    text_=text[l-1:][:r-1]
    count=re.findall(tg,text_)
    ans.append(len(count))
    
for i in range(q):
    check()

for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
w = [list(map(int, input().split())) for _ in range(q)]
for i in range(q):
    lw, rw = w[i][0], w[i][1]
    tmp = s[lw-1:rw].count('AC')
    print(tmp)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i, k in zip(l, r):
    print(s[i-1:k].count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = [i for i in input()]
questions = [[i-1 for i in map(int,input().split())] for j in range(Q)]
for i in range(len(S)-1):
  if S[i]=='A' and S[i+1]=='C':
    S[i]='a'
    
for q in questions:
  part_S = S[q[0]:q[1]+1]
  ans = part_S.count('a')
  if part_S[-1]=='a':
    ans -= 1
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
info = [list(map(int, input().split())) for _ in range(q)]
ans = []
lt = []
rt = []
all = s.count('AC')
for i in range(n):
    lt.append(all - s[i:].count('AC'))
    rt.append(all - s[:n-i].count('AC'))
rt.reverse()
# print(lt)
# print(rt)
for l, r in info:
    ans.append(all - (lt[l-1] + rt[r-1]))

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

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
info = [list(map(int, input().split())) for _ in range(q)]
ans = []
for l, r in info:
    ans.append(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 = input()
li = []

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

for i in li:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, Q = map(int, input().split())
    S = input()
    for _ in range(Q):
        l, r = [int(v) for v in input().split()]
        l -= 1
        print(count_ac(S[l:r]))


def count_ac(s):
    count = 0
    state = 0
    for c in s:
        if state == 0:
            if c == 'A':
                state = 1
        elif state == 1:
            if c == 'C':
                count += 1
            state = 0
    return count


if __name__ == '__main__':
    main()

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=[int(i) for i in input().rstrip().split()]
S = input().strip()
lr_list=[[int(j) for j in input().split()] for i in range(Q)]

calc_cnt=[]
for i in range(len(S)):
    sub_str = S[:(i+1)]
    cnt = sub_str.count("AC")
    calc_cnt += [cnt]

for l,r in lr_list:
    ans = calc_cnt[r-1] - calc_cnt[l-1]
    print(ans)

Submission status: Time Limit Exceeded

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

for l,r in lr_list:
    
    cnt=0
    for i in range((l-1),r-1):
        if S[i]+S[i+1] == "AC":
            cnt += 1
        
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:

N,Q=[int(i) for i in input().rstrip().split()]
S = input().strip()
lr_list=[[int(j) for j in input().split()] for i in range(Q)]

for l,r in lr_list:
    sub_str = S[(l-1):r]
    cnt = sub_str.count("AC")
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

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


def sol(n, q, s, ll, lr):
    aas = []
    a_append = aas.append
    for i in range(1,n):
        if s[i-1]=="A" and s[i]=="C":
            a_append(i)
    
    rsw = [0]
    a = 0
    rs_append = rsw.append
    for i in range(1,n+1):
        if i in aas:
            a += 1
        rs_append(a)

    ans = 0
    for i in range(q):
        ans = rsw[lr[i]-1]-rsw[ll[i]-1]
        print(ans)

def main():
    
    import sys
    input = sys.stdin.readline 
    l = list(map(int, input().split()))
    n = l[0]
    q = l[1]
    s = input()
    ll = []
    lr = []
    l_append = ll.append
    r_append = lr.append
    for i in range(q):
        l, r = list(map(int, input().split()))
        l_append(l)
        r_append(r)

    sol(n,q,s,ll,lr)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

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


def sol(n, q, s, ll, lr):
    aas = []
    for i in range(1,n):
        if s[i-1]=="A" and s[i]=="C":
            aas.append(i)
    
    rsw = [0]
    a = 0
    for i in range(1,n+1):
        if i in aas:
            a += 1
        rsw.append(a)

    ans = 0
    for i in range(q):
        ans = rsw[lr[i]-1]-rsw[ll[i]-1]
        print(ans)

def main():
    import sys
    input = sys.stdin.readline 
    l = list(map(int, input().split()))
    n = l[0]
    q = l[1]
    s = input()
    ll = []
    lr = []
    for i in range(q):
        l, r = list(map(int, input().split()))
        ll.append(l)
        lr.append(r)
    sol(n,q,s,ll,lr)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

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


def sol(n, q, s, ll, lr):
    aas = []
    for i in range(1,n):
        if s[i-1]=="A" and s[i]=="C":
            aas.append(i)
    rsw = [0]
    a = 0
    
    for i in range(1,n+1):
        if i in aas:
            a += 1
        rsw.append(a)

    for i in range(q):
        ans = rsw[lr[i]-1]-rsw[ll[i]-1]
        print(ans)

def main():
    import sys
    input = sys.stdin.readline 
    l = list(map(int, input().split()))
    n = l[0]
    q = l[1]
    s = input()
    ll = []
    lr = []
    for i in range(q):
        l, r = list(map(int, input().split()))
        ll.append(l)
        lr.append(r)
    sol(n,q,s,ll,lr)

main()

Submission status: Time Limit Exceeded

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

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


def sol(n, q, s, ll, lr):
    aas = []
    for i in range(1,n):
        if s[i-1]=="A" and s[i]=="C":
            aas.append(i)
    rsw = [0]
    a = 0

    for i in range(1,n+1):
        if i in aas:
            a += 1
        rsw.append(a)
    for i in range(q):
        ans = rsw[lr[i]-1]-rsw[ll[i]-1]
        print(ans)

def main():
    import sys
    input = sys.stdin.readline 
    l = list(map(int, input().split()))
    n = l[0]
    q = l[1]
    s = input()
    ll = []
    lr = []
    for i in range(q):
        l, r = list(map(int, input().split()))
        ll.append(l)
        lr.append(r)
    sol(n,q,s,ll,lr)

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil

    #mod = 1000000007

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

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil

    #mod = 1000000007

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil

    #mod = 1000000007

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

if __name__ == '__main__':
    main()

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
s = S[:2]
ans = 'AC'
lst = []
for i in range(N-1):
    s = S[i] + S[i + 1]
    lst.append(s == ans)

for _ in range(Q):
    a, b = map(int, input().split())
    res = 0
    for i in range(a - 1, b - 1):
        res += lst[i]
    print(res)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
s = S[:2]
ans = 'AC'
lst=[s == ans]
for i in range(1, N-1):
    s = s[1:] + S[i + 1]
    lst.append(s == ans)

for _ in range(Q):
    a, b = map(int, input().split())
    res = 0
    for i in range(a - 1, b - 1):
        res += lst[i]
    print(res)

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

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 range(Q):
    ans=S[LR[i][0]-1:LR[i][1]]
    #print(ans)
    print(ans.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)]
for i in range(Q):
    ans=[]
    ans.append(S[LR[i][0]-1:LR[i][1]])
    #print(ans)
    print(ans[0].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())
    sub = s[l-1:r]
    print(sub.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()
L=[0]*Q
P=[0]*Q
for i in range(Q):
	L[i],P[i]=map(int,input().split())
for i in range(Q):
	count=0
	D=S[L[i]-1:P[i]]
	print(D.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
L=[0]*Q
P=[0]*Q
for i in range(Q):
	L[i],P[i]=map(int,input().split())
for i in range(Q):
	count=0
	D=S[L[i]-1:P[i]]
	for j in range(len(D)-1):
		if D[j]=="A":
			if D[j+1]=="C":
				count+=1
	print(count)

Submission status: Time Limit Exceeded

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

for i in range(q):
    start = lr_lst[i][0] - 1
    end = lr_lst[i][1]

    str = s[start:end]
    answer = str.count('AC')
    print(answer)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = str(input())
l = []
r = []

for i in range(q):
    l_e, r_e = map(int, input().split())
    l_e -= 1
    l.append(l_e)
    r.append(r_e)

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

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = str(input())
l = []
r = []

for i in range(q):
    l_e, r_e = map(int, input().split())
    l_e -= 1
    l.append(l_e)
    r.append(r_e)

for i in range(q):
    count = 0
    for j in range(l[i], r[i] - 1):
        if s[j] == "A" and s[j+1] == "C":
            count += 1
    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:
import re
N,Q=map(int,input().split())
S=input()
a=[]
for _ in range(Q):
    l,r=map(int,input().split())
    a.append([l,r])
for i, j in enumerate(a):
    news=S[j[0]-1:j[1]]
    cntl= re.findall("AC",news)
    print(len(cntl))

Submission status: Time Limit Exceeded

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

for i in range(q):
    l,r = map(int,input().split())
    ans.append(sum(ac[l:r]))
#ここから出力
for i in ans:
    print(i)

Submission status: Time Limit Exceeded

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

for i in range(q):
    l,r = map(int,input().split())
    ct = [i for i in ac if i >= l and i+1 <= r] 
    an = len(ct)
    ans.append(an)
#ここから出力
for i in ans:
    print(i)

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())
    count = 0
    s_1 = s[l-1:r]
    for i in range(len(s_1)-1):
        if s_1[i]=="A":
            if s_1[i+1]=="C":
                count += 1
    ans.append(count)
#ここから出力
for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
l = []
ans = []
for i in range(q):
    l1 = [int(i) for i in input().split()]
    l.append(l1)
#ここまで入力
for i in l:
    count = 0
    s_1 = s[i[0]-1:i[1]]
    for i in range(len(s_1)-1):
        if s_1[i]=="A":
            if s_1[i+1]=="C":
                count += 1
    ans.append(count)
#ここから出力
for i in ans:
    print(i)

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)]
ac_list = [i+1 for i,(j,k) in enumerate(zip(s[0:len(s)-1],s[1:])) if j+k=='AC']
for i in lr:
    count = 0
    for j in ac_list:
        if j>=i[0] and j<=i[1]-1:
            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)]

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

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = list(input())
#print(s)
for i in range(q):
    x = 0
    l, r =  map(int, input().split())
    y = s[l-1:r]
    y = [i for i in y if i  == 'A' or i  == 'C']
    #print(y)
    for j in range(len(y)-1):
        if y[j] + y[j+1] == 'AC':
            x += 1
    print(x)

Submission status: Time Limit Exceeded

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

x = []
for i in range(q):
  x.append(list(map(int, input().split())))

for i in x:
  print(s[i[0] - 1:i[1]].count('AC'))

Submission status: Time Limit Exceeded

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

    tmp = [0] * (n + 1)

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


    for i in range(q):
        ans = 0
        if q_list[i][1] - q_list[i][0] < 2:
            print(0)
            continue
        tmp = s[q_list[i][0]-1:q_list[i][1]]
        ans = tmp.count('AC')
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

def check(S): #1 moji
    if S == "AC":
        return True
    else:
        return False

ans = [0]*Q

for i in range(Q):
    for j in range(L[i][0]-1,L[i][1]-1):
        if check(S[j:j+2]):
            ans[i]+=1
for i in range(Q):
    print(ans[i])

Submission status: Time Limit Exceeded

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

result = []
for i in range(q):
    left = lr[i][0] - 1
    right = lr[i][1] - 1
    substring = s[left:right + 1]
    ans = 0
    for j in range(1, len(substring)):
        if substring[j - 1] == 'A' and substring[j] == 'C':
            ans += 1
    result.append(ans)

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

Submission status: Time Limit Exceeded

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

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

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

for l, r in lr:
    substr = s[l: r]
    print(substr.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())  # n:文字数，q:問題数
s = list(input())  # 文字列
l = [list(map(int, input().split())) for _ in range(q)]  # 問題
cnt = [0] * q  # cnt list
for i in range(q):
    list = s[l[i][0] - 1:l[i][1]]  # 考えるリスト
    cnt[i] = 0
    for j in range(len(list) - 1):
        if list[j] == 'A' and list[j + 1] == 'C':
            cnt[i] += 1
for k in range(q):
    print(cnt[k])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
s_cnt=[]
for i in range(N):
    s_cnt.append(S[:i+1].count("AC"))
#print(s_cnt)    
for i in range(Q):
    l,r=map(int,input().split())
    if l-2 < 0:
        print(s_cnt[r-1])
    else:    
        print(s_cnt[r-1] - s_cnt[l-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline().rstrip()
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()
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 = [int(x) for x in input().split()]
s = input()
lst = []
for _ in range(q):
    l,r = [int(x) for x in input().split()]
    lst.append([l,r])

c_lst = [x for x in range(n) if s[x] == "C" and s[x-1] == "A"]

cnt = 0
for i in range(q):
    for x in c_lst:
        if x+1 <= lst[i][0]:
            pass
        elif x+1 <= lst[i][1]:
            cnt += 1
        else:
            break
    print(cnt)
    cnt = 0

Submission status: Time Limit Exceeded

Solution code:
n,q = [int(x) for x in input().split()]
s = input()
lst = []
for _ in range(q):
    l,r = [int(x) for x in input().split()]
    lst.append([l,r])

a_lst = [x for x in range(n) if s[x] == "A"]
cnt = 0
for i in range(q):
    for x in a_lst:
        if lst[i][0]-1 <= x and lst[i][1] > x+1:
            if s[x+1] == "C":
                cnt += 1
    print(cnt)
    cnt = 0

Submission status: Time Limit Exceeded

Solution code:
n,q = [int(x) for x in input().split()]
s = input()
lst = []
for _ in range(q):
    l,r = [int(x) for x in input().split()]
    lst.append([l,r])

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

Submission status: Time Limit Exceeded

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

for a in a_n:
    print(S[a[0]-1:a[1]].count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

def main(s):
  ans = 0
  for i in range(len(s)-1):
    if s[i] == 'A' and s[i+1] == 'C':
      ans += 1
  return ans

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