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:
i = input()
n, q = int(i.split()[0]), int(i.split()[1])
s = 'ACACTACG'
_list = []

for x in range(0, q):
    i = input()
    _list.append((int(i.split()[0]), int(i.split()[1])))

for x in _list:
    _str = s[x[0]-1:x[1]]
    n = 0
    for y in range(2, len(_str) + 1):
        if _str[y-2:y] == "AC":
            n += 1
    print(n)

Submission status: Runtime Error

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

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

for i in range(Q):
    cnt = 0
    tl,tr = list(map(int,input().split()))
    if num[i] >= tl and num[i]+1 <= tr:
        cnt+=1
    print(cnt)

Submission status: Runtime Error

Solution code:
import copy
N , Q = map(int,input().split())
S = list(input())
l = []
for i in range(Q):
	l.append(list(map(int,input().split())))

indexes = [i for i, x in enumerate(S) if x == "A" and S[i+1] == "C"]



		
for i in range(Q):
	down_lim = l[i][0] - 1.5
	up_lim = l[i][1] - 1.5
	temp_indexes = copy.copy(indexes)
	temp_indexes.append(down_lim)
	temp_indexes.append(up_lim)
	temp_indexes.sort()
	print(temp_indexes.index(up_lim) - temp_indexes.index(down_lim) - 1)

Submission status: Runtime Error

Solution code:
first_line = input()
N, Q = first_line.split(' ')
N = int(N) #length of the input sentence
Q = int(Q) #num of the questions

S = input() #input sentence

numbers_of_AC = []

question_atributes = []
for _ in range(Q):
    start, end = (input().split(' '))
    start = int(start)
    end = int(end)
    
    for c in S:
		if c == 'A':
			count+=1
		else:
			list.append(count)
    		count = 0
	list.append(count)

Submission status: Runtime Error

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

def f(i):
    cnt = 0
    for j in range(i-1):
        #print(s[j:j+2])
        if s[j:j+2] == 'AC':
            cnt += 1
    return cnt

for _ in range(q):
    l, r = list(map(int, input().split()))
    #print(s[l-1:r])
    print(f(r) - f(l))

Submission status: Runtime Error

Solution code:
import numpy as np

N, Q = map(int, input().split())
S = input()
l_list, r_list = [], []
for _ in range(Q):
    l, r = map(int, input().split())
    l_list.append(l)
    r_list.append(r)
    
    
# dp = np.zeros((N+1, N+1))
# # for j in range(0,N,1):
# #     for i in range(0,j,1):
# for i in range(0, N, 1):
#     for j in range(0, N, 1):
#         if i > j or j < 1:
#             continue
#         else:
#             if S[j-1] == "A" and S[j] == "C":
#                 dp[i][j] = dp[i][j-1] + 1
#                 print(j, S[j-1])
#             else:
#                 dp[i][j] == dp[i][j-1]

ac_begin_idx = []
A_flag = False
for idx, char in enumerate(S):
    if A_flag and char =="C":
        ac_begin_idx.append(idx-1)
    elif char == "A":
        A_flag = True
    else:
        A_flag = False
        
table = np.zeros((N,N))
for j in range(N):
    for i in range(j):
        ans = 0
        for idx in ac_begin_idx:
            if idx >= i and idx < j:
                ans+=1
            table[i][j] = ans
# print(table)

for l, r in zip(l_list, r_list):
    l_idx = l -1
    r_idx = r -1
    print(int(table[l_idx][r_idx]))

Submission status: Runtime Error

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

    ans = []
    ac = 'AC'
    for q in range(Q):
        lq, rq = input().split()
        S_sub = S[lq : rq + 1]
        ans.append(S_sub.count(ac))

    # solve
    for q in range(Q):
        print(ans[q])
            


if __name__ == '__main__':
    C()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

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

while Q > 0:
    r, l = input().split()

    s = list(S[int(r)-1:iint(l)])
    counter = 0
    oldsp =''
    while len(s) > 0:
        sp = s.pop(0)
        if sp == "C":
            if oldsp == "A":
                counter+=1
        
        oldsp=sp

    print(counter)
    

    Q -= 1

