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

new_S = S.replace("AC", "12")
# print(new_S)

for i in range(Q):
    left, right = map(int, input().split())
    # print(new_S[left-1:right-1], new_S[left-2:right])
    count_one = new_S[left-1:right-1].count('1')
    # count_two = new_S[left-1:right].count('2')
    print(count_one)

Submission status: Time Limit Exceeded

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

new_S = S.replace("AC", "12")
# print(new_S)

for i in range(Q):
    left, right = map(int, input().split())
    # print(new_S[left-1:right-1], new_S[left-2:right])
    count_one = new_S[left-1:right-1].count('1')
    count_two = new_S[left-1:right].count('2')
    print(min(count_one, count_two))

Submission status: Time Limit Exceeded

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

for i in range(Q):
    left, right = map(int, input().split())
    print(len(S[left-1:right].split("AC"))-1)

Submission status: Time Limit Exceeded

Solution code:
n,q=[int(i) for i in input().split()]
s=input().replace("AC","10")
f=[1 if s[i]=="1" else 0 for i in range(n)]
for i in range(q):
  l,r=[int(i)-1 for i in input().split()]
  print(sum(f[l:r]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input().replace("AC","10").replace("A","0").replace("T","0").replace("C","0").replace("G","0")
for i in range(q):
  l,r=map(int,input().split())
  print(len(s[l-1:r-1].replace("0","")))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=list(map(int,input().replace("AC","1 0 ").replace("A","0 ").replace("T","0 ").replace("C","0 ").replace("G","0 ").split()))
for i in range(q):
  l,r=map(int,input().split())
  print(sum(s[l-1:r-1]))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=list(map(int,input().replace("AC"," 1 0 ").replace("A"," 0 ").replace("T"," 0 ").replace("C"," 0 ").replace("G"," 0 ").replace("  "," ").split()))
for i in range(q):
  l,r=map(int,input().split())
  print(sum(s[l-1:r-1]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
f=[0]*n
for i,a in enumerate(zip(s,s[1:])):
  if a==("A","C"):f[i]=1
for i in range(q):
  l,r=map(int,input().split())
  print(sum(f[l-1:r-1]))

Submission status: Time Limit Exceeded

Solution code:
def solve(n, q, s):
    accm = [0]*n
    for i in range(n-1):
        if s[i:i+2] == 'AC':
            accm[i] = 1
    for j in range(q):
        l, r = map(int, input().split())
        ans = sum(accm[l-1:r])
        print(ans if accm[r-1] != 1 else ans-1)


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

Submission status: Time Limit Exceeded

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

b = []
for i in range(n-1):
	if s[i:i+2] == "AC":
		b.append((i,i+1))
for i in a:
	cnt = 0
	for j in b:
		if (i[0]-1) <= j[0] and j[1] <= (i[1]-1):
			cnt += 1
	print (cnt)

Submission status: Time Limit Exceeded

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

for i in a:
	ss = s[i[0]-1:i[1]]
	t = ss.replace("AC","")
	print (int((len(ss) - len(t))/2))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def print_ans(N, Q, S, arr):
    """Test Case
    >>> print_ans(8, 3, "ACACTACG", [[3, 7], [2, 3], [1, 8]])
    2
    0
    3
    """
    ans_list = [S[ar[0]-1:ar[1]].count("AC") for ar in arr]
    for ans in ans_list:
        print(ans)

if __name__ == '__main__':
    N, Q = map(int, input().rstrip().split())
    S = input().rstrip()
    arr = [list(map(int, input().rstrip().split())) for _ in range(Q)]
    print_ans(N, Q, S, arr)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def print_ans(N, Q, S, arr):
    """Test Case
    >>> print_ans(8, 3, "ACACTACG", [[3, 7], [2, 3], [1, 8]])
    2
    0
    3
    """
    for ar in arr:
        tmp_S = S[ar[0] - 1:ar[1]]
        print(tmp_S.count("AC"))

if __name__ == '__main__':
    N, Q = map(int, input().rstrip().split())
    S = input().rstrip()
    arr = [list(map(int, input().rstrip().split())) for _ in range(Q)]
    print_ans(N, Q, S, arr)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a = input().split(" ")
N = int(a[0])
Q = int(a[1])
s = list(input())
lr = []
ac = []
for i in range(Q):
	lr.append(input().split( ))
for i in range(len(s)-1):
	if s[i] == "A" and s[i+1] == "C":
		ac.append(i)
for i in range(Q):
	answer = 0
	for n in ac:
		if n+1 >= int(lr[i][0]) and n+2 <= int(lr[i][1]):
			answer += 1
	print(answer)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    import re
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    I = []
    for j in range(Q):
        cnt = 0
        l,r = L[j]
        S_2 = ''.join(S[l-1:r])
        print(len(re.findall('AC', S_2)))
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    I = []
    for j in range(Q):
        cnt = 0
        l,r = L[j]
        S_2 = ''.join(S[l-1:r])
        print(S_2.count("AC"))
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    I = []
    for i in range(len(S)-1):
        if S[i] == "A" and S[i+1] == "C":
            I.append(i)
    for j in range(Q):
        cnt = 0
        l,r = L[j]
        R = []
        for i in I:
            if l-1 <= i < r-1:
                cnt += 1
        print(cnt)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    I = []
    for i in range(len(S)-1):
        if S[i] == "A" and S[i+1] == "C":
            I.append(i)
    for j in range(Q):
        cnt = 0
        l,r = L[j]
        R = []
        for k in range(l-1,r-1):
            R.append(k)
        for i in I:
            if i in R:
                cnt += 1
        print(cnt)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,Q = list(map(int, input().split()))
S = list(input())
L = []
for _ in range(Q):
    temp = list(map(int, input().split()))
    L.append(temp)
for i in range(Q):
    ans = 0
    r,l = L[i]
    for j in range(r-1,l-1):
        if S[j] == "A" and 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())
  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):
    a,b = map(int, input().split())
    L.append(a)
    R.append(b)

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

Submission status: Time Limit Exceeded

Solution code:
import time

n,q = (int(i) for i in input().split())
s = input()

#starttime = time.time()
pos = [0]*n
for i in range(len(s)-1) :

  if s[i:i+2] == "AC" : pos[i]=1

#print(time.time()-starttime)

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

Submission status: Time Limit Exceeded

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

for i in range(q) :
  a,b = (int(i) for i in input().split())
  c = s[a-1:b]
  lenc = len(c)
  c = c.replace("AC","")
  delta = lenc - len(c)
  if delta != 0 : print(delta // 2)
  else:
    print(0)

Submission status: Time Limit Exceeded

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

for i in range(q) :
  a,b = (int(i) for i in input().split())
  c = s[a-1:b]
  lenc = len(c)
  c = c.replace("AC","")
  delta = lenc - len(c)
  if delta != 0 : print(delta // 2)
  else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
'''
c=[]
for i in range(n-1):
  if s[i:i+2]=='AC':
    c.append(1)
  else:
    c.append(0)
for i in range(q):
  l,r=map(int,input().split())
  print(sum(c[l-1:r-1]))
'''
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())
list_aaa = [list(map(int,input().split())) for i in range(Q)]

for i in list_aaa:
    target =S[(i[0]-1):i[1]]
    print(target.count("AC"))

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

Submission status: Time Limit Exceeded

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

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())
    left = S[l - 1]
    num = 0
    for i in range(l, r):
        right = S[i]
        if left == "A" and right == "C":
            num += 1
    print(num)

Submission status: Time Limit Exceeded

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

ac = []

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

for i in range(Q):
    Sum1 = list(filter(lambda x: l[i] < x, ac))
    Sum2 = list(filter(lambda x: x < r[i], Sum1))
    print(len(Sum2))

Submission status: Time Limit Exceeded

Solution code:
N,Q = input().split()
N,Q = int(N),int(Q)
S = input()
l,r = [],[]
for i in range(Q):
    l_,r_ = input().split()
    l_,r_ = int(l_)-1,int(r_)-1
    l.append(l_)
    r.append(r_)
    
for i in range(Q):
    print(S[l[i]:r[i]+1].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())
    ss = s[l-1:r]
    for j in range(len(ss)-1):
        if ss[j] == 'A' and ss[j+1] == 'C':
            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=str(input())
count=0
M=len(S)
S_AC=[0]*M
for i in range(M-1):
  if S[i]=='A' and S[i+1]=='C':
    S_AC[i]=1
for j in range(Q):
  l,r=map(int,input().split())
  print(sum(S_AC[l-1:r-1]))

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

Submission status: Time Limit Exceeded

Solution code:
import re
n,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())

counts = [0]*n

pattern = "AC"
result = re.finditer(pattern, s)
for res in result:
  counts[res.start()] = 1

cum_counts = [sum(counts[:i]) for i in range(n)]

#print(s)
#print(cum_counts)

for i in range(q):
  ret = cum_counts[r[i]-1] - cum_counts[l[i]-1]
  print(ret)

Submission status: Time Limit Exceeded

Solution code:

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

counts = [1 if s[i]=="A" and s[i+1]=="C" else 0 for i in range(n-1)]

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

Submission status: Time Limit Exceeded

Solution code:
import re
n,q = map(int, input().split())
s = input()
l = [0]*q
r = [0]*q
counts = [0]*n

pattern = "AC"
result = re.finditer(pattern, s)
for res in result:
  counts[res.start()] = 1

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

Submission status: Time Limit Exceeded

Solution code:
import re
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())

