Problem:


Score : 300 points

Problem Statement

You are given a string S of length N consisting of A, C, G and T. Answer the following Q queries:

Query i (1 \leq i \leq Q): You will be given integers l_i and r_i (1 \leq l_i < r_i \leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does AC occurs as a substring?

Notes

A substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.

For example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and  (the empty string), but not AC.

Constraints

2 \leq N \leq 10^5

1 \leq Q \leq 10^5

S is a string of length N.

Each character in S is A, C, G or T.

1 \leq l_i < r_i \leq N

Input

Input is given from Standard Input in the following format:

N Q
S
l_1 r_1
:
l_Q r_Q

Output

Print Q lines. The i-th line should contain the answer to the i-th query.

Sample Input 1

8 3
ACACTACG
3 7
2 3
1 8

Sample Output 1

2
0
3

Query 1: the substring of S starting at index 3 and ending at index 7 is ACTAC. In this string, AC occurs twice as a substring.

Query 2: the substring of S starting at index 2 and ending at index 3 is CA. In this string, AC occurs zero times as a substring.

Query 3: the substring of S starting at index 1 and ending at index 8 is ACACTACG. In this string, AC occurs three times as a substring.



Sample input:
8 3
ACACTACG
3 7
2 3
1 8


Sample output:
2
0
3

Submission status: Runtime Error

Solution code:
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

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

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  n, q = input_list()
  s = input()
  ss = list(s)
  ac_count = s.count('AC')
  index = 1
  for i in range(n):
    if s[i]=='A' and s[i+1]=='C':
      ss[i] = 1
    else:
      ss[i] = 0
  for qi in range(q):
    l, r = input_list()
    x = ss[l-1:r-1]
    print(x.count(1))
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Submission status: Runtime Error

Solution code:
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

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

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  n, q = input_list()
  s = input()
  ss = list(s)
  ac_count = s.count('AC')
  index = 1
  for i in range(n):
    if s[i]=='A' and s[i+1]=='C':
      ss[i] = str(index)
      ss[i+1] = str(index)
      index += 1
  for qi in range(q):
    l, r = input_list()
    x = ss[l-1:r]
    ans = 0
    for i in range(1, index+1):
      if x.count(str(i)) == 2:
        ans += 1
    print(ans)
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Submission status: Runtime Error

Solution code:
import numpy as np
n, q = map(int, input().split())
s = input()
lr = []
for i in range(q):
        l,r = map(int, input().split())
        lr.append([l,r])

n = len(s)
L = 0
R = 1
cntAC = [0] * n

for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        cntAC[i] += 1

# 累積和
cSum = np.cumsum(cntAC)


for _lr in lr:
    if _lr[L] == 1:
        print(cSum[-1])
    else:
        print(cSum[_lr[R]-2] - cSum[_lr[L]-2])
        

"""
ACACTACG
"""

Submission status: Runtime Error

Solution code:
import numpy as np
n, q = map(int, input().split())
s = input()
lr = []
for i in range(q):
        l,r = map(int, input().split())
        lr.append([l,r])

n = len(s)
L = 0
R = 1
cntAC = [0] * n

for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        cntAC[i] += 1

# 累積和
cSum = np.cumsum(cntAC)
print(cSum)

for _lr in lr:
    if _lr[L] == 1:
        print(cSum[-1])
    else:
        print(cSum[_lr[R]-2] - cSum[_lr[L]-2])
        

"""
ACACTACG
"""

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import bisect

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

l = []
for i in range(N):
    if S[i] == "A" and S[i+1] == "C":
        l.append(i+1.5)
s = 0
for i in range(Q):
    a,b = map(int,(input().split()))
    if l:
        print(bisect.bisect_left(l,b) - bisect.bisect_left(l,a))
    else:
        print(0)

Submission status: Runtime Error

Solution code:
import bisect

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

l = []
for i in range(N):
    if S[i] == "A" and S[i+1] == "C":
        l.append(i+1.5)
s = 0
for i in range(Q):
    a,b = map(int,(input().split()))
    print(bisect.bisect_left(l,b) - bisect.bisect_left(l,a))

Submission status: Runtime Error

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


t = [0] * (n+1)
for i in range(n):
    if s[i] == 'A' and s[i+1] == 'C':
        t[i+1] = t[i] + 1
    else:
        t[i+1] = t[i]
        

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

Submission status: Runtime Error

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


t = [0] * (n+1)
for i in range(n):
    if s[i] == 'A' and s[i+1] == 'C':
        t[i+1] = t[i] + 1
    else:
        t[i+1] = t[i]
        

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

Submission status: Runtime Error

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

last = ''
for i in range(N):
    c = S[i]
    if (last + c) == 'AC':
        cnt[i] = 1
    last = c

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

Submission status: Runtime Error

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

def bsearch(arr, num):
    r = len(arr) - 1
    l = 0
    while r - l > 1:
        c = (r + l) // 2
        if arr[c] > num:
            r = c
        elif arr[c] < num:
            l = c
        else:
            l = c
            r = c
            break
    return [l, r]

n, q = MAP()
s = STR()
index = []
for i in range(len(s) - 1):
    if s[i] + s[i + 1] == 'AC':
        index.append(i)
ans = 0
for _ in range(q):
    l, r = MAP()
    ll = bsearch(index, l - 1)
    rr = bsearch(index, r - 2)
    lll = ll[0] if index[ll[0]] >= l - 1 else ll[1]
    rrr = rr[1] if index[rr[1]] <= r - 2 else rr[0]
    print(rrr - lll + 1)

Submission status: Runtime Error

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

for i in range(len(ans)):
    print(ans[i])

Submission status: Runtime Error

Solution code:

n, q = map(int, input().split())
s = input()
cnt = 0
for i in range(n):
    if s[i] == 'A' and s[i + 1] == 'C':
        cnt += 1

data = [0] * cnt
j = 0
ans = [0] * q
for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        data[j] = i + 1
        j += 1
        
for i in range(q):
    l, r = map(int, input().split())
    cnt = 0
    for j in range(len(data)):
        if data[j] <= r - 1 and data[j] >= l:
            cnt += 1
        elif data[j] >= r:
            break
    ans[i] = cnt

for i in range(q):
    print(ans[i])

Submission status: Runtime Error

Solution code:
import numpy as np
n,q = map(int,input().split())
s = input()
check = np.zeros(n)
for i in range(n):
    if s[i] == "A" and s[i+1] == "C":
        check[i] = 1
for i in range(q):
    l,r = map(int,input().split())
    cnt = 0
    for j in range(l-1,r-1):
        if check[j] == 1:
            cnt += 1
    print(cnt)

Submission status: Runtime Error

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

# 先に回数を数える。累積和的に
hoge = [s[0:(i + 1)].count('AC') for i in range(n)]

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

Submission status: Runtime Error

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

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

for i,j in lr:
    print(R[j] - R[i])

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int i=0; i<n; i++) 