Submission status: Runtime Error

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

counter = [0 for _ in range(Q)]
index = -1
while True:
	index = S.find("AC", index+1)

	if index == -1:
		break
	
	for i, (l, r ) in enumerate(data):
		if l-1 <= index < r-1:
			counter[i] += 1

for res in counter:
	print(res)

Submission status: Runtime Error

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

for idx in lr:
    sub = S[idx[0] - 1:idx[1]]
    cnt = sub.count("AC")
    print("cnt = {}, sub = {}".format(cnt, sub))
    print(str(cnt))

Submission status: Runtime Error

Solution code:
import sys

str = []

lines = sys.stdin.readlines()
#print(lines)

for i, nyan in enumerate(lines):
    str.append(nyan.strip("\n"))
#print(nyan[0])

cnt = [0] * 3

for i in range(int(str[0][2])):
  for j in range(int(str[2+i][0]), int(str[2+i][2]), 1):
    if str[1][j-1] == 'A':
      if str[1][j] == 'C':
        cnt[i] += 1
  print(cnt[i]\n)

Submission status: Runtime Error

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

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

if len(ls)==0:
	for i in range(Q):
		print(0)
	exit(0)

for j in range(Q):
	for i in range(lr[j][0]):
		if ls[i]>lr[j][0]:
			l=i-1
			break
	for i in range(l,max(l+lr[j][1],len(ls))):
		if i==len(ls):
			r=len(ls)-1
			break
		if ls[i]+1>lr[j][1]:
			r=i-1
			break

	print(r-l+1 if r-l!=0 else 0)

Submission status: Runtime Error

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

S=input()

# 最初からNまでに何個ACがあったか
cnt=[0 for _ in range(N)]

prevA=False

for i in range(N):
	if S[i]=="C":
		if prev=="A":
			cnt[i]+=1
	if i!=0:
		cnt[i]+=cnt[i-1]
	prev = S[i]

for q in range(Q):
 	L,R=map(int,input().split())
 	ans = cnt[R-1]-cnt[L-1]
 	print(ans)

Submission status: Runtime Error

Solution code:
N,Q = input().split()
S = input()
 
p = []
for i in range(int(N)):
  if S[i:i+2] == "AC":
    p.append(i)
 
for i in range(int(Q)):
  l,r = input().split()
  count = 0
  for x in p:
    if x > int(r-2):
      break
    
    if int(l)-1 <= x and x <= int(r)-2:
      count += 1
  print(count)

Submission status: Runtime Error

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


idx = []

for i in range(len(S)):
        if S[i] != "A" and S[i] != "C":
            flag = 0
            continue
        if S[i] == "A":
            flag = 1
            continue
        if S[i] == "C" and flag == 1:
            flag = 0
            idx.append(i-1)
            continue
        if S[i] == "C" and flag == 0:
            continue

#print(idx)
L = []
R = []
for _ in range(Q):
    l,r = map(int,input().split())
    ans = 0
    for i in idx:
        if i in range(l-1,r-1):
            ans += 1
    print(ans)

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
inputl = []
inputr = []
for i in range(0,Q):
    l,r = map(int, input().split())
    inputl.append(l)
    inputr.append(r)
answerlist = []
for j in range(0,Q):
    l = inputl[j]
    r = inputr[j]
    appear = 0
    while(l+k+1<r):
    #for k in range(0,N):
        if(S[l+k-1:l+2+k-1] == 'AC'):
            appear = appear +1
    answerlist.append(appear)
for p in range(0,Q):
    print(answerlist[p])

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import sys

str = []

lines = sys.stdin.readlines()
#print(lines)

for i, nyan in enumerate(lines):
    str.append(nyan.strip("\n"))
#print(nyan[0])

cnt = [0] * 3

for i in range(int(str[0][2])):
  for j in range(int(str[2+i][0]), int(str[2+i][2]), 1):
    if str[1][j-1] == 'A':
      if str[1][j] == 'C':
        cnt[i] += 1

