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:
n, q = map(int, input().split())
s = input()
for i in range(q):
    l, r = map(int, input().split())
    start_a = s[l-1:r].find('A')
    end_a = s[l-1:r].rfind('A')
    start_c = s[l-1:r].find("C")
    end_c = s[l-1:r].rfind("C")
    if start_a == end_a or start_a +1 == start_c:
        start = start_a
    elif start_a +1 < start_c:
        start = start_c +1
       
    if start_c == end_c or end_a +1 == end_c:
        end = end_c
    elif end_a +1 < end_c:
        end = end_a
        
    if start == -1 or end== -1 or end <= start:
        print(0)
        continue
    cand = s[l-1:r][start:end+1]
    print(cand.count("AC"))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import re

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

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

for p in P:
	s = S[p[0] - 1:p[1]]
	I = [i for i, x in enumerate(s) if x == "A"]
	if I[-1] == (len(s) - 1):
		I.pop()
	count = 0
	for i in I:
		if s[i + 1] == "C":
			count += 1
	print(count)

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split())
s = input()
for i in range(q):
    l, r = map(int, input().split())
    start_a = s[l-1:r].find('A')
    end_a = s[l-1:r].rfind('A')
    start_c = s[l-1:r].find("C")
    end_c = s[l-1:r].rfind("C")
    if start_a == end_a or start_a +1 == start_c:
        start = start_a
    elif start_a +1 < start_c
        start = start_c +1
       
    if start_c == end_c or end_a +1 == end_c:
        end = end_c
    elif end_a +1 < end_c
        end = end_a
        
    if start == -1 or end== -1 or end <= start:
        print(0)
        continue
    cand = s[l-1:r][start:end+1]
    print(cand.count("AC"))

Submission status: Runtime Error

Solution code:
import numpy as np
N, Q = map(int, input().split())
S = input()
L_R = np.array([input().split() for _ in range(Q)], dtype=int)
L = L_R[:,0]
R = L_R[:,1]

for l, r in zip(L, R):
    s = np.array([*S[l-1:r]])
    print(len(np.intersect1d(np.where(s=='A')[0]+1, np.where(s=='C')[0])))

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_max = S.count('AC')
d = 0
for i in range(Q):
    d = lr[i][1] - lr[i][0]
    loss = 0
    if d * 2 > len(S):
        s_tmp = S[max(lr[i][0] - 1, 0):lr[i][1]]
        print(s_tmp.count('AC'))
    else:
        s_tmp_bef = S[:lr[i][0] - 1]
        s_tmp_aft = S[lr[i][1]:]
        if s_tmp_bef[-1] == 'A' and S[lr[i][0] - 1] == 'C':
            loss += 1
        if s_tmp_aft[0] == 'C' and S[lr[i][1] - 1] == 'A':
            loss += 1
        print(cnt_max - loss - s_tmp_bef.count('AC') - s_tmp_aft.count('AC'))

Submission status: Runtime Error

Solution code:
a, b = map(int, input().split())
c = [str(i) for i in input()]

d = [[int(i) for i in input().split()] for i in range(b)]
e = []

ans = 0
#print(d[1][0])

for i in range(a):
    if c[i] == "A" and c[i+1] == "C":
        e.append(i)

#print(e)

for i in range(b):
    for j in range(len(e)):
        if e[j] >= d[i][0] - 1 and e[j] + 1 < d[i][1]:
            ans=ans+1
    print(ans)
    ans = 0

Submission status: Runtime Error

Solution code:
def main():
    n, q = inputAsIntArr()
    s = input()

    idxes = []
    for i in range(n):
        if s[i] != 'A':
            continue
        if s[i+1] == 'C':
            idxes.append(i)
            i += 1

    # num_acs = ""
    # for i in range(q):
    #     li, ri = inputAsIntArr()
    #     num_ac = len([v for v in idxes if li-2 < v < ri-1])
    #     num_acs += str(num_ac) + "\n"

    # print(num_acs.strip())


