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: Runtime Error

Solution code:
def how_many_AC(count_summary, str):
  index = str.find('AC')
  if index == -1:
  	return (count_summary, "")
  else:
    return (count_summary+1, str[index+2:])

def how_many_AC_recursive(count1, str1):
  (count2, str2) = how_many_AC(count1, str1)
  if len(str2) <= 1:
    return count2
  else:
    x = how_many_AC_recursive(count2, str2)
    return x

import sys
sys.setrecursionlimit(10000)
(N, Q) = input().split()
S = input()
for i in range(1, int(Q)+1):
  (l_str, r_str) = input().split()
  l = int(l_str)
  r = int(r_str)
  substr = S[l-1:r]
  out = how_many_AC_recursive(0, substr)
  print(out)

Submission status: Runtime Error

Solution code:
def how_many_AC(count_summary, str):
  index = str.find('AC')
  if index == -1:
  	return (count_summary, "")
  else:
    return (count_summary+1, str[index+2:])

def how_many_AC_recursive(count1, str1):
  (count2, str2) = how_many_AC(count1, str1)
  if len(str2) <= 1:
    return count2
  else:
    x = how_many_AC_recursive(count2, str2)
    return x

(N, Q) = input().split()
S = input()
for i in range(1, int(Q)+1):
  (l_str, r_str) = input().split()
  l = int(l_str)
  r = int(r_str)
  substr = S[l-1:r]
  out = how_many_AC_recursive(0, substr)
  print(out)

Submission status: Runtime Error

Solution code:
# coding: utf-8

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


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

        

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

Submission status: Runtime Error

Solution code:
# coding: utf-8

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


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

        

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

Submission status: Runtime Error

Solution code:
# coding: utf-8

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

## S中で、'AC'であるインデックスを求める
num = [0] * (N+1)
i = 0
for i in range(N):
    if S[i]=='A' and S[i+1]=='C':
        num[i + 1] = num[i] + 1
    else:
        num[i + 1] = num[i]

#print(num)

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

Submission status: Runtime Error

Solution code:
def how_many_AC(count_summary, str):
  index = str.find('AC')
  if index == -1:
  	return (count_summary, "")
  else:
    return (count_summary+1, str[index+1:])

def how_many_AC_recursive(count1, str1):
  (count2, str2) = how_many_AC(count1, str1)
  if len(str2) <= 1:
    return count2
  else:
    x = how_many_AC_recursive(count2, str2)
    return x

(N, Q) = input().split()
S = input()
for i in range(1, int(Q)+1):
  (l_str, r_str) = input().split()
  l = int(l_str)
  r = int(r_str)
  substr = S[l-1:r]
  out = how_many_AC_recursive(0, substr)
  print(out)

Submission status: Runtime Error

Solution code:
# coding: utf-8

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

## S中で、'AC'であるインデックスを求める
index = [0] * N
i = 0
while i < len(S)-1:
    if S[i]=='A' and S[i+1]=='C':
        index[i] = 1
        i += 2
    else:
        i += 1
num = [sum(index[i]) for i in range(N)]

#print('\n')
#print(index)

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

Submission status: Runtime Error

Solution code:
def how_many_AC(count_summary, str):
  index = str.find('AC')
  if index == -1:
  	return (count_summary, "")
  else:
    return (count_summary+1, str[index+2:])

def how_many_AC_recursive(count1, str1):
  (count2, str2) = how_many_AC(count1, str1)
  if len(str2) <= 1:
    return count2
  else:
    x = how_many_AC_recursive(count2, str2)
    return x

(N, Q) = input().split()
S = input()
for i in range(1, int(Q)+1):
  (l_str, r_str) = input().split()
  l = int(l_str)
  r = int(r_str)
  substr = S[l-1:r]
  out = how_many_AC_recursive(0, substr)
  print(out)

Submission status: Runtime Error

Solution code:
def how_many_AC(count_summary, str):
  index = str.find('AC')
  if index == -1:
  	return (count_summary, "")
  else:
    return (count_summary+1, str[index+2:])

