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:
S = input()
question = []
for i in range(Q):
  question.append(list(map(int, input().split())))

# Sの中で、ACという部分文字列が含まれるときの（Aの）index
index = []
for i in range(N-1):
  if S[i]+S[i+1] == "AC":
    index.append(i)

for i, q in enumerate(question):
  ans = 0
  for j in range(len(index)):
    if index[j] >= q[0]-1 and index[j]+1 <= q[1]-1:
      ans +=1
  print(ans)

Submission status: Runtime Error

Solution code:
N,Q=(int(i) for i in input().split())
x=input()
a=[]

j=0
s=[]
while (j<len(x)-1):
  if (x[j]=="A"):
    if (x[j+1]=="C"):
      s.append(j+1)
      j+=1
  j+=1
for i in range(0,Q):
  a.append([int(j) for j in input().split()])
  answer=0
  j=0
  while s[j]<a[i][0]:
    j+=1
    if len(s)<=j:break
  k=0
  while s[k]<a[i][1]:
    k+=1
    if len(s)<=k:break
  print(k-j)

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
R = [list(map(int, input().split)) for i in range(Q)]
ans = []
for i in range(Q):
    x = R[i][0]-1
    y = R[i][1]
    a=S[x:y].count("AC")
    ans.append(a)

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

Submission status: Runtime Error

Solution code:
n, q = map(int,input().split())
S = list(input())
L = []
R = []
for i in range(q):
    l, r = [int(i) for i in input().split()]
    L.append(l)
    R.append(r)
for i in range(q):
    S_0 = ""
    for k in range(L[i], R[i] + 1):
        S_0 += S[k]
    print(S_0.count("AC"))

Submission status: Runtime Error

Solution code:
import re
n,q = map(int, input().split())
s = input()
m = list(re.finditer("AC",s))
mm = [s.start()+1 for s in m]
for i in range(q):
    a,b,aa,bb=0,0,False,False
    loc = [int(s) for s in input().split()]
    for j in range(loc[1]-loc[0]+1):
        if mm.count(loc[0]+j): a=loc[0]+j; break
    for j in range(loc[1]-loc[0]+1):
        if mm.count(loc[1]-1-j): b=loc[1]-1-j; break
    print(mm.index(b)-mm.index(a)+1)

Submission status: Runtime Error

Solution code:
N,Q = map(int,input().split())
S = input()
place = []
for s in range(N - 1):
	if S[s] == 'A':
		if S[s + 1] == 'C':
			place.append(s)
PlaceCount = len(place)
for q in range(Q):
    num = 0
	l,r = map(int,input().split())
	l -= 1
	r -= 2
	for i in range(PlaceCount):
		if l <= place[i] <= r:
			num += 1
	print(num)

Submission status: Runtime Error

Solution code:
def counts(s, l, r):
    ans = s[l-1:r].count('AC')
    print(ans)

n, q = map(int, input().split())
s = input()
for i in xrange(q):
    l, r = map(int, input().split())
    counts(s, l, r)

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
s = input()
ans =[]
j = 0
for i in range(n-1):#どこにACという連続文字列があるかを調べる
    if s[i] == "A" and s[i+1] == "C":
        j += 1
        ans.append(j)
    else:
        ans.append(j)
for i in range(q):
    l,r = map(int, input().split())
    print(ans[r-2]-ans[l]+1)

Submission status: Runtime Error

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

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

    dp = [0]*(N)
    dp[0] = 0
    for i in range(0, N-1):
        if S[i]=="A" and S[i+1]=="C":
            dp[i+1] = dp[i] + 1
        else:
            dp[i+1] = dp[i]
    
    for i in range(Q):
        l, r = list(map(int, input()))
        print(dp[r-1] - dp[l-1])
    
    

if __name__ == "__main__":
    solve()

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())
ct=0
max=0
for i in range(3):
  T = S[l[i]-1:r[i]]
  #print(T)
  for j in range(len(T)-1):
    if T[j]=='A' and T[j+1]=='C':
      ct+=1
  print(ct)
  ct=0

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())
ct=0
max=0
for i in range(3):
  T = S[l[i]-1:r[i]]
  print(T)
  for j in range(len(T)-1):
    if T[j]=='A' and T[j+1]=='C':
      ct+=1
  print(ct)
  ct=0

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