print(cnt)

Submission status: Runtime Error

Solution code:
#ACを検索して開始位置をインデックスにしておき、それを操作すれば多少はマシか
N,Q=[int(i) for i in input().split()]
S=list(input())
hani=[[int(i) for i in input().split()] for j in range(Q)]
ACindex=[i for i in range(N) if S[i]=="A" and S[i+1]=="C"]
for j in hani:
    print(sum([j[0]-1<= k <j[1]-1 for k in ACindex]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
BASE = ['A', 'T', 'C', 'G']

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

cumsum = [0] * N
sumbgn = [0] * N
sumend = [0] * N
tmpsum = 0
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        sumbgn[i-1] = sumbgn[i-2] + 1 if i-2 >= 0 else 1
        sumend[i] = sumend[i-1] + 1
    else:
        sumbgn[i-1] = sumbgn[i-2] if i-2 >= 0 else 0
        sumend[i] = sumend[i-1]

for i in range(Q):
    sumr = sumend[r[i]]
    suml = sumbgn[l[i]-1] if l[i] > 0 else 0
    print(sumr - suml)

Submission status: Runtime Error

Solution code:
import copy
N , Q = map(int,input().split())
S = list(input())
l = []
for i in range(Q):
	l.append(list(map(int,input().split())))

temp_indexes = [i for i, x in enumerate(S) if x == "A"]

indexes = []

for i in range(len(temp_indexes)):
	if S[temp_indexes[i] + 1] == "C":
		indexes.append(temp_indexes[i])
		
for i in range(Q):
	down_lim = l[i][0] - 1.5
	up_lim = l[i][1] - 1.5
	temp_indexes = copy.copy(indexes)
	temp_indexes.append(down_lim)
	temp_indexes.append(up_lim)
	temp_indexes.sort()
	print(temp_indexes.index(up_lim) - temp_indexes.index(down_lim) - 1)

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
s = input()
x = [list(map(int,input().split())) for i in range(q)]
for i in range(q):
    cnt = 0
    t = s[x[i][0]-1:x[i][1]]
    for i in range(len(t)-1):
        if t[i:i+2]=="AC"
            cnt += 1
    print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
NandQ=input() #文字列の長さ＆質問の個数
S=str(input()) #文字列
ListNum=[]
ListNandQ=NandQ.split()
N=int(ListNandQ[0])
Q=int(ListNandQ[1])
for i in range(0,Q,1):
  LandR=input() #質問の入力受付
  ListLandR=LandR.split()
  L=int(ListLandR[0])
  R=int(ListLandR[1])
  moji=S[L-1:R] #文字列の取り出し
  ListNum.append(int(moji.count("AC"))))

for i in range(0,len(ListNum),1):
  print(ListNum[i])

Submission status: Runtime Error

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

import re

for s in S_lr:
    count = len(re.findall('AC', s))
    print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
q = int(input())
s = input()
s = list(s)
cnt = []
l = []
r = []
for i in range(q):
  l.append(int(input()))
  r.append(int(input()))
  cnt.append(0)
for i in range(q):
  for j in range(l[i], r[i]):
    if j == len(s)-1:
      break
    if s[j-1] == 'A' and s[j] == 'C':
      cnt[i] += 1
for i in range(len(cnt)):
  print(cnt[i])

Submission status: Runtime Error

Solution code:
import numpy as np

N, Q = map(int, input().split())
S = input()
ls, rs = [], []
for _ in range(Q):
    l, r = map(int, input().split())
    ls.append(l-1)
    rs.append(r-1)

arr = np.zeros(N, np.int)
# flag = False
# for i in range(N):
#     if S[i] == 'A':
#         flag = True
#     elif S[i] == 'C' and flag:
#         arr[i - 1] = 1
#     else:
#         flag = False

for i, a, c in enumerate(zip(S, S[1:])):
    if a == 'A' and c == 'C':
        arr[i] = 1

for l, r in zip(ls, rs):
    print(np.sum(arr[l:r]))

Submission status: Runtime Error

Solution code:
# 2019/03/24
# AtCoder Beginner Contest 122 - C

# Input
n, q = map(int,input().split())
s = input()
sab = list()
aclist = list()

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

for k in range(q):
    l, r = map(int,input().split())
    ans = 0
    
    t_idx = 0
    b_idx = len(aclist)
    search_idx = int(len(aclist) / 2)

    while(b_idx + 1 < t_idx and aclist[search_idx] == l):
        if aclist[search_idx] > l:
            t_idx = search_idx
            search_idx = int((t_idx + b_idx) / 2)
        elif aclist[search_idx] < l:
            b_idx = search_idx
            search_idx = int((t_idx + b_idx) / 2)

    for i in range(search_idx-1, len(aclist), 1):
        if aclist[i] >= l:
            if aclist[i] < r:
                ans += 1
            else:
                break
        else:
            continue

    # Output
    print(ans)

Submission status: Runtime Error

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

pattern = r"[AC]+"

import re

repatter = re.compile(pattern)

result = []
for _ in range(n):
    begin, end = map(int, input().split())
    target_str = s[begin - 1:end]
    result.append(len(repatter.findall(target_str)))

print(result)

Submission status: Runtime Error

Solution code:

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

while Q > 0:
    r, l = map(int, input().split())

    s = S[r-1:l]
    counter = 0
    oldsp =''
    while s > 0:
        sp = s.pop(0)
        if sp == "T" and oldsp == "A":
            counter+=1
        
        oldsp=sp

    print(counter)
    

    Q -= 1

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = str(input())
len=len(S)
for i in range(Q):
    l, r = map(int, input().split())
    slice = S[l-1:r]
    po=slice.replace("AC","")
    le=len(po)
    print((len-(r-l+1)+le)//2)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i in range(q):
  a,b=list(map(int, input().split()))
  counter=0
 
  for j in range(len(s)-1):
    if S[a-1:b][j] == "A":
      if S[a-1:b][j+1] == "C":
        counter +=1

  print(counter)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <string>

using namespace std;

int main() {
    int n, q, l, r, count;
    string s;
    cin >> n >> q;
    cin >> s;
    int L[10100];
    for(int i = 0; i < n - 1; i++) {
        if(s[i] == 'A' && s[i + 1] == 'C') {
            L[i] = 1;
        } else {
            L[i] = 0;
        }
    }
    for(int i = 0; i < q; i++) {
        count = 0;
        cin >> l >> r;
        for(int j = l - 1; j < r - 1; j++) {
            if(L[j] == 1) {
                count++;
            }
        }
        cout << count << endl;
    }
}

Submission status: Runtime Error

Solution code:
import bisect
n, q = (int(i) for i in input().split())
s = input()
l,r = [],[]
for i in range(q):
    tmp = [int(i) for i in input().split()]
    l.append(tmp[0]-1)
    r.append(tmp[1]-1)
AC_index = []
while 'AC' in s:
    index = s.index('AC')
    AC_index.append(index + len(AC_index) * 2)
    if index < (len(s) - 1):
        s = s[:index] + s[index + 2:]
    else:
        s = s[:index]

for i in range(q):
    left_index = bisect.bisect_left(AC_index, l[i])
    right_index = bisect.bisect_right(AC_index, r[i])
    if AC_index[right_index - 1] == r[i]:
        right_index -= 1
        
    print(right_index-left_index)

Submission status: Runtime Error

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

array = []
for i in range(len(S)):
    if len(S) < i+1:
        break
    if S[i] == 'A':
        flag = True
        array.append('A')
    elif flag == True and S[i] == 'C':
        array.append('C')
    elif flag == True:
        array.append(' ')
        flag = False
    else:
        array.append(' ')

array_q = []
for q in range(Q):
    l, r = input().split()
    array_q.append([int(l), int(r)])

for arr in array_q:
    print(array[arr[0]:arr[1]].count('C'))

Submission status: Runtime Error

Solution code:
def counter(n, m):
	c = 0
	for o in range(n-1, m):
		if S[o] == "A":
			if o+1 <= m-1:
				if S[o+1] == "C": 
	return c
N, Q = map(int, input().split())
A = input()
S = [str(c) for c in A]
x = []
y = []
for i in range(Q):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
for i in range(Q):
	print(counter(x[i], y[i]))

Submission status: Runtime Error

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

li = []
for i in range(Q):
    s = lr[i][0] - 1
    l = lr[i][1]
    tempS = S[s:l]
    li.append(tempS)

for j in range(Q):
    print(li[j].count('AC'))

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
ind=[]
z=0
for i,j in zip(s[:-1],s[1:]):
    if i+j=="AC":
        ind.append(z)
    z+=1

aa=len(ind)
for i in range(q):
    l,r=map(int,input().split())
    l-=1
    r-=1
    for ii,jj in enumerate(ind):
        if jj>=l:
            start=ii
            break
    for ii,jj in enumerate(ind[::-1]):
        if jj<r:
            end=ii
            break
    print(max(0,aa-(start+end)))

Submission status: Runtime Error

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

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

cnt = 0
li = []

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

#print(li)
#exit()

for k in range(Q):
    print(li[lr[k][1]-1] - li[lr[k][0]-1])

Submission status: Runtime Error

Solution code:
import copy
N , Q = map(int,input().split())
S = list(input())
l = []
for i in range(Q):
	l.append(list(map(int,input().split())))

temp_indexes = [i for i, x in enumerate(S) if x == "A"]

indexes = []

for i in range(len(temp_indexes)):
	if S[temp_indexes[i] + 1] == "C":
		indexes.append(temp_indexes[i])
		
for i in range(Q):
	down_lim = l[i][0] - 1
	up_lim = l[i][1] - 1
	ans = [i for i in indexes if i > down_lim - 1 and i < up_lim]
	print(len(ans))

Submission status: Runtime Error

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

for s in S_lr:
    count = 0
    A_flag = False
    for i in range(len(s)):
        if s[i] == 'C' and i-1 > -1 and s[i-1] == 'A':
            count += 1

    print(count)

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split())
s = input()
ac_list = [0]*len(s)
i = 0
'''while True:
    ac_index = s[i:].find("AC")
    if ac_index == -1:
        break
    else:
        ac_list[ac_index+i] = 1
        i = ac_index + i + 2'''

for i in range(len(s-1)):
    if s[i] == 'A' and s[i+1] == 'C':
        ac_list[i] = 1
        
for _ in range(q):
    lr = tuple(map(int, input().split()))
    print(sum(ac_list[lr[0]-1:lr[1]-1]))

Submission status: Runtime Error

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

count = [0]
for i in range(0,N ):
    if S[i] == "A" and S[i + 1] == "C":
        count.append(count[i] + 1)
    else:
        count.append(count[i])


for i in range(0,Q):
    l,r = map(int,input().strip().split())
    if r > len(count):
        r = len(count)
    if l == 0:
        l += 1
    print(count[r - 1] - count[l - 1])

Submission status: Runtime Error

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

c = 0
j = 0


def fun(j, m, count):
    c = count
    if j >= m-1:
        return c
    if s[j] == "A":
        if s[j+1] == "C":
            c += 1
            j += 2
        elif s[j+1] == "A":
            j += 1
        else:
            j += 2
    else:
        j += 1
    return fun(j, m, c)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())  # 複数数値入力