int main() {
    int n, q;
    cin >> n >> q;

    string s;
    cin >> s;

    vector<int> l(q), r(q);
    rep(i, q){
        cin >> l[i] >> r[i];
    }

    vector<int> v(n, 0);

    int cnt = 0;
    string t;
    t = s[0];
    for (int i = 1; i < n; i++) {
        if (t+s[i]=="AC"){
            cnt++;
        }

        v[i] = cnt;
        t = s[i];
    }

    rep(i, q){
        cout << v[r[i] - 1] - v[l[i] - 1] << endl;
    }
}

Submission status: Runtime Error

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

for i in range(3):
    first, last = map(int, input().split())
    print(s.count("AC", first - 1, last))

Submission status: Runtime Error

Solution code:
tg="AC"
n,q=map(int,input().split())
text=input()
ans=[]

def check():
    l,r=map(int,input().split())
    text_=text[l-1:][:r-1]
    count=re.findall(tg,text_)
    ans.append(len(count))
    
for i in range(q):
    check()

for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
N,Q=map(int,input().split())
S=input()
l,r=list(map(int,input().split())) for i in range(Q)
def main():
  for i in range(Q):
    T=S[l[i]:r[i]+1]
    c=T.count('AC')
    print(c)
main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

accum_sum = [0] * (len(s)+1)

for i in range(len(s)):
    if s[i] == "A" and s[i+1] == "C":
        accum_sum[i+1] = accum_sum[i] + 1
    else:
        accum_sum[i+1] = accum_sum[i]

