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()
i=0
d=""
while i<n:
	if s[i]=="A" and s[i+1]=="C":
		d+="0"*2
		i+=2
	else:
		d+=s[i]
		i+=1
num=[0]*n
cnt=0
for i in range(n):
	if d[i]=="0":
		cnt+=1
	num[i]=cnt//2
for i in range(q):
	x,y=map(int,input().split())
	print(num[y-1]-num[x-1])

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

exist = [0]*n
for i in range(1,n):
    if s[i-1:i+1] == 'AC':
        exist[i+1] = 1

for i in range(q):
    if lr[i][1] - lr[i][0] < 2:
        print(0)
    else:
        print(sum(exist[lr[i][0]-1:lr[i][1]]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i,j in l:
    ans=0
    tmp=0
    for k in range(i-1,j):
        if s[k]=="A" and s[k+1]=="C" and k!=j-1:
            ans+=1
    print(ans)

Submission status: Runtime Error

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

l = [0]
ll = []
count = 0

for i in range(n):
    if s[i] == 'A' and s[i+1] == 'C':
        count += 1
    l.append(count)


for i in range(q):
    array = list(map(int, input().split()))
    ll.append(array)

for i in range(q):
    print(l[ll[i][1]-1] - l[ll[i][0]-1])

Submission status: Runtime Error

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

l = [0]
ll = []
count = 0

for i in range(n):
    if s[i] == 'A' and s[i+1] == 'C':
        count += 1
    l.append(count)


for i in range(q):
    array = list(map(int, input().split()))
    ll.append(array)

for i in range(q):
    print(l[ll[i][1]-1] - l[ll[i][0]-1])

print(l)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = 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()) # input:"2 2"
s = str(input())
#どこにACがあるかを計算しておいて、あとからL,Rでsplitする
ans=[0]*(n+1)
for i in range(n):
  if s[i]=='A' and s[i+1]=='C':
    ans[i+1]=ans[i]+1
  else:
    ans[i+1]=ans[i]
#ti =「S の 1 文字目から i 文字目までに出現する a の数」として数列 t = {t0, t1, . . . , tN } を考えると、問 i の答えは tri−1 − tli−1
for i in range(q):
  l, r = map(int, input().split()) #ループ内で一行ずつ読み込む
  print(ans[r-1]-ans[l-1])

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split()) # input:"2 2"
s = str(input())
#どこにACがあるかを計算しておいて、あとからL,Rでsplitする
ans=[0]*n
for i in range(n):
  if s[i]=='A' and s[i+1]=='C':
    ans[i]=1
for i in range(q):
  tmp=0
  l, r = map(int, input().split()) #ループ内で一行ずつ読み込む
  tmp=sum(ans[l-1:r-1])
  print(tmp)

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split()) # input:"2 2"
s = str(input())
#どこにACがあるかを計算しておいて、あとからL,Rでsplitする
ans=[0]*n
for i in range(n):
  if s[i]=='A' and s[i+1]=='C':
    ans[i]=1
for i in range(q):
  l, r = map(int, input().split()) #ループ内で一行ずつ読み込む
  print(sum(ans[l-1:r-1]))

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split()) # input:"2 2"
s = str(input())
#どこにACがあるかを計算しておいて、あとからL,Rでsplitする
ans=[0]*n
for i in range(n):
  if s[i]=='A' and s[i+1]=='C':
    ans[i]=1
for i in range(q):
  l, r = map(int, input().split()) #ループ内で一行ずつ読み込む
  print(sum(ans[L[i]-1:R[i]-1]))

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split()) # input:"2 2"
s = str(input())
Row=q
L=[]
R=[]
for i in range(Row):
    l,r=input().split()
    L.append(int(l))
    R.append(int(r))
#どこにACがあるかを計算しておいて、あとからL,Rでsplitする
ans=[0]*n
for i in range(n):
  if s[i]=='A' and s[i+1]=='C':
    ans[i]=1
for i in range(q):
  print(sum(ans[L[i]-1:R[i]-1]))

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split()) # input:"2 2"
s = str(input())
Row=q
L=[]
R=[]
for i in range(Row):
    l,r=input().split()
    L.append(int(l))
    R.append(int(r))
