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()
M=[[False,0]]
if S[0]=='A': M[0][0]=True
for s in S[1:]:
    if s=='A':
        M.append([True,M[-1][1]])
    elif s=='C':
        if M[-1][0]:
            M.append([False,M[-1][1]+1])
    else:
        M.append([False,M[-1][1]])
        
for _ in range(Q):
    l,r=map(int,input().split())
    ans=M[r-1][1]
    if l>1:
        ans-=((S[l-2]=='A' and S[l-1]=='C') + M[l-2][1])
    print(ans)

Submission status: Runtime Error

Solution code:
mport 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 = [i for i in range(len(s)) if s[i:i+2]=="AC"]
for i in range(q):
    l, r = na()
    print(len([i for i in index if l - 1 <= i <= r - 1 and l - 1 <= i + 1 <= r - 1]))

Submission status: Runtime Error

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

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

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

for arr in array_q:
    if ff != True:
        print(0)
        continue

    if len(array[arr[0]-1:arr[1]-1]) < 2:
        print(0)
        continue

    for a in array[arr[0]-1:]:
        if a == -1:
            flag = True
        elif flag == True:
            minv = a
            break

    for b in reversed(array[:arr[1]]):
        if b != 0 and b != -1:
            maxv = b
            break

    if minv == maxv and maxv != 0:
        print(1)
        
    elif maxv == 0:
        print(0)

    else:
        print(maxv - minv + 1)
        maxv = 0
        minv = 0

Submission status: Runtime Error

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

AC_accumulation = [0]

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


ans = []
for l, r in l_r_list:
    ans.append(str(AC_accumulation[r - 1] - AC_accumulation[l - 1]))

print("\n".join(ans))

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
l = []
r = []
for i in range(Q):
    li, ri = map(int, input().split())
    l += [li]
    r += [ri]

for ind in range(Q):
    substr = S[max(0, l[ind]-1) : min(r[ind], N)]
    print(len(re.findall("AC", S)))

Submission status: Runtime Error

Solution code:
from sys import stdin

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

for d in data:
    ans = 0
    flag = False
    for t in s[d[0]-1:d[1]]:
        if flag and t == "C":
            ans += 1
            flag = False
        else:
            flag = False
        if t == "A":
            flag = True

    print(ans)

Submission status: Runtime Error

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

AC_accumulation = [0]

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


ans = []
for l, r in l_r_list:
    ans.append(str(AC_accumulation[r - 1] - AC_accumulation[l - 1]))

print("\n".join(ans))

Submission status: Runtime Error

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

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

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

for arr in array_q:
    if ff != True:
        print(0)
        continue

    if len(array[arr[0]-1:arr[1]-1]) < 2:
        print(0)
        continue

    for a in array[arr[0]-1:]:
        if a == -1:
            flag = True
        elif flag == True:
            minv = a
            break

    for b in reversed(array[:arr[1]]):
        if b != 0 and b != -1:
            maxv = b
            break

    if minv == maxv and maxv != 0:
        print(1)
        
    elif maxv == 0:
        print(0)

    else:
        print(maxv - minv + 1)
        maxv = 0
        minv = 0

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
re = input()
res = list(map(str,re))
l = [0]*Q
r = [0]*Q
res2 = [0]*N
count = [0]*Q

for i in range(N):
  if res[i] =="A":
    if res[i+1] == "C":
      res2[i] = 1
  
for k in range(Q):
  l[k], r[k] = map(int, input().split())
  for j in range(l[k], r[k]):
    count[k] += res2[j-1]
    
for m in range(Q):
  print(count[m])

Submission status: Runtime Error

Solution code:
n, q = [int(i) for i in input().aplit()]
s = input()
for _ in range(q):
    l, r = [int(i) for i in input().aplit()]
    print(
        len([i for i in [a + b for a, b in zip(s[l-1: r], s[l: r+1])] if i == 'AC']))

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 = []
ac_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 - 1:
        t_li.append(count)
        break
    else:
        if s[i] == "A":
            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:
# -*- coding: utf-8 -*-
import numpy as np
import re
pattern = 'AC'
n, q = map(int, raw_input().split())
s = raw_input()

x = [raw_input() for i in range(q)]

result = re.finditer(pattern, s)

ac = np.zeros(len(s))
count = 0
for match in result:
    count += 1
    ac[match.span()[0]] = count

#print ac