for l, r in q_l:
    print(accum_sum[r-1]-accum_sum[l-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

s=[0]*(n+1)
for i in range(1,n+1):
    if S[i-1]=='A' and S[i]=='C':
        s[i]=s[i-1]+1
    else:
        s[i]=s[i-1]

#print(s)
for l,r in L:
    ans=s[r-1]-s[l-1]
    print(ans)

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

s=[0]*(n+1)
for i in range(1,n+1):
    if S[i-1]=='A' and S[i]=='C':
        s[i]=s[i-1]+1
    else:
        s[i]=s[i-1]

#print(s)
for l,r in L:
    ans=s[r]-s[l-1]
    print(ans)

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

s=[0]*(n+1)
for i in range(1,n+1):
    if S[i-1]=='A' and S[i]=='C':
        s[i]=s[i-1]+1
    else:
        s[i]=s[i-1]

#print(s)
for k,v in l:
    ans=s[v-1]-s[k-1]
    print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
sal
n,q = map(int, input().split())
s = input()
l = [0]*(n+1)
for i in range(1,n):
  if s[i-1:i+1] == "AC":
    l[i] = l[i-1]+1
  else:
    l[i] = l[i-1]
for _ in range(q):
  a,b = map(int, input().split())
  print(l[b-1]-l[a-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,q = [int(x) for x in input().split()]
s = input()
lst = []
for _ in range(q):
    l,r = [int(x) for x in input().split()]
    lst.append([l,r])

cnt = 0
for i in range(q):
    for x in range(lst[i][0]-1, lst[i][1]):
        if s[x] == "A" and s[x+1] == "C":
            if x+1 < lst[i][1]:
                cnt += 1
    print(cnt)
    cnt = 0

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
cnt=[0]*n
for i in range(n-1):
    if s[i:i+1]=="AC":
      cnt[i+1]=cnt[i]+1
#    else:
#      cnt[i+1]=cnt[i]

for i in range(q):
    li,ri=map(int,input().split())
#    print(s[li-1:ri].count("AC"))
#    print(sum(cnt[li-1:ri-1]))
    print(cnt[ri]-cnt[li])

Submission status: Runtime Error

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

for i in range(q):
    li,ri=map(int,input().split())
#    print(s[li-1:ri].count("AC"))
    print(cnt[li-1:ri-1].sum())

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S=list(input())
list=[0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        list[i]+=1
count=0
for j in range(Q):
    l, r = map(int, input().split())
    print(list[l-1:r-1]).count(1))

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S=list(input())
list=[]
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        list.append[i]
lis=[]
count=0
for j in range(Q):
    l, r = map(int, input().split())
    for h in range(l-1, r-2):
        lis.append(h)
        count+=len(set(list) & set(lis))
print(count)

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S=list(input())
list=[]
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        list.append[i]
lis=[]
count=0
for j in range(Q):
    l, r = map(int, input().split())
    for h in range(l-1, r+1):
        lis.append(h)
        count+=len(set(list) & set(lis))
print(count)

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S=list(input())
list=[]
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        list.append[i]
lis=[]
for j in range(Q):
    l, r = map(int, input().split())
    for h in range(l-1, r+1):
        lis.append(h)
        count+=len(set(list) & set(lis))
print(count)

Submission status: Runtime Error

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

lr=[]
for _ in range(q):
    D = list(map(int, input().split()))
    lr.append(D)

ac_list=[]

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

import bisect

for j in range(q):
    ind1 = bisect.bisect_left(ac_list,lr[j][0]-1)
    ind2 = bisect.bisect_left(ac_list,lr[j][1]-1)

    print(ind2-ind1)

Submission status: Runtime Error

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

cusum = [0]*(n+1)
for i in range(len(s)):
    if s[i] == "A" and s[i+1] == "C":
        cusum[i+1] = cusum[i] + 1
    else:
        cusum[i+1] = cusum[i]

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

Submission status: Runtime Error

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

N,Q = imn()
S = input()
lr = [iln() for _ in range(Q)]

s = [0 for _ in range(N+1)]

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

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

Submission status: Runtime Error

Solution code:
# https://atcoder.jp/contests/abc122/tasks/abc122_c
import itertools

N, Q = map(int, input().split())
N = int(N)
S = input()
lr = []
for _ in range(Q):
    l, r = map(int, input().split())
    lr.append((l - 1, r - 1))
locations = []
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        locations.append(i)
# print(locations)

for l, r in lr:
    subset = list(itertools.filterfalse(lambda x: x < l, locations))
    subset = list(itertools.filterfalse(lambda x: x > r, subset))
    # print(l, r, subset)
    num_substring = len(subset)
    # print('num_substring', num_substring)
    if subset[-1] == r:
        print(num_substring - 1)
    else:
        print(num_substring)

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
c=[0 for _ in range(n)]
p=''
for i in range(1,n):
  x=s[i]
  if p=='A' and x='C':
    c[i-1]=1
  p=x
for i in range(q):
  ans=0
  l,r=map(int,input().split())
  ans=sum(c[l-1:r-1])
 # if s[]
  print(ans)

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())
  print("string {}, l = {}, r = {}".format(S[l-1:r],l,r))
  print(len(S[l-1:r].split('AC')) - 1)

Submission status: Runtime Error

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


if __name__ == '__main__':
    main()

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())
	l,r=l-1,r-1
	print(s[l,r].count("AC"))

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
acc = [0] * (N+1)
for i in range(0, N):
    acc[i+1] = acc[i] + (S[i+1] == "C" and S[i] == "A")
for i in range(Q):
    l, r = map(int, input().split())
    print(acc[r-1] - acc[l-1])

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
acc = []
for i in range(1, Q+2):
    acc.append(S[0:i].count("AC"))

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

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

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
a=input()
l=[[int(i) for i in input().split()]for i in range(q)]
ac=[]
for x,aa in enumerate(a):
    if aa=="A" and a[x+1]=="C":
        ac.append(x+1)
ac=set(ac)
for i in l:
    cnt=0
    for j in ac:
        if i[0]<=j<i[1]:
            cnt+=1
    print(cnt)

Submission status: Runtime Error

Solution code:
N,Q = map(int, input().split())
S = input()
Query = []
for _ in range(Q):
    l,r = map(int, input().split())
    Query.append([l,r])

A = [0]*8

for i in range(N-2+1):
    if S[i]=="A" and S[i+1]=="C":
        A[i] = 1
s = [0]*(N+1)
for i in range(0,N,1):
    s[i+1] = A[i] + s[i]

for i in range(Q):
    l,r = Query[i]
    print(s[r-1]-s[l-1])

Submission status: Runtime Error

Solution code:
N,Q=map(int,input().split())
S=input()
A=[list(map(int,input().split())) for i in range(Q)]
X=[0]*(N+1)
cnt=1
for i in range(N): 
  if S[i]=='A' and S[i+1]=='C':
    X[i+1]=cnt
    cnt+=1
  else:
    X[i+1]=cnt
    
for i in range(Q):
  a=A[i][0]
  b=A[i][1]
  print(X[b]-X[a])

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
count=[]*n
for i in range(1,n):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":
        count[i]+=1

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

Submission status: Runtime Error

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


for i in range(N):
    if S[i] == "A" and S[i+1] == "C":
        SUM[i+1] = SUM[i] + 1
    else:
        SUM[i+1] = SUM[i]

for i in range(Q):
    L[i], R[i] = list(map(int, input().split()))
    #indexを0からにする
    print(SUM[R[i]-1] - SUM[L[i]-1])

Submission status: Runtime Error

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


for i in range(N):
    if S[i] == "A" and S[i+1] == "C":
        SUM[i+1] = SUM[i] + 1
    else:
        SUM[i+1] = SUM[i]
print(SUM)
for i in range(Q):
    L[i], R[i] = list(map(int, input().split()))
    #indexを0からにする
    print(SUM[R[i]-1] - SUM[L[i]-1])

Submission status: Runtime Error

Solution code:
n, q = list(map(int, input().split()))
s = input()
lr = []
for _ in range(q):
    lr.append(list(map(int, input().split())))
dp = [0]*(10^5+1)
for i in range(1, n):
    if s[i-1]=="A" and s[i]=="C":
        dp[i+1]=dp[i]+1
    else:
        dp[i+1]=dp[i]
for i in range(q):
    l = lr[i][0]
    r = lr[i][1]
    ans = dp[r] - dp[l]
    print(ans)

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
a=len(s)
l=[0]*a
z=0
i=0
while i<a:
    if s[i]=='A' and s[i+1]=='C':
        z+=1
        l[i],l[i+1]=['A',z],['C',z]
        i+=2
    else:
        l[i]=['O',z]
        i+=1
for _ in range(q):
    x,y=map(int,input().split())
    for i in range(x-1,y):
        if l[i][0]=='A':
            a=l[i][1]
            break
    for i in range(y-1,x-2,-1):
        if l[i][0]=='C':
            b=l[i][1]
            break
    print(b-a+1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import re

def solve1():
    N, Q = map(int, input().split())
    # print(N, Q)
    acgt_string = input()
    sub_str_ith = []
    for _ in range(Q):
        start, end = map(int, input().split())
        sub_str_ith.append((start, end))

    t = [0] * (N)
    for i in range(N):
        t[i+1] = t[i] + (1 if acgt_string[i:i+2] == "AC" else 0)

    for start, end in sub_str_ith:
        print(t[end-1] - t[start-1])

def my_solve1():
    N, Q = map(int, input().split())
    # print(N, Q)
    acgt_string = input()
    sub_str_ith = []
    for _ in range(Q):
        start, end = map(int, input().split())
        sub_str_ith.append((start, end))
    # print(sub_str_ith)

    # 全ての'A'の位置を取得
    a_iths = [m.span() for m in re.finditer('AC', acgt_string)]
    # print(a_iths)

    for start, end in sub_str_ith:
        # print(start, end)
        num = 0
        for ac_start, ac_end in a_iths:
            if ac_start >= start-1 and ac_end <= end:
                num += 1
        print(num)


solve1()
# my_solve1()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
#122-C
n,q=map(int,input().split())
s=input()
l=[list(map(int,input().split())) for i in range(q)]
m=[0]*(n+1)
for i in range(n):
    if s[i]=='A' and s[i+1]=='C':
        m[i+1]=m[i]+1
    else:
        m[i+1]=m[i]

for j in range(q):
    ans=m[l[j][1]-1]-m[l[j][0]-1]
    print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import bisect
n,q=map(int,input().split())
s=input()
ac=[]
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    ac.append(i+1)
for i in range(q):
  a,b=map(int,input().split())
  print(bisect.bisect_right(b-1)-bisect.bisect_left(a))

Submission status: Runtime Error

Solution code:
#122-C
n,q=map(int,input().split())
s=input()
l=[list(map(int,input().split())) for i in range(q)]
m=[0]*(n+1)
for i in range(len(s)):
    
    if s[i]=='A' and s[i+1]=='C':
        m[i+1]=m[i]+1
    else:
        m[i+1]=m[i]

for i in l:
    print(m[i[1]-1]-m[i[0]-1])

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)]
m=[0]*(n+1)
for i in range(len(s)):
    
    if s[i]=='A' and s[i+1]=='C':
        m[i+1]=m[i]+1
    else:
        m[i+1]=m[i]

print(m)
for i in l:
    print(m[i[1]-1]-m[i[0]-1])

Submission status: Runtime Error

Solution code:
# coding:utf-8

# 入力
N, Q = map(int, input().split(' '))
S = input()
ql = []
for _ in range(Q):
    l, r = map(int, input().split(' '))
    ql.append((l,r))

# 累積文字和の作成
cl = ['']
for char in S:
    cl.append(cl[-1] + char)

# クエリに対する出力
for i in range(Q):
    cnt = 0
    string = cl[ql[i][1]][ql[i][0]-1:]
    for j in range(len(string)-1):
        if string[j:j+2] == 'AC':
            cnt += 1
    print(cnt)

Submission status: Runtime Error

Solution code:
# coding:utf-8

# 入力
N, Q = map(int, input().split(' '))
S = input()
ql = []
for _ in range(Q):
    l, r = map(int, input().split(' '))
    ql.append({'l': l, 'r': r})

# 累積文字和の作成
cl = ['']
for char in S:
    cl.append(cl[-1] + char)

# クエリに対する出力
for i in range(Q):
    print(cl[ql[i]['r']][ql[i]['l']-1:].count('AC'))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

l = [0] * N
r = [0] * N

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

for j in range(Q):
    print(S[l[j]-1:r[j]].count('AC'))

Submission status: Runtime Error

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

Submission status: Runtime Error

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