#どこにACがあるかを計算しておいて、あとからL,Rでsplitする
ans=[0]*n
for i in range(n):
  if s[i]=='A' and s[i+1]=='C':
    ans[i]=1
for i in range(len(L)):
  tmp=0
  print(sum(ans[L[i]-1:R[i]-1]))

Submission status: Runtime Error

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

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

for i in range(q):
    print(sum(x[(lr[i][0]-1):(lr[i][1]-1)]))

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
8 3
s = input()
ACACTACG
lr = list(list(map(int,input().split())) for i in range(q))
3 7
2 3
1 8

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

for i in range(q):
    print(sum(x[(lr[i][0]-1):(lr[i][1]-1)]))

Submission status: Runtime Error

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

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

for i in range(q):
    print(sum((x[(lr[i][0]-1):(lr[i][1]-1)])))

Submission status: Runtime Error

Solution code:
a=list(map(int,input().split()))
n,q,b,c=a[0],a[1],[],[]
s=input()
for i in range(q):
    b.append(list(map(int,input().split())))
for i in range(len(s)):
    if s[i]=='A' and s[i+1]=='C':
        c.append(1)
    else:
        c.append(0)
for i in range(q):
    print(sum(c[b[i][0]-1:b[i][1]-1]))

Submission status: Runtime Error

Solution code:
n, q = map(int,input().split())
s = list(input())
x = []
ans = 0
for i in range(n-1):
	if s[i] == "A" and s[i+1] == "C":
		ans += 1
		x.append(ans)
	else:
		x.append(ans)

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

Submission status: Runtime Error

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

ans = 0
for i in range(n):
	if s[i] == "A" and s[i+1] == "C":
		ans += 1
		x.append(ans)
	else:
		x.append(ans)

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

Submission status: Runtime Error

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

ans = 0
for i in range(n):
	if s[i] == "A" and s[i+1] == "C":
		ans += 1
		x.append(ans)
	else:
		x.append(ans)
x.append(ans)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split())
s = input()
l = []
r = []
t = [0]*len(s)

for i in range(q):
    temp1, temp2 = map(int, input().split())
    l.append(temp1)
    r.append(temp2)

for i in range(1, len(s)):
    if s[i-1] + s[i] ==	'AC':
		t[i] = t[i-1] + 1
    else:
        t[i] = t[i-1]

#print(t)

for i in range(q):
    left = l[i]	- 1
    right = r[i] - 1
    # print(left)
    # print(right)
    print(t[right] - t[left])

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split())
s = input()
l = []
r = []
t = [0]*len(s)

for i in range(q):
    temp1, temp2 = map(int, input().split())
    l.append(temp1)
    r.append(temp2)

for i in range(1, len(s)):
    if s[i-1] + s[i] ==	'AC':
	t[i] = t[i-1] + 1
    else:
        t[i] = t[i-1]

#print(t)

for i in range(q):
    left = l[i]	- 1
    right = r[i] - 1
    # print(left)
    # print(right)
    print(t[right] - t[left])

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
s = input()
mylist = []
for i in range(n):
    if s[i] + s[i+1] == "AC":
        mylist.append(i)
for i in range(q):
    cnt = 0
    l,r = map(int,input().split())
    for j in range(len(mylist)):
        if l-1<=mylist[j]<=r-1:
              cnt +=1
    print(cnt)

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
s = input()
mylist = []
for i in range(n):
    if s[i] + s[i+1] == "AC":
        mylist.append(i)