for d in x:
    r = d.split(' ')
    start = int(r[0])-1
    end = int(r[1])
    for i in range(end-1, start, -1):
        if ac[i]!=0:
            m = ac[i]
#            print 'm', m
            break
    m2 = 0
    for i in range(start-1, -1, -1):
        if ac[i]!= 0:
            m2 = ac[i]
#            print 'm2',m2
            break
    wa = m-m2
#    wa = np.sum(ac[start:end] == 1)
#    wa = ac[start:end].count(1)
#    wa = sum(ac[start:end])
    if ac[end-1]!=0: wa = wa-1
    print int(wa)

Submission status: Runtime Error

Solution code:
import bisect
I=lambda:map(int,input().split())
N,Q=I()
S=input()
m=[]
for i in range(N-1):
    if S[i]=='A' and S[i+1]=='C':m.append(i+1)
#print(m)
for i in range(Q):
    l,r=I()
    li=bisect.bisect_left(m,l)
    ri=bisect.bisect_left(m,r)
    #print(i,li,ri)
    if m[ri-1]==r:
        print(ri-li-1)
    else:
        print(ri-li)

Submission status: Runtime Error

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

target = 'AC'
index = -1
idx = []
while True:
    index = S.find(target, index + 1)
    if index == -1:
        break
    idx.append(index+1)

max_idx = max(idx)
min_idx = min(idx)
ans = ''
for i in range(Q):
    l, r = list(map(int, input().split()))

    if (l > max_idx) or (r < min_idx):
        ans += '0\n'
        continue

    cnt = 0
    for j in idx:
        if l <= j < r:
            cnt += 1
        elif j >= r:
            break
    ans += str(cnt) + '\n'

print(ans, end='')

Submission status: Runtime Error

Solution code:
N , Q = map(int , input().split())
S = input()
l = []
r = []

for q in range(Q):
	a ,b = map(int , input().split())
	l.append(a)
	r.append(b)

for q in range(Q):
	count = 0
	a = l.pop(0)
	b = r.pop(0)
	subS = S[a-1:b]
	while subS!= "":
		x = subS.find("A")
		if x!= -1:
			subS = subS[x:]
		else:
			break
		elif subS[1] == "C":
			count += 1
			subS = subS[2:]
#			print("subS = " + subS)
		else:
			subS = subS[1:]
#			print("subS = " + subS)
	print(count)

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):
        l, r = map(int, input().split())
        B = A[l-1:r-1]
        print(sum(B))

main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
n,q = map(int,input().split())
s = input()
a = np.array(s)


for i in range(q):
        t1,t2 = map(int,input().split())
        r1 =a[t1-1:t2]
        c_2 = np.count_nonzero(r1 == "AC")
        print(c_2)

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

int main(){
    long int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    long long int lr[n][2];

    for(int i = 0; i < q; i++){
        cin >> lr[i][0] >> lr[i][1];
    }

    long long int dp[n];
    fill_n(dp, n, 0);
    int flag_a = 0;
    int count_ac = 0;
    for(int i = 0; i < n-1; i++){
        if(s[i] == 'A'){
            flag_a = 1;
        }
        else {
            if(s[i] == 'C'){
                if(flag_a == 1){
                    count_ac++;
                }
                else{
                    flag_a = 0;
                }
            }
            else {
                flag_a = 0;
            }
        }
        dp[i] = count_ac;
        //cout << dp[i] << endl;
    }

    dp[n-1] = count_ac;

    long long ans = 0;
    for(long long int i = 0; i < q; i++){
        if(dp[lr[i][0]-1] != 0){
            if(dp[lr[i][0]] == dp[lr[i][1]]){
                cout << dp[lr[i][0]-1] << endl;
            }
            else {
                cout << dp[lr[i][1]-1] - dp[lr[i][0]-1] << endl;
            }
        }
        else {
            cout << dp[lr[i][1]-1] << endl; 
        }
    }
}

Submission status: Runtime Error

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

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

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

for arr in array_q:
    if ff != True:
        print(0)
    if len(array[arr[0]-1:arr[1]-1]) < 2:
        print(0)
        continue
    for a in array[arr[0]-1:]:
        if a == -1:
            flag = True
        elif flag == True:
            minv = a
            break
    for b in reversed(array[:arr[1]]):
        if b != 0 and b != -1:
            maxv = b
            break
    if minv == maxv:
        print(1)
    else:
        print(maxv - minv + 1)

Submission status: Runtime Error