def inputAsIntArr():
    return [int(i) for i in input().split(' ')]


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N,Q = map(int,input().split())
s = input()
a = []
b = 0
for i in range(Q+1):
  a.append(map(int,input().split())
for j in range(Q+1):
           for k in range(2):
               if "AC" in a[j,k]:
                   b[j] = a[j,k].count("AC")
               else:
                   b[j] = 0
for l in range(len(b)):
           print(b[i])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
def main():
    n, q = inputAsIntArr()
    s = input()

    idxes = []
    for i in range(n):
        if s[i] != 'A':
            continue
        if s[i+1] == 'C':
            idxes.append(i)
            i += 1

    # num_acs = ""
    # for i in range(q):
    #     li, ri = inputAsIntArr()
    #     num_ac = len([v for v in idxes if li-2 < v < ri-1])
    #     num_acs += str(num_ac) + "\n"

    # print(num_acs.strip())


def inputAsIntArr():
    return [int(i) for i in input().split(' ')]


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def fun(s, A, i, n):
    if i >= n-1:
        return
    if s[i] == "A":
        if s[i+1] == "C":
            A[i] = 1
            i += 2
        elif s[i+1] == "A":
            i += 1
        else:
            i += 2
    else:
        i += 1
    fun(s, A, i, n)

def main():
    n, q = map(int, input().split())
    s = input()
    
    A = [0 for i in range(n)]
    fun(s, A, 0, n)
    
    for i in range(q):
        c = 0
        l, r = map(int, input().split())
        B = A[l-1:r-1]
        print(sum(B))

main()

Submission status: Runtime Error

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

for k in range(len(S) - 1):
    if S[k] == 'A':
            if S[k+1] == 'C':
                    cnt.append(1)
    else:
            cnt.append(0)



for lr in lrs:
    sums = 0
    for k in range(lr[0]-1,lr[1]-1):
        sums += cnt[k]
    print(sums)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N, Q = map(int, input().split())
s = str(input())
for i in range(0, Q):
    l, r = map(int, input().split())
    print(s.count('AC')

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
def main():
    n, q = inputAsIntArr()
    s = input()

    idxes = []
    for i in range(n):
        if s[i] != 'A':
            continue
        if s[i+1] == 'C':
            idxes.append(i)
            i += 1

    num_acs = ""
    for i in range(q):
        li, ri = inputAsIntArr()
        # num_ac = len([v for v in idxes if li-2 < v < ri-1])
        # num_acs += str(num_ac) + "\n"

    print(num_acs.strip())


def inputAsIntArr():
    return [int(i) for i in input().split(' ')]


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

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

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

    counter = 0

    while r <= l :
        
        if S[r] == "C":
            if S[r-1] == "A":
                counter+=1

        r+=1

    print(counter)

    Q -= 1

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
A, B = map(int, input().split())
C = input()
N = [list(str(input())) for _ in range(B)]
for i in N:
  slice = C[int(i[0])-1:int(i[2])]
  print(slice.count("AC"))

Submission status: Runtime Error

Solution code:


dp =[[0 for i in range(n+2)] for j in range(n+2)]

for i in range(1):
    for j in range(i,n):
        t=0
        if s[j]=="C" and j!=i:
            if s[j-1]=="A":
                t=1
        
        dp[i][j]=dp[i][j-1]+t
        
for i in range(1,n):
    t=0
    if s[i]=="C" and s[i-1]=="A":   
        dp[i]=list(map(lambda x: x-1,dp[i-1]))
    else:
        dp[i]=dp[i-1]        
        
        
for i in range(q):
    print(dp[l_li[i]-1][r_li[i]-1])

Submission status: Runtime Error

Solution code:
NandQ=input()
S=str(input())
NandQList=NandQ.split()
N=int(NandQList[0])
Q=int(NandQList[1])
ListAns=[] #Q個の答えを入れるリスト
for i in range(1,Q+1,1): #Q個の質問入力パート
  LandR=str(input())
  ListLandR=LandR.split()
  L=int(ListLandR[0])
  R=int(ListLandR[1])
  moji=S[int(L-1):int(R)]
  A=moji.count("AC")
  print(moji)
  ListAns.append(A)

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
def main():
    n, q = inputAsIntArr()
    s = input()

    idxes = []
    for i in range(n):
        if s[i] != 'A':
            continue
        if s[i+1] == 'C':
            idxes.append(i)
            i += 1

    num_acs = ""
    for i in range(q):
        li, ri = inputAsIntArr()
        num_ac = len([v for v in idxes if li-2 < v < ri-1])
        num_acs += str(num_ac) + "\n"

    print(num_acs.strip())


def inputAsIntArr():
    return [int(i) for i in input().split(' ')]


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N, Q = map(int, input().split())
s = str(input())
for i in range(0, Q):
  l, r = map(int, input().split())
  print(s.count('AC')

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
def main():
    n, q = inputAsIntArr()
    s = input()

    # 予め探す
    idxes = []
    for i in range(n):
        if s[i] != 'A':
            continue
        if s[i+1] == 'C':
            idxes.append(i)
            i += 1

    # 指定された箇所に何件含まれるか
    num_acs = ""
    for i in range(q):
        li, ri = inputAsIntArr()
        num_ac = len([v for v in idxes if li-2 < v < ri-1])
        num_acs += "{}\n".format(str(num_ac))

    print(num_acs)


def inputAsIntArr():
    return [int(i) for i in input().split(' ')]


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N,Q=map(int,input().split())
S=input()
check=[False]*N

for i in range(N):
    if S[i] == 'A' and S[i+1]=='C':
        check[i] = True
        i += 1

for _ in range(Q):
    start,end=map(int,input().split())
    #print(check[start-1:end-1])
    print(check[start-1:end-1].count(True))

Submission status: Runtime Error

Solution code:
from functools import lru_cache

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

hit = [False] * N


@lru_cache(maxsize=None)
def ac_count(start, end):
    if start == end:
        return 0

    end_count = 1 if hit[end - 1] else 0

    return ac_count(start, end - 1) + end_count


for i in range(0, N):
    if S[i:i+2] == 'AC':
        hit[i] = True

for _ in range(0, Q):
    l, r = map(int, input().split())
    print(ac_count(l - 1, r - 1))

Submission status: Runtime Error

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

ac = [0]*n


for i in range(1,n):
	if s[i] =='C':
		if s[i-1] == 'A':
			ac[i-1] = 1

for i in range(q):
	answer = sum(ac[int(lr[i][0])-1:int(lr[i][2])])
	if answer >= 1:
		if ac[int(lr[i][2])-1] == 1:
			answer -= 1
	print(answer)

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
S = input()
N = [0]*(10**5+1)
for i in range(1,n+1):
    if S[i-1]=='A'and S[i]=='C':
        N[i] = 1
SUM = [0]*(10**5+1)
for i in range(1,n+1):
    SUM[i] += SUM[i-1]+N[i]
for i in range(q):
    l,r = map(int,input().split())
    print(SUM[r-1]-SUM[l-1])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
def main():
    n, q = inputAsIntArr()
    s = input()

    # 予め探す
    idxes = []
    for i in range(n):
        if s[i] != 'A':
            continue
        if s[i+1] == 'C':
            idxes.append(i)
            i += 1

    # 指定された箇所に何件含まれるか
    num_acs = ""
    for i in range(q):
        li, ri = inputAsIntArr()
        num_ac = len([v for v in idxes if li-2 < v < ri-1])
        num_acs += f"{str(num_ac)}\n"

    print(num_acs)


def inputAsIntArr():
    return [int(i) for i in input().split(' ')]


if __name__ == '__main__':
    main()

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)]
rui_count = []
AC_k = S.find('AC')
for i in range(N):
    if AC_k+1 > i:
        if i == 0:
            rui_count.append(0)
        else:
            rui_count.append(rui_count[i-1])
        continue
    AC_k = S[i:N].find('AC')
    if AC_k == -1:
        rui_count += [rui_count[i-1]+1 for j in range(i,N)]
        break
    AC_k += i
    rui_count.append(rui_count[i-1]+1)
count = []
for i in lr:
    count.append(rui_count[i[1]-1]-rui_count[i[0]-1])
for i in count:
    print(i)

Submission status: Runtime Error

Solution code:
def fun(A, i, n):
    if i >= n-1:
        return
    if s[i] == "A":
        if s[i+1] == "C":
            A[i] = 1
            i += 2
        elif s[i+1] == "A":
            i += 1
        else:
            i += 2
    else:
      	i += 1
    fun(A, i, n)

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

	A = [0 for i in range(n)]
	fun(A, 0, n)

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

main()

Submission status: Runtime Error

Solution code:
length = list(map(int,input().split()))	
string = input()
l_r = [list(map(int,input().split())) for i in range(length[1])]
answer = []

for i in range(length[1]):
  part_str = string[(l_r[i][0]-1):l_r[i][1]]
  for n in range(len(part_str)):
    answer.append(0)
    if part_str[n]=='A':
      if n != (len(part_str)-1):
        if part_str[n+1]=='C':
          answer[i] += 1
  print(answer[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())
answer=[0]*Q
counter=[1 if (i!=len(S))and(S[i]=="A")and(S[i+1]=="C") else 0 for i in range(len(S))]
for j in range(Q):
  answer[j]=sum(counter[l[j]-1:r[j]-1])
for i in range(Q):
  print(answer[i])

Submission status: Runtime Error

Solution code:
N, Q= input().split(" ")
S = input()
index_list_all = []
for i in range(int(Q)):
    lQ, rQ = input().split(" ")
    print(len(S[index_list[lQ] - 1: index_list[rQ]].split("AC")) - 1)

Submission status: Runtime Error

Solution code:
def fun(A, i, n):
    if i >= n-1:
        return
    if s[i] == "A":
        if s[i+1] == "C":
            A[i] = 1
            i += 2
        elif s[i+1] == "A":
            i += 1
        else:
            i += 2
    else:
      	i += 1
    fun(A, i, n)

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

A = [0 for i in range(n)]
fun(A, 0, n)

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

Submission status: Runtime Error

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

S = input()
ans = []

for i in range(len(S)):
    if S[i:i + 2] == 'AC':
        ans.append(i)


for i in range(Q):
    l, r = map(int, input().strip().split())
    ret = 0
    if S[l-1] != 'C':
        ret -= 1

    ali, ari = 0, 0
    for a in ans:
        if l - 1 <= a and a < r and :
           ret += 1
    print(ret)

Submission status: Runtime Error

Solution code:
N,Q = map(int,input().split())
S = input()
ans = []
for i in Q:
    z,x = map(int,input().split())
    ans.append(S[z:x].count('AC'))
for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
import sys
import os
f = open("C:/Users/kazuki/Documents/python/import.txt","r")
sys.stdin = f

# -*- coding: utf-8 -*-
N,Q = map(int,input().split())
S = str(input())
ls =[]
rs = []
for i in range(0,Q):
 l,r = map(int,input().split())
 slice = S[l-1:r]
 cnt = slice.count("AC")
 print(cnt)

Submission status: Runtime Error

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

ac = [0]*n


for i in range(1,n):
	if s[i] =='C':
		if s[i-1] == 'A':
			ac[i-1] = 1

for i in range(q):
	answer = sum(ac[int(lr[i][0])-1:int(lr[i][2])])
	if ac[int(lr[i][2])-1] == 1:
		answer -= 1
	print(answer)

Submission status: Runtime Error

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

L = list(input())
m = [0] * len(S)
cnt = 0
for idx, l in enumerate(L):
    if l == "C":
        if idx != 0 and L[idx-1] == "A":
            cnt += 1
            m[idx] = cnt

for i in range(Q):
    s, e = map(int, input().split())
    cnt_s = max(m[:s])
    cnt_e = max(m[:e])
    print(cnt_e - cnt_s)

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])
    for j in point:
        if a-1 <= j:
            if b-2 >= j:
                ans[i] += 1