N,Q = [int(x) for x in input().split()]
S = list(input())
lrlist =[]
for _ in range(Q):
    l,r = [int(x) for x in input().split()]
    lrlist.append((l,r))

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

for _ in range (Q):
    l = lrlist[_][0]
    r = lrlist[_][1]
    ans = sum(sumls[r-1]-sumls[l-1])
    print(ans)

Submission status: Runtime Error

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

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

anslist = []
for k in range(q):
  ans = rightac[inputlist[k][0] - 1] - rightac[inputlist[k][1] - 1]
  anslist.append(ans)

print(*anslist, sep = "\n")

Submission status: Runtime Error

Solution code:
N,Q=map(int,input().split())
s=list(input())
p=[]
li=[]
ri=[]
for i in range(Q):
  l,r=map(int,input().split())
  li.append(l)
  ri.append(r)
for i in range(r[i]-l[i]):
  pr=0
  if s[i+l[i]]=='A' and s[i+l[i]+1]=='C':
    pr +=1
  else:
    pass
  p.append(pr)
for i in range(Q):
  print(p[i])

Submission status: Runtime Error

Solution code:
N,Q=map(int,input().split())
s=list(input())
p=[]
li=[]
ri=[]
for i in range(Q):
  l,r=map(int,input().split())
  li.append(l)
  ri.append(r)
for i in range(r[i]-l[i]):
  pr=0
  if s[i+l]=='A' and s[i+l+1]=='C':
    pr +=1
  else:
    pass
  p.append(pr)
for i in range(Q):
  print(p[i])

Submission status: Runtime Error

Solution code:
N,Q=map(int,input().split())
s=list(input())
p=[]
for i in range(Q):
  l,r=map(int,input().split())
  part=s[l:r+1]
  pr=0
  for i in range(r-l):
    if part[i+l]=='A' and part[i+l+1]=='C':
      pr +=1
    else:
      pass
  p.append(pr)
for i in range(Q):
  print(p[i])

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):
  1, 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 = str(input())
N,Q = 8,3
S = "ACACTACG"
L = [0] * len(S) #0はACのAでない
i = 0
while i < len(S)-1:
    if S[i] == "A":
        if S[i+1] == "C":
            L[i] = 1
            i += 1
        elif S[i+1] == "A":
            i += 1
        else:
            i += 2
    else:
        i += 1
for _ in range(Q):
    l, r = map(int, input().split())
    print(sum(L[l-1:r-1]))

Submission status: Runtime Error

Solution code:
N,Q = map(int, input().split())
S = str(input())
# L = []
# R = []
for _ in range(N):
    l, r = map(int, input().split())
    print(S[l-1:r].count("AC"))
#     L.append(l)
#     R.append(r)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

S=input()

ACDP=[0]*N
Aflag=0
ACcount=0
for i in range(len(S)):
  if S[i]=='A':
    Aflag=1
  else:
    Aflag=0
  if S[i]=='C' and Aflag==1:
    ACcount+=1
  ACDP[i]=ACcount
print(ACDP)

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

Submission status: Runtime Error

Solution code:
N,Q=map(int,input().split())
S=input()
count=[0]*(N)
for i in range(N-1):
    if S[i:i+2]=="AC":
        count[i]=1
sums=list(accumulate([0]+count))

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

Submission status: Runtime Error

Solution code:
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, q = read_line(int, int)
s, = read_line(str)

p = []
i = 0
while i < len(s) - 1:
    if s[i:i+2] == 'AC':
        p.append(i)
        i += 2
    else:
        i += 1

for i in range(q):
    l, r = read_line(int, int)
    l, r = l - 1, r - 1

    c = 0
    for j in range(len(p)):
        pp = p[j]
        if l <= pp:
            break
        c += 1

    for jj in reversed(range(j, len(p))):
        pp = p[jj]
        if pp + 1 <= r:
            break
        c += 1

    print(len(p) - c)

Submission status: Runtime Error