S = list(input())  # 一文字ずつ格納
L = []
R = []

for i in range(Q):
    l, r = map(int, input().split())  # 複数数値入力
    L.append(l)
    R.append(r)

list = []
flg = 0
for s in S:
    if s == "A":
        flg = 1
    elif s == "C" and flg == 1:
        list.append(1)
        list.append(2)
        flg = 0
    elif flg == 1:
        list.append(0)
        list.append(0)
    else:
        list.append(0)

for i in range(Q):
    S = list[L[i]-1:]
    S = S[:R[i] - L[i]+1]
    if S[0] == 2:
        S = S[1:]
    if S[-1] == 1:
        S = S[:-2]
    print(int(sum(S)/3))

Submission status: Runtime Error

Solution code:
def solve(N, Q, S, L_R):
    answers = [None] * Q
    ac_index = [0] * len(S)
    for i in range(len(S)):
        s = S[i]
        if s == "A":
            a_flag = True
            continue
        elif s == "C":
            if a_flag:
                ac_index[i - 1] = 1
            a_flag = False
        else:
            a_flag = False
    q = 0
    for l, r in L_R:
        arr = ac_index[l - 1:r]
        ans = sum(arr)
        if arr[-1] == 1:
            ans -= 1
        answers[q] = ans
        q += 1
    return answers