for i in ans:
    print(i)

Submission status: Runtime Error

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

target = "AC"
ac_list =[]

index = -1
while True:
    index = S.find(target,index+ 1)
    if index == -1 :
        break
    ac_list.append(index)
    
for lr in lr_list:
    st = 0
    last = 0
    for i,ac in enumerate(ac_list):
#         print(ac+1,lr[0])
        if ac + 1 >= lr[0]:
            st = i
            break
    for i,ac in enumerate(ac_list[::-1]):
#         print(ac+1,lr[1]-1)
        if ac + 1 <= lr[1] - 1:
            end = len(ac_list) - i
            break
    
#     print(ac_list)
#     print(st,end)
    print(len(ac_list[st:end]))

Submission status: Runtime Error

Solution code:
NQ = list(map(int, input().split()))
word = input()
word_list = [*word]
for i in range(0, NQ[1]):
    rl = list(map(int, input().split()))
    word = word_list[rl[0]-1:rl[1]]
    word = ''.join(word)
    print(word.count('AC'))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S=input()
l=list()
r=list()
for i in range(Q):
  L,R=map(int, input().split())
  S2=S[L-1:R].split("AC")
  print(S[L-1:R])
  print(len(S2)-1)

Submission status: Runtime Error

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

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

for i in range(Q):
    hajime = bisect.bisect_left(numlist, l[i])
    owari = bisect.bisect_right(numlist,r[i]-1)
    print(owari - hajime)

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):
	count = 0
	j = 0
	while indexes[j] < l[i][1] - 1:
		if indexes[j] < l[i][0] -1:
			j += 1
		else:
			count += 1
			if j == len(indexes) - 1:
				break
			j += 1
	print(count)