for i in range(q):
    cnt = 0
    l,r = map(int,input().split()
    for j in range(len(mylist)):
        if l-1<=mylist[j]<=r-1:
              cnt +=1
    print(cnt)

Submission status: Runtime Error

Solution code:
from itertools import accumulate

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

s_list = [0]*(N+1)
for i in range(1,N+1):
    if S[i-1] == 'A':
        if S[i] == 'C':
            s_list[i] = 1
s_list = list(accumulate(s_list))
for i,j in zip(L, R):
    print(s_list[j-1]-s_list[i-1])

Submission status: Runtime Error

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

nums = [0] * (N+1) 
count = 0
for i in range(len(S)):
    nums[i] = count
    if S[i] == "A" and S[i+1] == "C":
        count += 1

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

Submission status: Runtime Error

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

nums = [0] * (N+1) 
count = 0
for i in range(len(S)):
    nums[i] = count
    if S[i] == "A" and S[i+1] == "C":
        count += 1

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
AClst = []
c = 0

for i in range(N-1):
  if S[i:i+2]=="AC":
    c += 1
  AClst.append(c)
AClst.append(c)

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

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
AClst = []
count = 0

for i in range(N-1):
  if S[i:i+2]=="AC":
    c += 1
  AClst.append(c)
AClst.append(c)

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

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
AClst = [] #ACのAを抜き出すリスト

for i in range(N-1):
  if S[i,i+2]=="AC":
    AClst.append(1)
  else:
    AClst.append(0)
AClst.append(0)

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

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
AClst = [] #ACのAを抜き出すリスト

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

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

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
AClst = [] #ACのAを抜き出すリスト

for i in range(len(s)-1):
  if S[i,i+2]=="A":
    AClst.append(1)
  else:
    AClst.append(0)

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

Submission status: Runtime Error

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

for i in range(1,n):
  if s[i-1]==A and s[i]==C:
    a[i]=a[i-1]+1
  else:
    a[i]=a[i-1]
    
for i in range(q):
  sita,ue=map(int,input().split())
  if sita==1:
    print(a[ue-1])
  elif s[sita-2]=='A' and s[sita-1]=='C':
    print(a[ue-1]-a[sita-2]-1)
  else:
    print(a[ue-1]-a[sita-2])

Submission status: Runtime Error

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

count=0


ans=[0 for i in range(n+2)]
for i in range(n-1):
  if s[i]+s[i+1]=='AC':
    count+=1
    ans[i+1]=count
  else:
    ans[i+1]=count
ans[n]=ans[n-1]
ans[n+1]=ans[n]


for i in range(q):
  sita,ue=map(int,input().split())
  if s[ue-1]=='A' and s[ue]=='C' and ue!=n:
    print(ans[ue]-ans[sita-1]-1)
  
  else:
    print(ans[ue]-ans[sita-1])

Submission status: Runtime Error

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

count=0


ans=[0 for i in range(n+2)]
for i in range(n-1):
  if s[i]+s[i+1]=='AC':
    count+=1
    ans[i+1]=count
  else:
    ans[i+1]=count
ans[n]=ans[n-1]
ans[n+1]=ans[n]


for i in range(q):
  sita,ue=map(int,input().split())
  if s[ue-1]=='A' and s[ue]=='C':
    print(ans[ue]-ans[sita-1]-1)
  
  else:
    print(ans[ue]-ans[sita-1])

Submission status: Runtime Error

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

count=0


ans=[0 for i in range(n+2)]
for i in range(n-1):
  if s[i]+s[i+1]=='AC':
    count+=1
    ans[i+1]=count
  else:
    ans[i+1]=count
ans[n]=ans[n-1]
ans[n+1]=ans[n]

print(*ans)

for i in range(q):
  sita,ue=map(int,input().split())
  if s[ue-1]=='A' and s[ue]=='C':
    print(ans[ue]-ans[sita-1]-1)
  
  else:
    print(ans[ue]-ans[sita-1])

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=list(input())
li=[0]*n
cnt=0
ans=0

for i in range(n):
  if i==0:
    continue
  if s[i-1]=="A" and s[i]=="C":
    cnt+=1  
  li[i]=cnt
    
for i in range(q):
  l,r=map(int,input().split())
  ans=li[r]-li[l]
  print(ans)

Submission status: Runtime Error

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

for i in range(n):
  if i==0:
    continue
  if s[i-1]=="A" and s[i]=="T":
    li[i]=1

for i in range(q):
  l,r=map(int,input())
  tmp=li[l:r]
  print(sum(temp))

Submission status: Runtime Error

Solution code:
import re
2. 
3.def a():
4.	b = input()
5.    l, r = b.split(" ")
6.    l = int(l)
7.    r = int(r)
8.    acList = re.findall("AC", S[l-1:r])
9.    print(len(acList))
10. 
11.a = input()
12.N, Q = a.split(" ")
13.S = input()
14.for i in range(int(Q)):
15.  	a()

Submission status: Runtime Error

Solution code:
import re

def a():
    a = input()
    N, Q = a.split(" ")
    S = input()
    for i in range(int(Q)):
        b = input()
        l, r = b.split(" ")
        l = int(l)
        r = int(r)
        acList = re.findall("AC", S[l-1:r])
        print("Sの先頭から{3}文字目から{2}文字目までの部分文字列は{1}です。この文字列に'AC'は部分文字列として{0}回含まれます。"
             .format(len(acList), S[l-1:r], r, l))

a()

Submission status: Runtime Error

Solution code:
sn,qn=map(int,input().split())
s=input()
x=list(list(map(int,input().split())) for _ in range(qn))

import math

s2=[0]*(sn+1)

for i in range(sn):
	if s[i]=='A' and s[i+1]=='C':
		s2[i]=0.5
		s2[i+1]=0.5

al=sum(s2)

for i in range(qn):
	res=al-math.ceil(sum(s2[:x[i][0]-1]))-math.ceil(sum(s2[x[i][1]:]))
	print(int(res))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ac_list = [0 for i in range(a[0])]
is_a = False
mojiretu = input()

for i in range(1, a[0] + 1):
    if mojiretu[i - 1] == "A" and mojiretu[i] == "C":
        ac_list[i] = 1

list_num = []
for i in range(a[1]):
    u = input().split()
    u = [int(f) for f in u]
    list_kari = ac_list[u[0] - 1:u[1]]
    if mojiretu[u[0]-1] == "C" and 1 in list_kari:
        list_num.append(sum(list_kari) - 1)
    else:
        list_num.append(sum(list_kari))

for i in list_num:
    print(i)

Submission status: Runtime Error

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

ac_list = [0 for i in range(a[0])]
is_a = False
mojiretu = input()

for i in range(1, a[0] + 1):
    if mojiretu[i - 1] == "A" and mojiretu[i] == "C":
        ac_list[i] = 1

list_num = []
for i in range(a[1]):
    u = input().split()
    u = [int(f) for f in u]
    list_kari = ac_list[u[0] - 1:u[1]]
    if mojiretu[u[0]-1] == "C":
        list_num.append(sum(list_kari) - 1)
    else:
        list_num.append(sum(list_kari))

for i in list_num:
    print(i)

Submission status: Runtime Error

Solution code:
from bisect import bisect, bisect_left
N, Q = map(input().split(), int)
S = input()
ac = []
for i in range(N-1):
  if S[i:i+1] == "AC":
    ac.append(i)
for i in range(Q):
  l, r = map(input().split(), int)
  l -= 1
  r -= 1
  print(bisect_right(ac, r-1) - bisect_left(ac, l))

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
AC = []
ans = []
AC.append(0)
for i in range(1,N+1):
    if S[i - 1] == "A" and S[i] == "C":
        AC.append(AC[i - 1] + 1)
    else:
        AC.append(AC[i - 1])
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(AC[r - 1] - AC[l - 1])
print("\n".join(map(str,ans)))

Submission status: Runtime Error

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

Temp = [0 for i in range(N)]
num = 0
while num <= N-2:
    if S[num] == "A" and S[num+1] == "C":
        Temp[num] = 1
        Temp[num+1] = 2
    num += 1

for j in range(Q):
    Temp2 = Temp[L[j][0]-1:L[j][1]]
    c = sum(Temp2)
    if c%3 == 0:
        if Temp2[0] != 2
            print(int(c/3))
        else:
            print(int(c/3-1))
    elif c%3 == 1:
        print(int((c-1)/3))
    else:
        print(int((c-2)/3))

Submission status: Runtime Error

Solution code:
from functools import reduce

N, Q = map(int, input())
S = input()
LR = [list(map(int, input())) for i in range(Q)]

P = []
before_a = False
for i in range(N):
  if before_a and S[i] == 'C':
    P.append(i)
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
for i in range(Q):
  ans = 0
  for num in P:
    if num-1 >= LR[i][0] and num <= LR[i][1]:
      ans += 1
  print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce

N, Q = map(int, input())
S = input()
LR = [list(map(int, input())) for i in range(Q)]

P = []
before_a = False
for i in range(N):
  if before_a and S[i] == 'C':
    P.append(i)
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
for i in range(Q):
  ans = 0
  for num in P:
    if num-1 >= LR[i][0] and num >= LR[i][1]:
      ans += 1
  print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce

N, Q = map(int, input())
S = input()
LR = [list(map(int, input())) for i in range(Q)]

P = []
before_a = False
for i in range(N):
  if before_a and S[i] == 'C':
    P.append(i)
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
for i in range(Q):
  print(reduce(lambda x: if x >= RL[i][0]-1 and x <= RL[i][1]: return 1, P))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
Last login: Thu Jul  4 14:50:06 on ttys001
jngt@Nagata:Documents$ abc122
zsh: command not found: abc122
jngt@Nagata:Documents$ atcoder
jngt@Nagata:atcoder$ abc122
jngt@Nagata:abc122$ ls
a.py  b.py  c.py
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 8[0, 2, 5]
jngt@Nagata:abc122$ 3 7
zsh: command not found: 3
jngt@Nagata:abc122$ 2 3
zsh: command not found: 2
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 8
[0, 2, 5]
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 82
0

3
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 82
0
^[  
Traceback (most recent call last):
  File "c.py", line 33, in <module>
    
  File "c.py", line 29, in main
    l, r = MAP()
ValueError: invalid literal for int() with base 10: '8\x1b'
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 8
2
0
3
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 8> /Users/jngt/Documents/atcoder/abc122/c.py(29)main()
-> for i in range(Q):
(Pdb) 3 7
*** SyntaxError: invalid syntax
(Pdb) 2 3
*** SyntaxError: invalid syntax
(Pdb) t
[0, 1, 1, 2, 2, 2, 3, 3, 0]
(Pdb) q
Traceback (most recent call last):
  File "c.py", line 36, in <module>
    main()
  File "c.py", line 29, in main
    for i in range(Q):
  File "c.py", line 29, in main
    for i in range(Q):
  File "/Users/jngt/anaconda/lib/python3.6/bdb.py", line 48, in trace_dispatch
    return self.dispatch_line(frame)
  File "/Users/jngt/anaconda/lib/python3.6/bdb.py", line 67, in dispatch_line
    if self.quitting: raise BdbQuit
bdb.BdbQuit
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 8> /Users/jngt/Documents/atcoder/abc122/c.py(29)main()
-> for i in range(Q):
(Pdb) 3 7
*** SyntaxError: invalid syntax
(Pdb) 2 3
*** SyntaxError: invalid syntax
(Pdb) t
[0, 1, 1, 2, 2, 2, 3, 3, 3]
(Pdb) q
Traceback (most recent call last):
  File "c.py", line 36, in <module>
    main()
  File "c.py", line 29, in main
    for i in range(Q):
  File "c.py", line 29, in main
    for i in range(Q):
  File "/Users/jngt/anaconda/lib/python3.6/bdb.py", line 48, in trace_dispatch
    return self.dispatch_line(frame)
  File "/Users/jngt/anaconda/lib/python3.6/bdb.py", line 67, in dispatch_line
    if self.quitting: raise BdbQuit
bdb.BdbQuit
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 8> /Users/jngt/Documents/atcoder/abc122/c.py(29)main()
-> for i in range(Q):
(Pdb) 3 7
*** SyntaxError: invalid syntax
(Pdb) 2 3
*** SyntaxError: invalid syntax
(Pdb) 1 8
*** SyntaxError: invalid syntax
(Pdb) q
Traceback (most recent call last):
  File "c.py", line 36, in <module>
    main()
  File "c.py", line 29, in main
    for i in range(Q):
  File "c.py", line 29, in main
    for i in range(Q):
  File "/Users/jngt/anaconda/lib/python3.6/bdb.py", line 48, in trace_dispatch
    return self.dispatch_line(frame)
  File "/Users/jngt/anaconda/lib/python3.6/bdb.py", line 67, in dispatch_line
    if self.quitting: raise BdbQuit
bdb.BdbQuit
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 8> /Users/jngt/Documents/atcoder/abc122/c.py(29)main()
-> for i in range(Q):
(Pdb) 3 7
*** SyntaxError: invalid syntax
(Pdb) 2 3
*** SyntaxError: invalid syntax
(Pdb) 1 8
*** SyntaxError: invalid syntax
(Pdb) q
Traceback (most recent call last):
  File "c.py", line 36, in <module>
    main()
  File "c.py", line 29, in main
    for i in range(Q):
  File "c.py", line 29, in main
    for i in range(Q):
  File "/Users/jngt/anaconda/lib/python3.6/bdb.py", line 48, in trace_dispatch
    return self.dispatch_line(frame)
  File "/Users/jngt/anaconda/lib/python3.6/bdb.py", line 67, in dispatch_line
    if self.quitting: raise BdbQuit
bdb.BdbQuit
jngt@Nagata:abc122$ python c.py
8 3
ACACTACG
3 7
2 3
1 8
2
0
3
jngt@Nagata:abc122$

Submission status: Runtime Error

Solution code:
import re
n, q = map(int, input().split())
st = input()
lst = []
for i in range(q):
    l, r = map(int, input().split())
    s = st[l-1:r]
    lst.append(s)
    
    # count = ac_str.count('AC')
    # ans.append(count)

for ac_str in lst:
    ss = 0
    for m in re.finditer('AC', ac_str):
        ss += 1
    print(ss)

Submission status: Runtime Error

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


for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
Sum = [0]*(N+1)
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, r = map(int, input().split())
	print(Sum[r-1] - Sum[l-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = str(input())
cnt = 0
count = [0]*(N+1)
lists_l = []
lists_r = []
for i in range(N):
    if S[i] == "A" and S[i + 1] == "C":
        count[i + 1] = count[i] + 1
    else:
        count[i + 1] = count[i]
for i in range(Q):
    l, r = map(int, input().split())
    lists_l.append(l)
    lists_r.append(r)
for i in range(Q):
    L = lists_l[i]
    R = lists_r[i]
    print(count[R-1] - count[L-1])

Submission status: Runtime Error

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

    c = [0] * n
    for i in range(1, n):
        if s[i-1:i+1] == "AC":
            c[i] = c[i-1] + 1
        else:
            c[i] = c[i-1]
    for i in range(q):
        l, r = dat_q[i][0], dat_q[i][1]
        print(c[r - 1] - c[l - 1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
N,Q = map(int,input().split())
S = input()
ans =[]
for i in range(N):
  if S[i] == 'A':
    if S[i+1] == 'C':
      ans.append(i)
ans2 = np.array(ans)
for i in range(Q):
  l,r = map(int,input().split())
  print(np.count_nonzero((l-2<ans2)&(ans2<r-1)))

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] + (1if 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()
flag = False
cnt = 0
dp = []
for i in range(len(s)):
    if s[i] == "A":
        flag = True
        dp.append(cnt)
        continue
    if s[i] == "C" and flag:
        cnt += 1
        dp.append(cnt)
        flag = False
for i in range(q):
    l,r = map(int, input().split())
    print(max(dp[l:r]) - dp[l-1])

Submission status: Runtime Error

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

for q in range(Q):
    q_list[q] = list(map(int, input().split()))

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

for item in q_list:
    l, r = item[0], item[1]
    print(ac_list[r - 1] - ac_list[l - 1])

Submission status: Runtime Error

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

for q in range(Q):
    q_list[q] = list(map(int, input().split()))

ac_list = [0] * len(S)
count = 0
for i in range(1, len(S)):
    if S[i - 1] == 'A' and S[i] == 'C':
        count += 1
        ac_list[i] = count
    else:
        ac_list[i] = count
#print(ac_list)
for item in q_list:
    l, r = item[0], item[1]

    print(ac_list[r - 1] - ac_list[l - 1])