Solution code:
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, q = read_line(int, int)
s, = read_line(str)

p = []
i = 0
while i < len(s) - 1:
    if s[i:i+2] == 'AC':
        p.append(i)
        i += 2
    else:
        i += 1

for i in range(q):
    l, r = read_line(int, int)
    l, r = l - 1, r - 1

    c = 0
    for j in range(len(p)):
        pp = p[j]
        if l <= pp:
            break
        c += 1

    for jj in range(len(p) - 1, j - 1, -1):
        pp = p[jj]
        if pp + 1 <= r:
            break
        c += 1

    print(len(p) - c)

Submission status: Runtime Error

Solution code:
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, q = read_line(int, int)
s, = read_line(str)

p = []
i = 0
while i < len(s) - 1:
    if s[i:i+2] == 'AC':
        p.append(i)
        i += 2
    else:
        i += 1

for i in range(q):
    l, r = read_line(int, int)
    l, r = l - 1, r - 1

    c = 0
    for j in range(len(p)):
        pp = p[j]
        if l <= pp:
            break
        c += 1

    for jj in range(len(p), j, -1):
        pp = p[j]
        if pp + 1 <= r:
            break
        c += 1

    print(len(p) - c)

Submission status: Runtime Error

Solution code:
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, q = read_line(int, int)
s, = read_line(str)

p = []
for i in range(len(s) - 1):
    if s[i:i+2] == 'AC':
        p.append(i)

for i in range(q):
    l, r = read_line(int, int)
    l, r = l - 1, r - 1

    c = 0
    print(s[l:r + 1])
    for pp in p:
        if l <= pp and pp + 1 < r:
            c += 1
    print(c)

Submission status: Runtime Error

Solution code:
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, q = read_line(int, int)
s, = read_line(str)

p = []
for i in range(len(s) - 1):
    if s[i:i+2] == 'AC':
        p.append(i)

for i in range(q):
    l, r = read_line(int, int)
    l, r = l - 1, r

    c = 0
    print(s[l:r])
    for pp in p:
        if l <= pp and pp + 1 < r:
            c += 1
    print(c)

Submission status: Runtime Error

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

lis = [0] * (len(S)+1)
for i in range(len(S)+1):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S) and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1

    
for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

Submission status: Runtime Error

Solution code:
_=input()
A=map(lambda x:("A", int(x)), input())
B=map(lambda x:("B", int(x)), input())
C=map(lambda x:("C", int(x)), input())
S = sorted(A, cmp=lambda x, y:-x[1] + y[1])

A=None
B=None
C=None
for i in len(S):
  if A==None and x[0]=="A":
    A=i
  elif B==None and x[0]=="B":
    B=i
  elif C==None and x[0]=="C":
  	C=i

for i in [A, B, C].sort()[::-1]:
  del S[i]

print(S)

Submission status: Runtime Error

Solution code:
import sys
 
r=[x.strip() for x in sys.stdin.readlines()[1:]]
 
s=r.pop(0)
 
q=[x.split() for x in r]
 
for i in q:
    prt=str(s[int(i[0])-1:int(i[1])])
    
    prt=prt.translate(str.maketrans({
    "A":"0+1*",
    "C":"*1+0",
    "G":"",
    "T":"",
    }))
 
    print(int(eval("0{0}0".format(prt))))

Submission status: Runtime Error

Solution code:
import sys
 
r=[x.strip() for x in sys.stdin.readlines()[1:]]
 
s=r.pop(0)
 
q=[x.split() for x in r]
 
for i in q:
    prt=str(s[int(i[0])-1:int(i[1])])
    
    prt=prt.translate(str.maketrans({
    "A":"0+1*",
    "C":"*1+0",
    "G":"",
    "T":"",
    }))
 
    print(eval("0{}0".format(prt)))

Submission status: Runtime Error

Solution code:
import sys
 
r=[x.strip() for x in sys.stdin.readlines()[1:]]
 
s=r.pop(0)
 
q=[x.split() for x in r]
 
for i in q:
    prt=str(s[int(i[0])-1:int(i[1])])
    
    eq=prt.translate(str.maketrans({
    "A":"0+1*",
    "C":"*1+0",
    "G":"0",
    "T":"0",
    }))
 
    print(eval("0{}0".format(eq)))