Submission status: Runtime Error

Solution code:
N, Q= input().split(" ")
S = input()
index_list_all = []
for i in range(int(Q)):
    lQ, rQ = input().split(" ")
    index_list_all.append([int(lQ), int(rQ)])

print(index_list_all)
for index_list in index_list_all:
    print(S[index_list[0] - 1: index_list[1]])
    print(len(S[index_list[0] - 1: index_list[1]].split("AC")) - 1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#import numpy as np
#import re
N, Q = map(int,input().split())
S = input()
spl = list(S)
#S_mod = re.sub('AC',"aa", S)
S_mod = S.replace('AC',"aa")
spl_mod = list(S_mod)
for i in range(Q):
    l, r = map(int,input().split())
    #print(spl_mod[l-1:r])
    minus = 0
    if l>=2:
      if (spl[l-2]=='A')&(spl[l-1]=='C'):
        minus += 1
    if r<=Q-2:
    	if (spl[r]=='A')&(spl[r+1]=='C'):
      		minus += 1
    print(int((spl_mod[l-1:r].count('a')-minus)/2))

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])
print('\r\n')

Submission status: Runtime Error

Solution code:
n, q = map(int,input().split())
s = input()
Ai = [j for j, x in enumerate(s[:len(s)-1]) if x == 'A']
for k in range(len(Ai)):
     if s[Ai[k]+1] != 'C':
            del Ai[k]