Solution code:
from sys import stdin
N,Q=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
for i in range(Q):
    n1,n2=[int(x) for x in stdin.readline().rstrip().split()]
    print(S[n1-1:n2])

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 = []
ac_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:
        t_li.append(count)
        break
    else:
        if s[i] == "A":
            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:
N, Q = list(map(int, input().split()))
S = input()

target = 'AC'
index = -1
idx = []
while True:
    index = S.find(target, index + 1)
    if index == -1:
        break
    idx.append(index+1)

max_idx = max(idx)
min_idx = min(idx)
ans = ''
for i in range(Q):
    l, r = list(map(int, input().split()))
    cnt = 0
    if l > max_idx:
        continue
    if r < min_idx:
        continue
    for j in idx:
        if l <= j < r:
            cnt += 1
        elif j >= r:
            break
    ans += str(cnt) + '\n'

print(ans, end='')

Submission status: Runtime Error

Solution code:
def getIdx(data, val):
    idx = len(data) // 2
    step = idx // 2 + 1
    ready = False

    while True:
        if data[idx] < val:
            idx += step
            if idx >= len(data) - 1:
                idx = len(data) 
                break
            if step == 1:
                ready = True
        else:
            if ready and step == 1:
                break
            idx -= step
            if idx < 0:
                idx = 0
                break
        
        if step > 1:
            step //= 2
    
    return idx

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

idx = -1
idxList = []
while True:
    idx = S.find('AC', idx + 1)
    if idx == -1:
        break
    idxList.append(idx)

ans = []

for q in range(Q):
    l, r = map(int, input().split())
    ans.append(getIdx(idxList, r-1) - getIdx(idxList, l-1))

for a in ans:
    print(a)

Submission status: Runtime Error

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

#print(N,Q,S)

L = S.replace('AC', '1 0 ').replace('T', '0 ').replace('G', '0 ')
R = S.replace('AC', '0 1 ').replace('T', '0 ').replace('G', '0 ')

L = list( map(int, L.split()) )	# 1 2 3 4 5 ...
R = list( map(int, R.split()) )	# 1 2 3 4 5 ...

#L = [1,2,3,4,5,6,7,8,9]
#R = [1,2,3,4,5,6,7,8,9]
#print(N,Q,S,L,R)
#print(N,Q,S)
#print("L", L)
#print("R", R)


from functools import reduce
#print( reduce(lambda x,y: x+y, L) )	#=> 10 (=sum(1,2,3,4))


for q in range(1,Q+1):
	ans=0
	l, r = map(int, input().split())		# 5 7

	X=L[l-1:l]
	Y=R[l+1:r]
	Z=X+Y
	
	ans = reduce(lambda x,y: x+y, Z)	#=> 10 (=sum(1,2,3,4))

	#print(l,r,X,Y,Z,ans)

	print(ans)

Submission status: Runtime Error

Solution code:
import re
import sys
s = sys.stdin.readlines()
N, Q = map(int, s[0].split())
S = s[1]
for i in s[2:]:
    lr.append(tuple(map(int, i.split())))
    