counts = [0]*n

pattern = "AC"
result = re.finditer(pattern, s)
for res in result:
  counts[res.start()] = 1

for i in range(q):
  print(sum(counts[l[i]-1:r[i]-1]))

Submission status: Time Limit Exceeded

Solution code:
import re
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())

counts = [0]*n

pattern = "AC"
result = re.finditer(pattern, s)
for res in result:
  counts[res.start()] = 1

for i in range(q):
  tmp = counts[l[i]-1:r[i]]
  if tmp[-1]==1:
    tmp[-1]=0
  ret=sum(tmp)
  print(ret)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
l = []
r = []
for i in range(q):
    li,ri = map(int,input().split())
    l.append(li)
    r.append(ri)
  
al = [0]*n  
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        al[i] = 1
        
for j in range(q):
    left = l[j]
    right = r[j]
    print(sum(al[left-1:right-1]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,Q = [int(i) for i in input().split()]
S = str(input())
lrlist = []
for i in range(Q):
    lrlist.append([int(i)-1 for i in input().split()])

#print(S)
#print(lrlist)

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


for l,r in lrlist:
    ans = 0
    for i in Asite:
        if l <= i and i+1 <= r:
            ans+=1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,Q = [int(i) for i in input().split()]
S = str(input())
lrlist = []
for i in range(Q):
    lrlist.append([int(i)-1 for i in input().split()])

#print(S)
#print(lrlist)

import re
result = [i.span() for i in re.finditer("AC",S)]
#print(result)

for l,r in lrlist:
    ans = 0
    for i in result:
        if l <= i[0] and i[0]+1 <= r:
            ans+=1
    print(ans)

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

for i in LR:
    newS=S[i[0]-1:i[1]]
    Ans=(''.join(newS)).count('AC')
    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())
    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())
    ans.append(s[l-1:r].count("AC"))