for i in range(q):
    l, r = map(int, input().split())
    print(sum(l-1 <= x <= r-2 for x in Ai))

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)
    
ac_begin_idx = []
A_flag = False
for idx, char in enumerate(S):
    if A_flag and char =="C":
        ac_begin_idx.append(idx-1)
        A_flag = False
    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:
n, q = map(int, input().split())
s = input()
for i in range(q):
    l, r = map(int, input().split())
    start = s[l-1:r].find('A')
    end = s[l-1:r].rfind("C")
     if start == -1 or end== -1:
        print(0)
        pass
    cand = s[l-1:r][start:end+1]
    print(cand.count("AC"))

Submission status: Runtime Error

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

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)

for i in range(Q):
    ans = 0
    y = input().split()
    a = int(y[0])
    b = int(y[1])
    for j in point:
        num = 0
        if a-1 <= j:
            if b-2 >= j:
                ans += 1
    print(ans)

Submission status: Runtime Error

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

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
    c.append(cnt)

for i in range(Q):
    print(c[i])

Submission status: Runtime Error

Solution code:
#coding: utf-8
N, Q = map(int, input().split())
S = input()
for i in range(Q):
    q1 = list(map(int, input().split()))
    cnt = 0
    qs = S[q1[0]-1: q1[1]]
    print(qs)
    print(qs.count("AC"))

Submission status: Runtime Error

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

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
    cnt.append(str(c))

for i in range(Q):
    print(c[i])

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