def how_many_AC_recursive(count1, str1):
  (count2, str2) = how_many_AC(count1, str1)
  if len(str2) == 0:
    return count2
  else:
    x = how_many_AC_recursive(count2, str2)
    return x

(N, Q) = input().split()
S = input()
for i in range(1, int(Q)+1):
  (l_str, r_str) = input().split()
  l = int(l_str)
  r = int(r_str)
  substr = S[l-1:r]
  out = how_many_AC_recursive(0, substr)
  print(out)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

for i in range(Q):
    s, e = map(int, input().split())
    qlist.append([s-1, e])

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

    print(out)

Submission status: Runtime Error

Solution code:
a, loop = input().split()
string = input()

import re
for i in range(int(loop)):
  j, k = input().split()
  #print(string[int(j)-1:int(k)].count('AC'))  # TLE
  print(re.findall('AC', string[int(j)-1:int(k)])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,q = int(input().split(' '))
str = input()
for i in range(q):
  s,e = int(input().split(' '))
  tmp = s[s-1:e]
  ans = tmp.count('AC')
  print(ans)

Submission status: Runtime Error

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

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

for i in range(Q):
  l, r = T[i][0], T[i][1]
  if l != 1:
    print(total_list[r-2]-total_list[l-2])
  else:
    print(total_list[r-2])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import re

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

S = re.sub('[^AC]+', 'X', S)
print(S)

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

Submission status: Runtime Error

Solution code:
nq = input().split()
n, q = int(nq[0]), int(nq[1])
s = list(input())
r_li = []
l_li = []
t_li = []
for i in range(q):
    rl = input().split()
    l_li.append(int(rl[0]))
    r_li.append(int(rl[1]))
count = 0
i = 0
while True:
    if i == n:
        break
    else:
        if s[i] == "A":
            if i i == n - 1:
                i += 1
                t_li.append(count)
            else:
                if s[i + 1] == "C":
                    t_li.append(count)
                    count += 1
                    t_li.append(count)
                    i += 2
                else:
                    t_li.append(count)
                    i += 1
        else:
            i += 1
            t_li.append(count)
for i in range(q):
    print(t_li[r_li[i] - 1] - t_li[l_li[i] - 1])

Submission status: Runtime Error

Solution code:
def main():
    n, q = split_and_to_int(input().strip())
    s = input().strip()

    res = ""
    pos = []
    for i in range(len(s)):
        if s[i] == 'A' and s[i+1] == 'C':
            i += 1
            pos.append(i)

    for _ in range(q):
        le, re = split_and_to_int(input().strip())
        n = 0
        for v in pos:
            if le <= v < re:
                n += 1
            if re < v:
                break
        res = res + "\n" + str(n)

    print(res.strip())


def split_and_to_int(s):
    return [int(i) for i in s.split()]


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    n, q = split_and_to_int(input().strip())
    s = input().strip()

    res = ""
    pos = []
    for i, v in enumerate(s):
        if s[i] == 'A' and s[i+1] == 'C':
            pos.append(i+1)
            i += 1

    for _ in range(q):
        le, re = split_and_to_int(input().strip())
        n = len([v for v in pos if le <= v < re])
        res = res + "\n" + str(n)

    print(res.strip())


def split_and_to_int(s):
    return [int(i) for i in s.split()]


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    n, q = split_and_to_int(input().strip())
    s = input().strip()

    res = ""
    for _ in range(q):
        l, r = split_and_to_int(input().strip())
        n = 0
        for i in range(l-1, r-2):
            if s[i] == 'A' and s[i+1] == 'C':
                n += 1
                i += 1
        res = res + "\n" + n

    print(res)


def split_and_to_int(s):
    return [int(i) for i in s.split()]


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    n, q = split_and_to_int(input().strip())
    s = input().strip()

    res = ""
    for _ in range(q):
        l, r = split_and_to_int(input().strip())
        n = 0
        for i in range(l-1, r-1):
            if s[i] == 'A' and s[i+1] == 'C':
                n += 1
                i += 1
        res = res + "\n" + n

    print(res)


def split_and_to_int(s):
    return [int(i) for i in s.split()]


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    n, q = split_and_to_int(input().strip())
    s = input().strip()

    res = ""
    for _ in range(q):
        l, r = split_and_to_int(input())
        n = 0
        for i in range(l-1, r-1):
            if s[i] == 'A' and s[i+1] == 'C':
                n += 1
                i += 1
        res += f"{n}\n"

    print(res)


def split_and_to_int(s):
    return [int(i) for i in s.split()]


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
data = [0] * (N+1)
for i in range(N):
    data[i+1] = data[i] + (1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
    l, r =map(int, input().split())
    print(data[r-1] - t[l-1])

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
data = [0] * (N+1)
for i in range(N):
    data[i+1] = data[i] + (1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
    l, r =map(int, input().split())
    print(t[r-1] - t[l-1])

Submission status: Runtime Error

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

list=[0]*(N+1)

for i in range(N):
    list[i+1]=list[i]+1 if a[i:i+2]=="AC" else list[i]
    
for i in range(N):
    l,r = map(int, input().split())
    print(list[r-1]-list[l-1])

Submission status: Runtime Error

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

list=[0]*N+1

for i in range(N):
    list[i+1]=list[i]+1 if a[i:i+2]=="AC" else list[i]
    
for i in range(N):
    l,r = map(int, input().split())
    print(list[r-1]-list[l-1])

Submission status: Runtime Error

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

list=[0]*N

for i in range(N):
    list[i+1]=list[i]+1 if a[i:i+2]=="AC" else list[i]
    
for i in range(N):
    l,r = map(int, input().split())
    print(list[r-1]-list[l-1])

Submission status: Runtime Error

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

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	n,q=map(int, io().split())
	s=list(io())
	
	ss=[0 for _ in s[:-1]]
	for i, (c, cn) in enumerate(zip(s, s[1:])):
		if c=='A' and cn=='C':
			ss[i]=1
	
	#ret=[]
	for i in range(q):
		r,l=map(int, io().split())
		rr=sum(ss[r-1:l])-ss[l-1]
		#ret.append(str(rr))
		print(rr)
		
	#return "\n".join(ret)
	
#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	#print (main(io))
	main(io)

Submission status: Runtime Error

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

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	n,q=map(int, io().split())
	s=list(io())
	
	ss=[0 for _ in s[:-1]]
	for i, (c, cn) in enumerate(zip(s, s[1:])):
		if c=='A' and cn=='C':
			ss[i]=1
	
	#ret=[]
	for i in range(q):
		r,l=map(int, io().split())
		rr=sum(ss[r-1:l])-ss[l-1]
		#ret.append(str(rr))
		print(rr)
		
	#return "\n".join(ret)
	
	
#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	#print (main(io))
	main(io)

Submission status: Runtime Error

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

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	n,q=map(int, io().split())
	s=list(io())
	
	ss=[0 for _ in s[:-1]]
	for i, (c, cn) in enumerate(zip(s, s[1:])):
		if c=='A' and cn=='C':
			ss[i]=1
	
	ret=[]
	for i in range(q):
		r,l=map(int, io().split())
		rr=sum(ss[r-1:l])-ss[l-1]
		ret.append(str(rr))
		
	return "\n".join(ret)
	
	
#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Submission status: Runtime Error

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

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	n,q=map(int, io().split())
	s=list(io())
	
	ss=[0 for _ in s[:-1]]
	for i, (c, cn) in enumerate(zip(s, s[1:])):
		if c=='A' and cn=='C':
			ss[i]=1
	
	print(ss)
	ret=[]
	for i in range(q):
		r,l=map(int, io().split())
		rr=sum(ss[r-1:l])-ss[l-1]
		ret.append(str(rr))
		
	return "\n".join(ret)
	
	
#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split())
s = input()
flag = False
count = 0
li = []

for i in range(n):
    if s[i] == "A":
        flag = True
    if s[i] == "C" and flag is True:
        count += 1
        flag = False
    li.append(count)
    print(li)

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

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split())
s = input()
flag = False
count = 0
li = [0]

for i in s:
    if i == "A":
        flag = True
    if i == "C" and flag is True:
        count += 1
        flag = False
    li.append(count)
    print(li)

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
[N,Q] = list(input())
S = str(input())
for k in range(1,Q+1):
  [l,i] = list(input())
  T = S[l-1:i]
  counter = 0
  n = 0
  while (n+1 != len(T)):
    if (T[n] == "A") and (T[n+1] == "C"):
      counter += 1
    n += 1
  print(counter)

Submission status: Runtime Error

Solution code:
N = int(input())
Q = int(input())
S = str(input())
M = []
for k in range(1,Q+1):
  l = int(input())
  i = int(input())
  T = S[l-1:i]
  counter = 0
  n = 0
  while (n+1 != len(T)):
    if (T[n] == "A") and (T[n+1] == "C"):
      counter += 1
    n += 1
  print(counter)

Submission status: Runtime Error

Solution code:
N = int(input())
Q = int(input())
S = str(input())
M = []
for k in range(1,Q+1):
  i = int(input())
  l = int(input())
  T = S[l:i+1]
  counter = 0
  n = 0
  while (n+1 != len(T)):
    if (T[n] == "A") and (T[n+1] == "C"):
      counter += 1
    n += 1
  print(counter)

Submission status: Runtime Error

Solution code:
N = int(input())
Q = int(input())
S = str(input())
M = []
for k in range(1,Q+1):
  i = int(input())
  l = int(input())
  T = S[i:l+1]
  counter = 0
  n = 0
  while (n+1 != len(T)):
    if (T[n] == "A") and (T[n+1] == "C"):
      counter += 1
    n += 1
  print(counter)

Submission status: Runtime Error

Solution code:
N = int(input())
Q = int(input())
S = str(input())
M = []
for k in range(1,Q+1):
  i = int(input())
  l = int(input())
  T = S[i:l+1]
  counter = 0
  n = 0
  while (n != len(T)):
    if (T[n] == "A") and (T[n+1] == "C"):
      counter += 1
    n += 1
  print(counter)

Submission status: Runtime Error

Solution code:
N = int(input())
Q = int(input())
S = str(input())
M = []
for k in range(1,Q+1):
  i = int(input())
  l = int(input())
  T = S[i:l+1]
  counter = 0
  n = 0
  while (n != len(T)):
    if (T[n] = "A") and (T[n+1] = "C"):
      counter += 1
    n += 1
  print(counter)

Submission status: Runtime Error

Solution code:
N = int(input())
Q = int(input())
S = str(input())
M = []
for k in range(1,Q+1):
  i = int(input())
  l = int(input())
  T = S[i:l+1]
  counter = 0
  n = 0
  while (n != len(T)):
    if (T[n-1] = "A") and (T[n] = "C"):
      counter += 1
    n += 1
  print(counter)

Submission status: Runtime Error

Solution code:
N = int(input())
Q = int(input())
S = str(input())
M = []
for k in range(i,Q+1):
  i = int(input())
  l = int(input())
  T = S[i:l+1]
  counter = 0
  n = 0
  while (n != len(T)):
    if (T[n-1] = "A") and (T[n] = "C"):
      counter += 1
    n += 1
  print(counter)

Submission status: Runtime Error

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

for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)

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

Submission status: Runtime Error

Solution code:
input()
s = input()
ac_locates = []

for i, c in enumerate(s):
    if c == "A":
        if s[i+1] == "C":
            ac_locates.append(i+1)

def seach(start, end):
    bs = True
    first = None
    last = len(ac_locates)
    for i, n in enumerate(ac_locates):
        if bs and n >= start:
            first = i
            bs = False
        if n >= end:
            last = i
            break
    # print(first, last)
    if first == None:
        return 0
    return last - first

# print(ac_locates)
try:
    while True:
        s, e = map(int, input().split())
        # print("case:", s, e)
        print(seach(s, e))
except EOFError:
    pass

Submission status: Runtime Error

Solution code:
input()
s = input()
ac_locates = []

for i, c in enumerate(s):
    if c == "A":
        if s[i+1] == "C":
            ac_locates.append(i+1)

def seach(start, end):
    bs = True
    last = len(ac_locates)
    for i, n in enumerate(ac_locates):
        if bs and n >= start:
            first = i
            bs = False
        if n >= end:
            last = i
            break
    # print(first, last)
    return last - first

# print(ac_locates)
try:
    while True:
        s, e = map(int, input().split())
        # print("case:", s, e)
        print(seach(s, e))
except :
    pass

Submission status: Runtime Error

Solution code:
input()
s = input()
ac_locates = []

for i, c in enumerate(s):
    if c == "A":
        if s[i+1] == "C":
            ac_locates.append(i+1)

def seach(start, end):
    bs = True
    last = len(ac_locates)
    for i, n in enumerate(ac_locates):
        if bs and n >= start:
            first = i
            bs = False
        if n >= end:
            last = i
            break
    # print(first, last)
    return last - first

# print(ac_locates)
try:
    while True:
        s, e = map(int, input().split())
        # print("case:", s, e)
        print(seach(s, e))
except EOFError:
    pass

Submission status: Runtime Error

Solution code:
input()
s = input()
ac_locates = []

for i, c in enumerate(s):
    if c == "A":
        if s[i+1] == "C":
            ac_locates.append(i+1)

def seach(start, end):
    bs = True
    last = len(ac_locates)
    for i, n in enumerate(ac_locates):
        if bs and n >= start:
            first = i
            bs = False
        if n >= end:
            last = i
            break
    print(first, last)
    return last - first

print(ac_locates)
try:
    while True:
        s, e = map(int, input().split())
        print("case:", s, e)
        print(seach(s, e))
except EOFError:
    pass

Submission status: Runtime Error

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

n = len(s)
ary = [0 for i in range(lne(s)+1)]

for i in range(1, N):
    if s[i-1] == 'A' and s[i] == 'C':
        ary[i+1] = ary[i] + 1
    else:
        ary[i+1] = ary[i]

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

cnt_list = [0]*n
jufge = 0

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

for i in range(q):
    print(cnt_list[quiz[i][1] - 1] - cnt_list[quiz[i][0]-1])

Submission status: Runtime Error

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

cnt_list = [0]*n
jufge = 0

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

for i in range(n):
    print(cnt_list[quiz[i][1] - 1] - cnt_list[quiz[i][0]-1])

Submission status: Runtime Error

Solution code:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(np.sum([1 for i in range(len(S)) if S[i:i+1] == "AC"])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
def contain(s):
  
for q in range(Q):
  l, r = map(int, input().split())
  print(S.count('AC',l-1, r))

Submission status: Runtime Error

Solution code:
import re
lines = sys.stdin.readlines()
for line in lines[2:]:
    l, r = map(int, line.split())
    match = re.findall("(AC)", lines[1][l-1:r])
    print(len(match))

Submission status: Runtime Error

Solution code:
I=input
n,q=map(int,I())
s=I()
a=[0]
for i in range(n):a+=[a[i]+(s[i-1:i+1]=='AC')]
for _ in[0]*q:l,r=map(int,I());print(a[r]-a[l])

Submission status: Runtime Error

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

hit = [0] * N

for i in range(0, N - 1):
    hit[i + 1] = hit[i]

    if S[i:i+2] == 'AC':
        hit[i + 1] += 1

for _ in range(0, Q):
    result = hit[r - 1] - hit[l - 1]
    print(result)

Submission status: Runtime Error

Solution code:
N, Q = [int(nq) for nq in input().split(" ")]
S = input()
for i in range(Q):
    li, ri = [int(lr) for lr in input().split(" ")]
    print(s[li-1:ri].count("AC"))

Submission status: Runtime Error

Solution code:
N, Q = [int(nq) for nq in input().split(" ")]
S = input()
s = S.replace("AC", "NM")
for i in range(Q):
    li, ri = [int(lr) for lr in input().split(" ")]
    print(li, ri, S[li-1:ri])
    print(s[li-1:ri].count("NM"))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

from itertools import product

def main():
    N = II()
    A, G, C, T = range(4)
    def code(c0, c1, c2):
        return c0 + 4 * c1 + 16 * c2
    dp = [0] * 64
    dp[code(T, T, T)] = 1
    for _ in range(N):
        tmp = [0] * 64
        for p1, p2, p3 in product(range(4), repeat=3):
            for cur in range(4):
                if (p2, p1, cur) == (A, G, C):
                    continue
                if (p2, p1, cur) == (A, C, G):
                    continue
                if (p2, p1, cur) == (G, A, C):
                    continue
                if (p3, p1, cur) == (A, G, C):
                    continue
                if (p3, p2, cur) == (A, G, C):
                    continue
                tmp[code(cur, p1, p2)] += dp[code(p1, p2, p3)]
                tmp[code(cur, p1, p2)] %= MOD
        dp = tmp
    ans = sum(dp)

    return ans % MOD

print(main())

Submission status: Runtime Error

Solution code:
N, Q = input().split(" ")
N, Q = int(N), int(Q)
S = input()
s = S.replace("AC", "__")
counts = range(Q)
for i in range(Q):
    li, ri = [int(lr) for lr in input().split(" ")]
    print(s[li, ri].count("__"))

Submission status: Runtime Error

Solution code:
N, Q = input().split(" ")
N, Q = int(N), int(Q)
S = input()
s = S.replace("AC", "__")
counts = range(Q)
for i in range(Q):
    li, ri = [int(lr) for lr in input().split(" ")]
    counts[i] = s[li-1, ri].count("__")

print(max(counts))

Submission status: Runtime Error

Solution code:
N, Q = input().split(" ")
N, Q = int(N), int(Q)
S = input()
s = S.replace("AC", "__")
counts = []
for i in range(Q):
    li, ri = [int(lr) for lr in input().split(" ")]
    counts[i] = s[li-1, ri].count("__")

print(max(counts))

Submission status: Runtime Error

Solution code:
x = input().split()
N = int(x[0])
Q = int(x[1])
atcgstr = list(input())

point = []
for i in range(0,len(atcgstr)):
    if atcgstr[i] == 'A':
        if atcgstr[i+1] == 'C':
            point.append(i)
ans = []
for i in range(Q):
    ans.append(0)
    y = input().split()
    a = int(y[0])
    b = int(y[1])
    start = 0
    end = 0
    for j in point:
        if a-1 <= j:
            break
        start += 1
    for j in reversed(point):
        if b-2 >= j:
            break
        end += 1
    ans[i] = len(point) - start - end

for i in ans:
    print(i)

Submission status: Runtime Error

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())
counter=[0]*N
for i in range(len(S)-1):
  if S[i]=="A":
    counter[i]+=counter[i-1]+(S[i+1]=="C")
  else:counter[i]=counter[i-1]
for j in range(Q):
  print(counter[r[j-1]]-counter[l[j-1]])

Submission status: Runtime Error

Solution code:
#coding: utf-8
N, Q = map(int, input().split())
S = input()
T = [0]
for i in range(N):
    if S[i] == "A" and S[i+1] == "C":
        T.append(T[i] + 1)
    else:
        T.append(T[i])
print(T)
for j in range(Q):
    l, r = map(int, input().split())
    print(T[r-1] - T[l-1])

Submission status: Runtime Error

Solution code:
#coding: utf-8
N, Q = map(int, input().split())
S = input()
T = [0]
for i in range(N):
    if S[i] == "A" and S[i+1] == "C":
        T.append(T[i] + 1)
    else:
        T.append(T[i])
for j in range(Q):
    l, r = map(int, input().split())
    print(T[r] - T[l-1])

Submission status: Runtime Error

Solution code:
N,Q = map(int,input().split())
S = input()
p = [0]*(N+1)
a = 0
for i in range(-1,N-1):
    if S[i+1] == "A" and S[i+2]=="C":
        a+=1
    p[i+2]=a
#print(p)
for i in range(Q):
    a,b = map(int,input().split())
    print(p[b-1] - p[a-1])

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
T = [0]*N
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        T[i] = T[i-1] + 1
    else:
        T[i] = T[i-1]
for j in range(Q):
    left, right = map(int, input().split())
    print(T[right]-T[left-1])

Submission status: Runtime Error

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