def count_ac(pstr):
    count = 0
    a_flag = False
    for i in range(len(pstr)):
        s = pstr[i]
        if s == "A":
            a_flag = True
            continue
        elif s == "C":
            if a_flag:
                count += 1
            a_flag = False
        else:
            a_flag = False
    return count

N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
for ans in solve(N, Q, S, L_R):
    print(ans)

Submission status: Runtime Error

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

for i in range(q):
    l,r = [int(i) for i in input().split()]
    p = s[l-1:r]
    ans = re.findall("AC",p)
    print(len("AC"))

Submission status: Runtime Error

Solution code:
import re

i = input().split()[1]
s = input()
k = 0
result = []

while k < i:
    ft, et = [int(n) for n in input().split()]
    result.append(len(re.findall("AC", s[ft - 1:et])))
    k += 1

for kekka in result:
    print(kekka)

Submission status: Runtime Error

Solution code:
import sys

N, Q = map(int, sys.stdin.readline().split())
S = input()
s = [0] * Q
ans = 0

for i in range(Q):
    l, r = map(int, sys.stdin.readline().split())
    s[i] = S[l-1:r]

for j in range(Q):
    print(s[j].count('AC'))

Submission status: Runtime Error

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

li = []

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

Submission status: Runtime Error

Solution code:
import sys