for i in range(Q):
    ans = 0
    y = input().split()
    a = int(y[0])
    b = int(y[1])
    for j in point:
        num = 0
        if a-1 <= j:
            if b-2 >= j:
                ans += 1
    print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def check(S):
  # はじめにACのある位置を調べる
  N = len(S)
  place = []
  for i in range(N-1): # 最後の文字がAでも意味ない
    if S[i:i+2] == "AC":
      place.append(i)
  return place

def f(place, l, r):
  if l > place[-1]:
    return 0
  count = 0
  for x in place:
    if l<= x and x < r:
      count += 1
    elif x > r:
      break
  return count 

if __name__ == "__main__":
  N, Q = map(int, input().split())
  S = input()
  place = check(S)
  for _ in range(Q):
    l, r = map(int, input().split())
    print(f(place, l-1, r-1))

Submission status: Runtime Error

Solution code:
b = "ACACTACG"
n, q = map(int, input().split())
b = input()
a = [[int(x) for x in input().split()] for _ in range(q)]
for j in range(len(b)-1):
        if b[j] == "A" and b[j+1] == "C":
            ans.append(1)
        else:
            ans.append(0)
for i in a:
    print(sum(ans[i[0]:i[1]]))

Submission status: Runtime Error

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

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

for i in LR:
    n = len([k for k in AC_list if k>=i[0]-1 and k<i[1]-1])
    print(n)

Submission status: Runtime Error

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

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
    cnt.append(c)

for i in range(Q):
    print(c[i])

Submission status: Runtime Error

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

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
	numbers_of_AC.append(count)

Submission status: Runtime Error

Solution code:
a = input().split() 
n = a[0]
q = a[1]
s = a[2]
s = list(s)
cnt = []
l = []
r = []
for i in range(int(q)):
  l.append(a[3+i*2])
  r.append(a[4+i*2])
  cnt.append(0)
print(a)
for i in range(int(q)):
  for j in range(int(l[i]), int(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:


tmp = input().split(" ")
n = tmp[0]
q = int(tmp[1])

s = input()

ac_indexes=[]
start=0
while True:
    ind = s.find("AC", start)
    if ind != -1:
        start=ind+2
        ac_indexes.append(ind)
    else:
        break

for i in range(q):

    if len(ac_indexes) == 0:
        print ("0")
        continue

    tmp = input().split(" ")
    a = int(tmp[0]) - 1
    b = int(tmp[1]) - 2

    left = 0
    right = len(ac_indexes)
    left_kari=-1
    left_kakutei = -1
    while left <= right:
        center = (left+right)//2
        if ac_indexes[center] > a:
            right = center-1
            left_kari = center
        elif ac_indexes[center] < a:
            left = center+1
        else:
            left_kakutei = center
            break
    if left_kakutei == -1:
        left_kakutei = left_kari
    
    left = 0
    right = len(ac_indexes)-1
    right_kari = -1
    right_kakutei = -1
    while left <= right:
        center = (left+right)//2
        #print (left, center, right)
        if ac_indexes[center] > b:
            right = center-1
        elif ac_indexes[center] < b:
            left = center+1
            right_kari = center
        else:
            right_kakutei = center
            break
    if (right_kakutei == -1):
        right_kakutei = right_kari

    if (left_kakutei > right_kakutei or left_kakutei==-1 or right_kakutei==-1):
        print ("0")
        continue

    print(str(right_kakutei - left_kakutei + 1))

Submission status: Runtime Error

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

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

ei = []
for index, item in enumerate(s):
    if index == n - 1:
        break
    if s[index] == "A" and s[index + 1] == "C":
        ei.append(index)
        ce.append(index+1)

for i in range(0,q):
    sum = 0
    for j in range(int(lr[i][0])-1,int(lr[i][1])):
        if j in ei:
            sum += 1
    if int(lr[i][1])-1 in ei:
        sum -= 1
    print(sum)

print(ei)

Submission status: Runtime Error

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, q = na()
s = input()
index = []
for i in range(len(s)):
    if s[i:i+2] == "AC":
        index.append(i)
for i in range(q):
    l, r = na()
    print(len([i for i in index if l-1<= i <= r-1))