Submission status: Runtime Error

Solution code:
import sys

r=[x.strip() for x in sys.stdin.readlines()[1:]]

s=r.pop(0)

q=[x.split() for x in r]

for i in q:
    prt=str(s[int(i[0])-1:int(i[1])])
    
    prt=prt.translate(str.maketrans({
    "A":"0+1*",
    "C":"*1+0",
    "G":"0",
    "T":"0",
    }))

    print(eval("0{0}0".format(prt)))

Submission status: Runtime Error

Solution code:
import sys

r=[x.strip() for x in sys.stdin.readlines()[1:]]

s=r.pop(0)

q=[x.split() for x in r]

for i in q:
    prt=str(s[int(i[0])-1:int(i[1])])
    
    prt=prt.translate(str.maketrans({
    "A":"0+1*",
    "C":"*1+0",
    "G":"0",
    "T":"0",
    }))

    print(eval("0{}0".format(prt)))

Submission status: Runtime Error

Solution code:
#122 C
from itertools import accumulate
N,Q= map(int,input().split())
S=input()
ans=[0]*(N)

for i,s in enumerate(list(accumulate(S))):
    ans[i]=s.count('AC')
ans
for i in range(Q):
    L1,L2= map(int,input().split())
    print(ans[L2-1]-ans[L1-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import pdb
import builtins
import sys
import numpy as np
class Test:
    def __init__(self):
        pass

class CustomUtils:
    def __init__(self):
        pass
    def to_int(self, inputs, sp=' '):
        if sp == '':
            return [int(d) for d in list(inputs)]
        else:
            # return map(int,input().split())
            return [int(d) for d in inputs.split(sp)]
    def debug_print(self, inputs, debug=False):
        if debug:
            print(inputs)

# 引用　python する man,「Pythonでの再帰関数とメモ化」, PSM, ２０１７、７/４
# http://muromura.hatenablog.com/entry/2017/07/04/204908#%E3%83%A1%E3%83%A2%E5%8C%96
def memorize(f):
    table = {}
    def func(*args):
        if not args in table:
            table[args] = f(*args)
        return table[args]
    return func
debug = False

u = CustomUtils()

n, q = u.to_int(input())
s = input()

import re

ss = []
m = re.finditer('AC', s)
for match in m:
    st, en= match.span()
    ss.append(st)
ss.sort()
ss = np.array(ss)

# そこまでに含まれるACの数を返す。
@memorize
def accumulative(i):
	if i == -1:
		return 0
	elif i -1 in ss:
		return accumulative(i-1)+1
	else:
		return accumulative(i-1)


for _ in range(q):
    # n文字目とindexがずれた。
    l, r = [int(x)  - 1 for x in input().split()]
    result = accumulative(r) - accumulative(l)
    # ちょうどindexlまでに含まれるACの数が、境界をまたぐ数。
    print("{}".format(result))

Submission status: Runtime Error

Solution code:
import pdb
import builtins
import sys
import numpy as np
class Test:
    def __init__(self):
        pass

class CustomUtils:
    def __init__(self):
        pass
    def to_int(self, inputs, sp=' '):
        if sp == '':
            return [int(d) for d in list(inputs)]
        else:
            # return map(int,input().split())
            return [int(d) for d in inputs.split(sp)]
    def debug_print(self, inputs, debug=False):
        if debug:
            print(inputs)

# 引用　python する man,「Pythonでの再帰関数とメモ化」, PSM, ２０１７、７/４
# http://muromura.hatenablog.com/entry/2017/07/04/204908#%E3%83%A1%E3%83%A2%E5%8C%96
def memorize(f):
    table = {}
    def func(*args):
        if not args in table:
            table[args] = f(*args)
        return table[args]
    return func
debug = False

u = CustomUtils()

n, q = u.to_int(input())
s = input()

import re

ss = []
m = re.finditer('AC', s)
for match in m:
    st, en= match.span()
    ss.append(st)
ss.sort()
ss = np.array(ss)

# そこまでに含まれるACの数を返す。
@memorize
def accumulative(i):
  if i == -1:
    return 0
  elif i -1 in ss:
    return accumulative(i-1)+1
  else:
    return accumulative(i-1)


for _ in range(q):
    # n文字目とindexがずれた。
    l, r = [int(x)  - 1 for x in input().split()]
    result = accumulative(r) - accumulative(l)
    # ちょうどindexlまでに含まれるACの数が、境界をまたぐ数。
    print("{}".format(result))

Submission status: Runtime Error

Solution code:
import pdb
import builtins
import sys
import numpy as np
class Test:
    def __init__(self):
        pass

class CustomUtils:
    def __init__(self):
        pass
    def to_int(self, inputs, sp=' '):
        if sp == '':
            return [int(d) for d in list(inputs)]
        else:
            # return map(int,input().split())
            return [int(d) for d in inputs.split(sp)]
    def debug_print(self, inputs, debug=False):
        if debug:
            print(inputs)

# 引用　python する man,「Pythonでの再帰関数とメモ化」, PSM, ２０１７、７/４
# http://muromura.hatenablog.com/entry/2017/07/04/204908#%E3%83%A1%E3%83%A2%E5%8C%96
def memorize(f):
    table = {}
    def func(*args):
        if not args in table:
            table[args] = f(*args)
        return table[args]
    return func
debug = False

u = CustomUtils()

n, q = u.to_int(input())
s = input()

import re

ss = []
m = re.finditer('AC', s)
for match in m:
    st, en= match.span()
    ss.append(st)
ss.sort()
ss = np.array(ss)

# そこまでに含まれるACの数を返す。
@memorize
def accumulative(i):
	if i == -1:
        return 0
    elif i -1 in ss:
        return accumulative(i-1)+1
    else:
        return accumulative(i-1)


for _ in range(q):
    # n文字目とindexがずれた。
    l, r = [int(x)  - 1 for x in input().split()]
    result = accumulative(r) - accumulative(l)
    # ちょうどindexlまでに含まれるACの数が、境界をまたぐ数。
    print("{}".format(result))

Submission status: Runtime Error

Solution code:
class Test:
    def __init__(self):
        pass

class CustomUtils:
    def __init__(self):
        pass
    def to_int(self, inputs, sp=' '):
        if sp == '':
            return [int(d) for d in list(inputs)]
        else:
            # return map(int,input().split())
            return [int(d) for d in inputs.split(sp)]
    def debug_print(self, inputs, debug=False):
        if debug:
            print(inputs)

# 引用　python する man,「Pythonでの再帰関数とメモ化」, PSM, ２０１７、７/４
# http://muromura.hatenablog.com/entry/2017/07/04/204908#%E3%83%A1%E3%83%A2%E5%8C%96
def memorize(f):
    table = {}
    def func(*args):
        if not args in table:
            table[args] = f(*args)
        return table[args]
    return func
debug = False

u = CustomUtils()

n, q = u.to_int(input())
s = input()

import re

ss = []
m = re.finditer('AC', s)
for match in m:
    st, en= match.span()
    ss.append(st)
ss.sort()
ss = np.array(ss)

# そこまでに含まれるACの数を返す。
@memorize
def accumulative(i):
    return sum(ss <= i - 1)
    
total = len(ss)

for _ in range(q):
    # n文字目とindexがずれた。
    l, r = [int(x)  - 1 for x in input().split()]
    result = accumulative(r) - accumulative(l)
    # ちょうどindexlまでに含まれるACの数が、境界をまたぐ数。
    print("{}".format(result))

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
    NQ = input().split(" ")
    N ,Q = int(NQ[0]),int(NQ[1])

    S = input()
    stack =[]
    for x in range(Q):
        lr = input()
        lr = lr.split(" ")
        l ,r = int(lr[0]),int(lr[1])
        target = S[l-1:r]
        stack.append((r-l+1-len(target.replace("AC"," ")))
        
        
    for x in stack:
        print(x)

Submission status: Runtime Error

Solution code:

class Test:
    def __init__(self):
        pass

class CustomUtils:
    def __init__(self):
        pass
    def to_int(self, inputs, sp=' '):
        if sp == '':
            return [int(d) for d in list(inputs)]
        else:
            # return map(int,input().split())
            return [int(d) for d in inputs.split(sp)]
    def debug_print(self, inputs, debug=False):
        if debug:
            print(inputs)

# 引用　python する man,「Pythonでの再帰関数とメモ化」, PSM, ２０１７、７/４
# http://muromura.hatenablog.com/entry/2017/07/04/204908#%E3%83%A1%E3%83%A2%E5%8C%96
def memorize(f):
    table = {}
    def func(*args):
        if not args in table:
            table[args] = f(*args)
        return table[args]
    return func
debug = False


u = CustomUtils()

n, q = u.to_int(input())
s = input()

import re
# カウントに関わる要素が同時に起こることはない（独立でもある。）
# この問題のみに特化したアルゴを書く
# そこまでに含まれているACの数とそこまでに崩されているACの数を数える。


ss = []
# 文字列をreで
# 先に処理, 同じことをなんどもやらんですむように
m = re.finditer('AC', s)
for match in m:
    st, en= match.span()
    ss.append(st)
ss.sort()
ss = np.array(ss)

#ここまでのコードでは時間切れにならないとはわかった。
#ちなみに各地点でのエンドポイントは各地点でのスタートポイント+...?

# そこまでに含まれるACの数を返す。
@memorize
def accumulative(i):
#     if i == -1:
#         return 0
#     elif i -1 in ss:
#         return accumulative(i-1)+1
#     else:
#         return accumulative(i-1)
    return sum(ss <= i - 1)
    # どうせブール値配列なのでsumでok
    

# array はすでにソート済みであり、ダブりはないものとする
# def bs_rank(array, target):
#     total = len(array)
#     half = int(total)
#     if target > array[-1]:
#     if array[half] > target:
#         return bs_cnt(array[half])
#     elsarray[half] > target:
#         return bs_cnt(array[half])
    
    
total = len(ss)

for _ in range(q):
    # n文字目とindexがずれた。
    l, r = [int(x)  - 1 for x in input().split()]
    result = accumulative(r) - accumulative(l)
    # ちょうどindexlまでに含まれるACの数が、境界をまたぐ数。
    print("{}".format(result))

Submission status: Runtime Error

Solution code:
class Test:
    def __init__(self):
        pass

class CustomUtils:
    def __init__(self):
        pass
    def to_int(self, inputs, sp=' '):
        if sp == '':
            return [int(d) for d in list(inputs)]
        else:
            # return map(int,input().split())
            return [int(d) for d in inputs.split(sp)]
    def debug_print(self, inputs, debug=False):
        if debug:
            print(inputs)

# 引用　python する man,「Pythonでの再帰関数とメモ化」, PSM, ２０１７、７/４
# http://muromura.hatenablog.com/entry/2017/07/04/204908#%E3%83%A1%E3%83%A2%E5%8C%96
def memorize(f):
    table = {}
    def func(*args):
        if not args in table:
            table[args] = f(*args)
        return table[args]
    return func
debug = False

u = CustomUtils()

n, q = u.to_int(input())
s = input()

import re
# カウントに関わる要素が同時に起こることはない（独立でもある。）
# この問題のみに特化したアルゴを書く
# そこまでに含まれているACの数とそこまでに崩されているACの数を数える。


ss = []
# 文字列をreで
# 先に処理, 同じことをなんどもやらんですむように
m = re.finditer('AC', s)
for match in m:
    st, en= match.span()
    ss.append(st)
ss.sort()
ss = np.array(ss)

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
    NQ = input().split(" ")
    N ,Q = int(NQ[0]),int(NQ[1])

    S = input()
    stack =[]
    for x in range(Q):
        lr = input()
        lr = lr.split(" ")
        l ,r = int(lr[0]),int(lr[1])
        target = S[l-1:r]
        num = target.split("AC")
        stack.append(num)
        print(target)
    for x in [len(y)-1 for y in stack]:
        print(x)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
str_ = ['' for i in range(Q)]
for i in range(Q):
        l, r = map(int, input().split())
        str_[i] = S[l-1:r]
for i in range(Q):
        count = 0
        ac_flag = 0
        for chr in str_[i]:
                if chr == 'A':
                        ac_flag = 1
                elif chr == 'C' and ac_flag == 1:
                        count += 1
                else:
                                ac_flag = 0
        print('{}'.format(count))

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
str_ = []
for i in range(Q):
        l, r = map(int, input().split())
    	str_[i] = S[l-1:r]
for i in range(Q):
        count = 0
        ac_flag = 0
        for chr in str_[i]:
                if chr == 'A':
                        ac_flag = 1
                elif chr == 'C' and ac_flag == 1:
                        count += 1
                else:
                  		ac_flag = 0
        print('{}'.format(count))

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
str_ = []
for i in range(Q):
        l, r = map(int, input().split())
    	str_[i] = S[l-1:r]
for i in range(Q):
        count = 0
        ac_flag = 0
        for chr in str_[i]:
                if chr == 'A':
                        ac_flag = 1
                elif chr == 'C' and ac_flag == 1:
                        count += 1
                else:

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
str_ = [0 for i in range(Q)]
for i in range(Q):
        l, r = map(int, input().split())
    	str_[i] = S[l-1:r]
for i in range(Q):
        count = 0
        ac_flag = 0
        for chr in str_[i]:
                if chr == 'A':
                        ac_flag = 1
                elif chr == 'C' and ac_flag == 1:
                        count += 1
                else:

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
str_ = [0 for i in range(0)]
for i in range(Q):
        l, r = map(int, input().split())
    	str_[i] = S[l-1:r]
for i in range(Q):
        count = 0
        ac_flag = 0
        for chr in str_[i]:
                if chr == 'A':
                        ac_flag = 1
                elif chr == 'C' and ac_flag == 1:
                        count += 1
                else:
                        ac_flag = 0
        print('{}'.format(count))

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
for i in range(Q):
        l[i], r[i] = map(int, input().split())
        str_[i] = S[l[i]-1:r[i]]
        count[i] = 0
        ac_flag[i] = 0
        for chr in str_[i]:
                if chr == 'A':
                        ac_flag[i] = 1
                elif chr == 'C' and ac_flag[i] == 1:
                        count[i] += 1
                else:
                        ac_flag[i] = 0
        print('{}'.format(count[i]))

Submission status: Runtime Error

Solution code:
times, questions = [int(a) for a in input().split()]

strings = str(input())

for i in range(questions):
    for j in range(times):
        start, end = [int(a) for a in input().split()]
        moji = strings[start - 1: end]
        counts = 0
        for k in range(len(moji) - 1):
            if moji[k] == 'A' and moji[k + 1] == 'C':
                counts += 1
        print(counts)

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
list_ac=[]
number=0
for i in range(0,len(s)):
    if s[i]=='A':
        state=1
        list_ac.append(number)
    elif s[i]=='C':
        if state==1:
            number=number+1   
        list_ac.append(number)
        state=0
    else:
        state=0
        list_ac.append(number)
list_ac.append(list_ac[-1])
for i in range(0,q):
    l,r=map(int,input().split())
    print(list_ac[r-1]-list_ac[l-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
list_ac=[]
number=0
for i in range(0,len(s)):
    if s[i]=='A':
        state=1
        list_ac.append(number)
    elif s[i]=='C':
        if state==1:
            number=number+1   
        list_ac.append(number)
        state=0
    else:
        state=0
        list_ac.append(number)
for i in range(0,q):
    l,r=map(int,input().split())
    print(list_ac[r-1]-list_ac[l-1])

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
list_ac=[]
for i in range(0,len(s)):
    if s[i]=='A':
        place=i
        state=1
    elif s[i]=='C':
        if state==1:
            list_ac.append(place)
        state=0
    else:
        state=0      
for i in range(0,q):
    l,r=map(int,input().split())
    count=0
    for j in list_ac:
        if l-1<=j<=r-2:
            count=count+1
        elif j>r-2:
            break
    print(count)

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = str(input())
position = [0] * (N)
count = 0
for i in range(N):
    if S[i] == "A" and S[i + 1] == "C":
        count += 1
    position[i] = count

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