N, Q = map(int, sys.stdin.readline.split())
S = input()
s = [0] * Q
ans = 0

for i in range(Q):
    l, r = map(int, sys.stdin.readline.split())
    s[i] = S[l-1:r]

for j in range(Q):
    print(s[j].count('AC'))

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import bisect

n,q = na()
s = ns()
x = []

for r in range(len(s)):
  if s[r] == 'A':
    if s[r+1] == 'C':
      x.append(r)

for i in range(q):
  l,r = na()
  b = bisect.bisect_left(x,l-1)
  a = bisect.bisect_right(x,r-2)
  c = a-b if a-b>0 else 0
  print(c)

Submission status: Runtime Error

Solution code:
n, q = [int(i) for i in input().split() ]
s = input() #文字列
lr = list([])
for i in range(q):
    lr.append([int(i) for i in input().split() ])

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

for i in range(q):
    ans = 0
    for m in ll:
        if (m >= lr[i][0]) and (m+1 <=lr[i][1]):
            ans += 1
        elif m >= lr[i][1]:
            break
    print(ans)

Submission status: Runtime Error

Solution code:
import bisect
N, Q = map(int, input().split())
s = input()
AC = []
for i in range(len(s)):
    if s[i] == 'A':
        if s[i+1] == 'C':
            AC.append(i)

for _ in range(Q):
    l, r = map(int, input().split())
    a = bisect.bisect_left(AC, l-1)
    b = bisect.bisect_right(AC, r-2)
    print(b-a)

Submission status: Runtime Error

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

cnt = [0]*N
tmp = 0
for i,c in enumerate(S):
    if tmp == 0 and c == "A":
        tmp =1
        cnt[i] = cnt[i-1]
    elif tmp == 1 and c == "C":
        tmp =0
        cnt[i] = cnt[i-1]+1
    else:
        tmp = int(c == "A")
        cnt[i] = cnt[i-1]

for l,r in lr:
    print(cnt[r-1]-cnt[l-1] , " : " ,S[l-1:r])

Submission status: Runtime Error

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