for i in lr:
    print(len(re.findall("AC", S[i[0]-1:i[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 += 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:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

int main(){
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int lr[n][2];

    for(int i = 0; i < q; i++){
        cin >> lr[i][0] >> lr[i][1];
    }

    long long int dp[n];
    int flag_a = 0;
    int count_ac = 0;
    for(int i = 0; i < n-1; i++){
        if(s[i] == 'A'){
            flag_a = 1;
        }
        else {
            if(s[i] == 'C'){
                if(flag_a == 1){
                    count_ac++;
                }
                else{
                    flag_a = 0;
                }
            }
            else {
                flag_a = 0;
            }
        }
        dp[i] = count_ac;
        //cout << dp[i] << endl;
    }

    dp[n-1] = count_ac;

    long long ans = 0;
    for(int i = 0; i < q; i++){
        if(dp[lr[i][0]-1] != 0){
            if(dp[lr[i][0]] == dp[lr[i][1]]){
                cout << dp[lr[i][0]-1] << endl;
            }
            else {
                cout << dp[lr[i][1]-1] - dp[lr[i][0]-1] << endl;
            }
        }
        else {
            cout << dp[lr[i][1]-1] << endl; 
        }
    }
}

Submission status: Runtime Error

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

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

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

for arr in array_q:
    if len(array[arr[0]-1:arr[1]-1]) < 2:
        print(0)
        continue
    for a in array[arr[0]-1:]:
        if a == -1:
            flag = True
        elif flag == True:
            minv = a
            break
    for b in reversed(array[:arr[1]]):
        if b != 0 and b != -1:
            maxv = b
            break
    if minv == maxv:
        print(1)
    else:
        print(maxv - minv + 1)

Submission status: Runtime Error

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

cntli = []
for i in range(q):
    si = s[lr[i][0]-1:lr[i][1]]
    si2 = [n for n in si if n in ("A","C")]
    cnt = 0
    for j in range(len(si)-1):
        if si2[j] == "A":
            if si2[j+1] == "C":
                cnt += 1
    else:
        cntli.append(cnt)

for p in cntli:
    print(p)

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

int main(){
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int lr[n][2];

    for(int i = 0; i < q; i++){
        cin >> lr[i][0] >> lr[i][1];
    }

 

    long long int dp[n];
    int flag_a = 0;
    int count_ac = 0;
    for(int i = 0; i < n-1; i++){
        if(s[i] == 'A'){
            flag_a = 1;
        }
        else {
            if(s[i] == 'C'){
                if(flag_a == 1){
                    count_ac++;
                }
                else{
                    flag_a = 0;
                }
            }
            else {
                flag_a = 0;
            }
        }
        dp[i] = count_ac;
        //cout << dp[i] << endl;
    }

    dp[n-1] = count_ac;
   

    long long ans = 0;
    for(int i = 0; i < q; i++){
        if(dp[lr[i][0]-1] != 0){
            if(dp[lr[i][0]] == dp[lr[i][1]]){
                cout << dp[lr[i][0]-1] << endl;
            }
            else {
                cout << dp[lr[i][1]-1] - dp[lr[i][0]-1] << endl;
            }
        }
        else {
            cout << dp[lr[i][1]-1] << endl; 
        }
    }
}

Submission status: Runtime Error

Solution code:
N,Q = list(map(int, input().split()))
S=input()
ac_indexes=[]
i=0
while i < N:
    if S[i]=='A':
        if S[i+1]=='C':
            ac_indexes.append(1)
            ac_indexes.append(0)
            i+=2
        else:
            ac_indexes.append(0)
            i+=1
    else:
        ac_indexes.append(0)
        i+=1

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

Submission status: Runtime Error

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

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

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

print(array_q)

for arr in array_q:
    if len(array[arr[0]-1:arr[1]-1]) < 2:
        print(0)
        continue
    for a in array[arr[0]-1:]:
        if a == -1:
            flag = True
        elif flag == True:
            minv = a
            break
    for b in reversed(array[:arr[1]]):
        if b != 0 and b != -1:
            maxv = b
            break
    if minv == maxv:
        print(1)
    else:
        print(maxv - minv + 1)

Submission status: Runtime Error

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

def get_num_AC(ccond, s, count):
    if s == []:
        return count
    if ccond:
        if s.pop() == 'A':
            return get_num_AC(False, s, count+1)
        else:
            if s == []:
                return count
            else:
                return get_num_AC(s.pop() == 'C', s, count)
    return get_num_AC(s.pop() == 'C', s, 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(False, substr, 0)
    print(count)

Submission status: Runtime Error

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

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 = ''
#i = 0
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, h, x):
        while h <= self.size:
            self.tree[h] += x
            h += h & -h

bit = Bit(N)     # 要素数を与えてインスタンス化
i = 1
while i < len(S):
    if S[i] == "A":
        if S[i+1] == "C":
            bit.add(i, 1)    # a2に10を加える
        else:
            pass
    i += 1

for left, right in lr:
    print(bit.sum(right-1) - bit.sum(left-1)) # a1～a6の合計を返す => 9

Submission status: Runtime Error

Solution code:
from collections import Counter
N=list(map(int,input().split()))
S=input()
l=[list(map(int,input().split())) for i in range(N[1])]
ans=0

for i in range(N[1]):
	for j in range(l[i][0]-1,l[i][1]):
		if S[j] == "A":
			if S[j+1]=="C"and j<l[i][1]-1:
				ans=ans+1

	print(ans)
	ans=0

Submission status: Runtime Error

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

def get_num_AC(ccond, s, count):
    if s == []:
        return count
    if ccond:
        if s.pop() == 'A':
            return get_num_AC(False, s, count+1)
        else:
            if s == []:
                return count
            else:
                return get_num_AC(s.pop() == 'C', s, count)
    return get_num_AC(s.pop() == 'C', s, 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:
n, q = map(int, input().split())
s = input()
for i in range(q):
    list_q = list(map(int, input().split()))
    list_q[0] = list_q[0] - 1
    list_q[1] = n - list_q[1]
    min_num = min(list_q)
    for j in range(min_num):
        s = s[1:]
        s = s[:-1]
    for k in range(list_q[0] - min_num):
        s = s[1:]
    for k in range(list_q[1] - min_num):
        s = s[:-1]
    s = s.split("AC")
    print(len(s) - 1)

Submission status: Runtime Error

Solution code:
#ACを検索して開始位置をインデックスにしておき、それを操作すれば多少はマシか
import numpy as np
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=np.array([S[i]=="A" and S[i+1]=="C" for i in range(N)])
for j in hani:
    print(sum(ACindex[j[0]-1:j[1]-1]))

Submission status: Runtime Error

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

s = ['a', 'b']

def get_num_AC(ccond, s, count):
    if s == []:
        return count
    if ccond:
        if s.pop() == 'A':
            return get_num_AC(False, s, count+1)
        else:
            if s == []:
                return count
            else:
                return get_num_AC(s.pop() == 'C', s, count)
    return get_num_AC(s.pop() == 'C', s, 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:
import sys.stdin.readline
input = readline

N,Q = [int(i) for i in input().split()]
S = input()

ans = []
for _ in range(Q):
    a,b = [int(i) for i in input().split()]
    ans.append(S[a-1:b].count('AC'))

[print(i) for i in ans]

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
re = input()
res = list(map(str,re))
l = [0]*Q
r = [0]*Q
res2 = [0]*N
count = [0]*Q

for i in range(N):
  if res[i] =="A":
    if res[i+1] == "C":
      res2[i] = 1
  
for k in range(Q):
  l[k], r[k] = map(int, input().split())
  for j in range(l[k], r[k]):
    count[k] += res2[j-1]

  print(count[k])

Submission status: Runtime Error

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

S = input()

lr = []

for q in range(Q):
  lr.append(input().split())
  
for q in lr:
  st = q[0]-1
  en = q[1]
  s = S[st:en]
  print(s.count('AC'))

Submission status: Runtime Error

Solution code:
nq=map(int,input().split())
N=nq[0];Q=nq[1]
S=input()
ls=[];rs=[]
for i in range(Q):
    lr=map(int,input().split())
    ls.append(lr[0])
    rs.append(lr[1])
for j in range(Q):
    n=0;a=False
    for k in S[(ls[j]-1):(rs[j])]:
        if k!="A" and a==False:
            pass
        elif k=="A":
            a=True
        elif a:
            if k=="C":
                n+=1
            else:
                a=False
    print(n)

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):
        if j == 0:
            continue
        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())
  s = S[l-1:r]
  print(s)

Submission status: Runtime Error

Solution code:
#ACを検索して開始位置をインデックスにしておき、それを操作すれば多少はマシか
import numpy as np
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=np.array([S[i]=="A" and S[i+1]=="C" for i in range(N-1)])
for j in hani:
    print(sum(ACindex[j[0]-1:j[1]-1]))

Submission status: Runtime Error

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

index = -1
idxs = []
while True:
    index = s.find("A", index + 1)
    if index == -1:
        break
    elif s[index + 1] == "C":
        idxs.append(index)

for i in range(Q):
    l,r = map(int,input().split())
    ans = sum(l-1 <= x <= r-2 for x in idxs)
    print(ans)

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
s = input()
x = [0]
flag = False
for i in range(n):
    if s[i] == 'A' and flag==False:
        flag = True
        x.append(x[i])
    elif s[i]=='C' and flag==True:
        flag = False
        x.append(x[i]+1)
    else:
        flag = False
        x.append(x[i])
print(x)
for i in range(q):
    l,r = map(int,input().split())
    print(x[r+1]-x[l])

Submission status: Runtime Error

Solution code:
re = input()
res = list(map(str,re))
l = [0]*Q
r = [0]*Q
res2 = [0]*N
count = [0]*Q

for i in range(N):
  if res[i] =="A":
    if res[i+1] == "C":
      res2[i] = 1
  
for i in range(Q):
  l[i], r[i] = map(int, input().split())
  for j in range(l[i], r[i]):
    count[i] += res2[j-1]

  print(count[i])

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()
  ss = s[l-1:r]
  print(ss)