for _ans in ans:
    print(_ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int,input().split())
S = input()
"""
points = []
for i in range(N-1):
  if S[i] == 'A' and S[i+1] == 'C':
    points.append(i)
for _ in range(Q):
  r, l = map(int,input().split())
  List = [n for n in points if n >= r -1 and n+1 <= l-1]
  print(len(List))
"""
for i in range(Q):
  r, l = map(int,input().split())
  S_short = S[r-1:l]
  counter = 0
  for j in range(len(S_short)-1):
    if S_short[j]=='A' and S_short[j+1] == 'C':
      counter +=1
  print(counter)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int,input().split())
S = input()
points = []
for i in range(N-1):
  if S[i] == 'A' and S[i+1] == 'C':
    points.append(i)
for _ in range(Q):
  r, l = map(int,input().split())
  List = [n for n in points if n >= r -1 and n+1 <= l-1]
  print(len(List))

Submission status: Time Limit Exceeded

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

for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        ac_li.append(i+1)
        
for i in range(1,q+1):
    l,r = map(int,input().split())
    print(sum(l<=x<=r-1 for x in ac_li))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# import re
N, Q = map(int, input().split())
S = input()
qs = [tuple(map(int, input().split())) for _ in range(Q)]

# print(qs)

# regex =  re.compile('AC')
for q in qs:
    # print(q)
    print(S[q[0]-1:q[1]].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
import re
N, Q = map(int, input().split())
S = input()
qs = [tuple(map(int, input().split())) for _ in range(Q)]

# print(qs)

regex =  re.compile('AC')
for q in qs:
    # print(q)
    print(len(regex.findall(S[q[0]-1:q[1]])))

Submission status: Time Limit Exceeded

Solution code:
# ABC122-C
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
ind = []
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ind.append(i+1)
cnt_list = [0] * N
tmp = 0
for i in range(N):
    if i in ind:
        tmp += 1
    cnt_list[i] = tmp
##print(cnt_list)

for i in range(Q):
    l = lr[i][0] - 1
    r = lr[i][1] - 1
    print(cnt_list[r] - cnt_list[l])

Submission status: Time Limit Exceeded

Solution code:
# ABC122-C
import numpy as np
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
ind = []
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ind.append(i+1)
##print(ind)
ind = np.array(ind)
##print(ind)
for i in range(Q):
    print(np.count_nonzero((lr[i][0] <= ind) & (ind <= lr[i][1] - 1)))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = list(input())
l = []
r = []
for _ in range(q):
    line = list(map(int, input().split()))
    l.append(line[0])
    r.append(line[1])
acgt = []
for i in range(1, n):
    if s[i-1] == "A" and s[i] == "C":
        acgt.append(1)
    else:
        acgt.append(0)
for i in range(q):
    print(sum(acgt[l[i]-1:r[i]-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()
acIdx = []
i = -1
while True:
    i = s.find('AC', i+1)
    if i == -1:
        break
    acIdx.append(i+1)

for i in range(q):
    l, r = map(int, input().split())
    print(len(list(filter(lambda x: l <= x <= (r-1), acIdx))))

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]
    count=0
    for j in range(r-l):
        if ss[j]=="A":
            if ss[j+1]=="C":
                count+=1
    print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, q = (int(_) for _ in input().split())
s = input()
lr = [[int(_) for _ in 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 = 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 sys
input = sys.stdin.readline

def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))


N,Q=two_int()
S=one_str()

for i in range(Q):
    l,r =two_int()
    print(S[l-1:r].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,Q=two_int()
S=one_str()

for i in range(Q):
    l,r =two_int()
    print(S[l-1:r].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import re
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())
  
where_a=[0]*n
where_c=[0]*n
pattern = "AC"
result = re.finditer(pattern, s)
i=0
for res in result:
  i+=1
  tmp=res.span()
  where_a[tmp[0]]=i
  where_c[tmp[1]-1]=i

  
for i in range(q):
  tmp1 = where_a[l[i]-1:r[i]]
  tmp2 = where_c[l[i]-1:r[i]]
  tmp3 = set(tmp1) & set(tmp2) -{0}
  #print(tmp3)
  print(len(tmp3))

Submission status: Time Limit Exceeded

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

for _ in range(Q):
    l, r = list(map(lambda x: int(x), input().split(' ')))
    l -=1
    r -=1
    ans = 0
    for i in range(l, r):
        # print(S[i:i+2])
        if S[i:i+2] == 'AC':
            ans += 1

    # print(S[l:r+1])
    print(ans)
    # exit()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    n,q = map(int, input().split())
    S = input()
    N = [0]*n

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n,q = map(int, input().split())
    S = input()
    array = [list(map(int,input().split())) for _ in range(q)]
    N = [0]*n

    for i in range(n):
        if S[i:i+2] == 'AC':
            N[i] = 1
    for l,r in array:
        print(sum(N[l-1:r-1]))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

for i in ans:
    print(i)

Submission status: Time Limit Exceeded

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

    for i in range(q):
        count = 0
        S_temp = S[array[i][0]-1:array[i][1]]
        S_temp_len = len(S_temp)
        for j in range(S_temp_len-1):
            if S_temp[j:j+2] == 'AC':
                count += 1
        print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

    for i in range(q):
        count = 0
        S_temp = S[array[i][0]-1:array[i][1]]
        S_temp_len = len(S_temp)
        for j in range(S_temp_len):
            if j == S_temp_len-1:
                break
            if S_temp[j] == 'A':
                if S_temp[j+1] == 'C':
                    count += 1
        print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

    for i in range(q):
        count = 0
        S_temp = S[array[i][0]-1:array[i][1]]
        for j in range(len(S_temp)):
            if j == len(S_temp)-1:
                break
            if S_temp[j] == 'A':
                if S_temp[j+1] == 'C':
                    count += 1
        print(count)


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(1, N):
    if S[i-1]=="A" and S[i]=="C":
        ans[i] = 1

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

Submission status: Time Limit Exceeded

Solution code:
#print("UNKO"[2:3])

N,Q=map(int,input().split())
S=input()
LR=[[list(map(int,input().split())),i,0] for i in range(Q)]
LR=sorted(LR,key=lambda x: x[0][1])
#print(LR)
minl=min([i[0][0] for i in LR])
maxr=max([i[0][1] for i in LR])
Qidx=0
for i in range(minl-1,maxr-1):
    #print(i,Qidx, S[i]+S[i+1])
    if S[i]+S[i+1]=="AC":
        for q in range(Qidx,Q):
            if i+1>LR[q][0][1]-1:
                Qidx=q+1
                continue
            if i<LR[q][0][0]-1:
                continue

            LR[q][2]+=1

LR=sorted(LR,key=lambda x: x[1])
for i in LR:
    print(i[2])

Submission status: Time Limit Exceeded

Solution code:
#print("UNKO"[2:3])

N,Q=map(int,input().split())
S=input()
LR=[[list(map(int,input().split())),i,0] for i in range(Q)]
LR=sorted(LR,key=lambda x: x[0][0])
minl=min([i[0][0] for i in LR])
maxr=max([i[0][1] for i in LR])
Qidx=0
for i in range(minl-1,maxr-1):
    if S[i]+S[i+1]=="AC":
        for q in range(Qidx,Q):
            if i<LR[q][0][0]-1:
                break
            if i+1>LR[q][0][1]-1:
                continue
            LR[q][2]+=1

LR=sorted(LR,key=lambda x: x[1])
for i in LR:
    print(i[2])

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n,q = [int(x) for x in stdin.readline().rstrip().split()]
s = stdin.readline().rstrip()
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(q)]
lin = [0]*n
point = 0
for i in range(n-1):
    if s[i] + s[i+1] == "AC":
        for k in range(i+1,n):
            lin[k] += 1
for j in range(q):
    print(lin[li[j][1]-1]-lin[li[j][0]-1])

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n,q = [int(x) for x in stdin.readline().rstrip().split()]
s = stdin.readline().rstrip()
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(q)]

for i in range(q):
    kotoba = s[li[i][0]-1:li[i][1]]
    kai = kotoba.count("AC")
    print(kai)