ls=[]
for i in range(len(S)):
	if S[i]=='A' and S[i+1]=='C':
		ls.append(i+1)
for j in range(Q):
	tmp=0
	for i in range(len(ls)):
		if lr[j][0]<=ls[i]<lr[j][1]:
			tmp+=1
	print(tmp)

Submission status: Runtime Error

Solution code:
N,Q=map(int,input().split())
S=input()
L = [list(map(int,input().split())) for i in range(Q)]
P=[]
for k, j in enumerate(S):
        if j=="A" and S[k+1]=="C":
            P.append(k+1)
for i in L:
    flag=0
    res=0
    for j in P:
        if(j>=i[0] and j<i[1]):
            flag=1
            res+=1
        else:
            if(flag==1):
                break
    print(res)

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
L = []
R = []
# ans = []
for _ in range(Q):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)
flag = []
for i in range(N):
	if S[i] == 'A' and S[i+1] == 'C':
		flag.append(1)
		i += 1
	else:
		flag.append(0)
# print(flag)

for i in range(Q):
	print(sum(flag[L[i]-1:R[i]-1]))

# for i in range(Q):
# 	print(ans[i])

Submission status: Runtime Error

Solution code:
import re
import numpy as np
_, q = input()
s = input()
qs = [input().split() for _ in range(q)]

def get_num_AC(s):
    count = len(re.split(r'AC', s)) - 1
    return count

def get_substr(s, smaller, larger)
    s1 = s[smaller-1:larger]
    return s1

for smaller, larger in qs:
    substr = get_substr(s, smaller, larger)
    count = get_num_AC(substr)
    print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, Q =  map(int, (input().split(' ')))
S = str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = [0] * N
print(N)
print(Q)
print(S)
i = 0
while i < len(S):
    if S[i] == "A":
        if S[i+1] == "C":
            save[i] = 1
        i += 1
    elif S[i] == "C":
        i += 1
    else:
        i+=1

for left, right in lr:
    print(sum(save[left-1: right-1]))

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
L = []
R = []
ans = []
for _ in range(Q):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)
flag = [0]*(N-1)

for i in range(N):
	if S[i] == 'A' and S[i+1] == 'C':
		flag[i] = 1
		i += 1
	else:
		pass
# print(flag)

for i in range(Q):
	print(sum(flag[L[i]-1:R[i]-1]))

# for i in range(Q):
# 	print(ans[i])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, Q =  map(int, (input().split(' ')))
S = str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = [0] * N
print(N)
print(Q)
print(S)
i = 0
while i < len(S):
    if S[i] == "A":
        if S[i+1] == "C":
            save[i] = 1
        i += 2N, Q =  map(int, (input().split(' ')))
S = str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = [0] * N
print(N)
print(Q)
print(S)
i = 0
while i < len(S):
    if S[i] == "A":
        if S[i+1] == "C":
            save[i] = 1
        i += 1
    elif S[i] == "C":
        i += 1
    else:
        i+=1

for left, right in lr:
    print(sum(save[left-1: right-1]))




    elif S[i] == "C":
        i += 1
    else:
        i+=1

for left, right in lr:
    print(sum(save[left-1: right-1]))

Submission status: Runtime Error

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

for lr_ in lr:
    l, r = lr_[0], lr_[1]
    
    print(S[l - 1: r].count('AC'))

Submission status: Runtime Error

Solution code:
import re

input()
s = input()
b, c = [int(n) for n in input().split()]
d, e = [int(n) for n in input().split()]
f, g = [int(n) for n in input().split()]
print(len(re.findall("AC", s[b - 1:c])))
print(len(re.findall("AC", s[d-1:e])))
print(len(re.findall("AC", s[f-1:g])))

Submission status: Runtime Error

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

P=[]
for k, j in enumerate(S):
        if j=="A" and S[k+1]=="C":
            P.append(k+1)

for i in L:
    flag=0
    res=0
    for j in P:
        if(j>=i[0] and j<i[1]):
            res+=1
        else:
            if(flag==1):
                break
            flag=1
    print(res)