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:
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):
	answer = 0
	for n in ac:
		if n >= lr[i][0] and n+1 <= lr[i][1]:
			answer += 1
    print(answer)

Submission status: Runtime Error

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
    temp = list(map(int, input().split()))
    L.append(temp)
    I = []
    for i in range(len(S)-1):
    if S[i] == "A" and S[i+1] == "C":
        I.append(i)
    for j in range(Q):
    cnt = 0
    l,r = L[j]
    R = []
    for k in range(l-1,r-1):
        R.append(k)
    for i in I:
        if i in R:
            cnt += 1
    print(cnt)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,Q =map(int,input().split())
S=str(input())
A=[0]*N
P=0
for i in range(N):
  if S[i]=='A' and S[i+1]=='C':
    P +=1
  A[i]+=P
print(A)
for i 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=str(input())
A=[0]*N
P=1
for i in range(N):
  if S[i]=='A' and S[i+1]=='C':
    A[i] = P
    P +=1
print(A)
for i in range(Q):
  l,r = map(int,input().split())
  if l==1:
    print(max(A[:r-2]))
  else:
    print(max(A[:r-2])-max(A[:l-1]))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
import bisect


def main():
    N, Q = [int(x) for x in input().split()]
    S = input().strip()

    ac = []
    for i, s in enumerate(S):
        if s == 'A' and S[i + 1] == 'C':
            ac.append(i)

    for _ in range(Q):
        x, y = [int(x) for x in input().split()]
        l = bisect.bisect_left(ac, x - 1)
        r = bisect.bisect_right(ac, y - 2)
        print(r - l)

    
    




if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

counts = [1 if s[i]=="A" and s[i+1]=="C" else 0 for i in range(n)]
cum_counts = [sum(counts[:i]) for i in range(n)]

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

Submission status: Runtime Error

Solution code:
from itertools import accumulate

N, Q = map(int, input().split())
S = input()
A = [list(map(int, input().split())) for i in range(Q)]
# リストに入れておく
#print(A)

flg = []
for i in range(N-1):
    tmp_S = S[i:i+2]
    if tmp_S == 'AC':
        flg.append(1)
    else:
        flg.append(0)
# print(len(flg)) #N-1になっていることを確認

ans = []
ans = [0] + flg #繋げて
ans = list(accumulate(flg)) #累積和にする
#print(ans)

for li in A:
    print(ans[li[1]-1] - ans[li[0]-1] )

Submission status: Runtime Error

Solution code:
N,Q = [int(i) for i in input().split()]
S = str(input())
lrlist = []
for i in range(Q):
    lrlist.append([int(i)-1 for i in input().split()])

#print(S)
#print(lrlist)

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


for l,r in lrlist:
    ans = 0
    for i in Asite:
        if l <= i and i+1 <= r:
            ans+=1
    print(ans)

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
lst=[]
for i in range(n):
    if s[i]=="A" and s[i+1]=="C":
        lst.append(i+1)
x=len(lst)
ans=[]
for j in range(q):
    l,r=map(int,input().split())
    for k in range(x):
        mi=1
        if lst[k]>l:
            mi=k
            break
    for k in range(x):
        ma=x
        if lst[k]>r-1:
            ma=k-1
            break
    ans.append(ma-mi+1)
for i in range(len(ans)):
    print(ans[i])

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[0]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

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

for k in range(0,q):
  print(x[r[k]-1]-x[l[k]-1])

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[0]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

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

for k in range(0,q):
  print(x[r[k]-1]-x[l[k]-1])

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

for j in range(0,n):
  if s[j]=="A" and s[j+1]=="C":
    ans+=1
    x.append(ans)
  
for k in range(0,q):
  print(x[r[k]-1]-x[l[k]-1])

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

for j in range(0,n):
  if s[j]=="A" and s[j+1]=="C":
      ans+=1
      x.append(ans)
  
for k in range(0,q):
  print(x[r[k]-1]-x[l[k]-1])

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

for j in range(0,q):
  for k in range(l[j],r[j]):
    if s[k]=="A" and s[k+1]=="C":
      ans+=1
    else:
      ans+=0
  x.append(ans)
  ans=0
  
for m in range(0,q):
  print(x[m])

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[]
for i in range(q):
  x1,y1=[int(i) for i in input().split()]
  x.append(x1)
  y.append(y1)
  
for j in range(0,q):
  for k in range(l[j],r[j]):
    if s[k]=="A" and s[k+1]=="C":
      ans+=1
    else:
      ans+=0
  x.append(ans)
  ans=0
  
for m in range(0,q):
  print(x[m])

Submission status: Runtime Error

Solution code:
n,q=map(int(input()).split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[]
for i in range(q):
  x1,y1=[int(i) for i in input().split()]
  x.append(x1)
  y.append(y1)
  
for j in range(0,q):
  for k in range(l[j],r[j]):
    if s[k]=="A" and s[k+1]=="C":
      ans+=1
    else:
      ans+=0
  x.append(ans)
  ans=0
  
for m in range(0,q):
  print(x[m])

Submission status: Runtime Error

Solution code:
import numpy as np

N, Q = map(int, input().split())
S = input()
ac_array = np.zeros(N)
ans = []

for i in range(N):
    if S[i] == 'A' and S[i+1] == 'C':
        ac_array[i] += 1
#         ac_array[i+1] += 1
# print(ac_array)
t = []
t.append(0)
for j in range(N):
    t.append(ac_array[:j+1].sum())
#     print(ac_array[:j+1])
# q_list = np.zeros([Q, 2])
# print(ac_array, t)
for q in range(Q):
    q_l, q_r = map(int, input().split())
    ans.append(t[q_r-1]-t[max(q_l-1, 0)])
    
#     q_list[q, 0], q_list[q, 1] = map(int, input().split())
#     ans.append(ac_array[int(q_list[q, 0]-1):int(q_list[q,1]-1)].sum())   

for a in range(Q):
    print(int(ans[a]))

Submission status: Runtime Error

Solution code:
import numpy as np

N, Q = map(int, input().split())
S = input()
ac_array = np.zeros(N)
ans = []

for i in range(N):
    if S[i] == 'A' and S[i+1] == 'C':
        ac_array[i] += 1
#         ac_array[i+1] += 1
# print(ac_array)
q_list = np.zeros([Q, 2])
for q in range(Q):
    q_list[q, 0], q_list[q, 1] = map(int, input().split())
    ans.append(ac_array[int(q_list[q, 0]-1):int(q_list[q,1]-1)].sum())

for a in range(Q):
    print(int(ans[a]))

Submission status: Runtime Error

Solution code:
import numpy as np

N, Q = map(int, input().split())
S = input()
ac_array = np.zeros(N)
ans = []

for i in range(N):
    if S[i] == 'A' and S[i+1] == 'C':
        ac_array[i] += 1
        ac_array[i+1] += 1
#print(ac_array)
q_list = np.zeros([Q, 2])
for q in range(Q):
    q_list[q, 0], q_list[q, 1] = map(int, input().split())
    ans.append(np.trunc(ac_array[int(q_list[q, 0]-1):int(q_list[q,1])].sum()/2))

for a in range(Q):
    print(int(ans[a]))

Submission status: Runtime Error

Solution code:
import numpy as np

N, Q = map(int, input().split())
S = input()
ac_array = np.zeros(N)
ans = []

for i in range(N):
    if S[i] == 'A' and S[i+1] == 'C':
        ac_array[i] += 1
        ac_array[i+1] += 1
print(ac_array)
q_list = np.zeros([Q, 2])
for q in range(Q):
    q_list[q, 0], q_list[q, 1] = map(int, input().split())
    ans.append(np.trunc(ac_array[int(q_list[q, 0]-1):int(q_list[q,1])].sum()/2))

for a in range(Q):
    print(int(ans[a]))

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
s = list(input())
li = [0]*(a+1)
for i in range(a):
    if s[i] == "A":
        if s[i+1] == "C":
            li[i+1]  = 1

li2 = [0]*(a+1)
li2[0] = li[0]
for i in range(1,len(li)):
    li2[i] = li2[i-1]+li[i]

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split())
S = input()
partS = []
for _ in range(q):
    l, r = map(int, input().split())
    partS .append(S[l - 1:r])
for i in range(q):
    print(partS[i].count("AC"))

Submission status: Runtime Error

Solution code:
    N, Q = [int(x) for x in input().split()]
    S = input()
    lr = [[int(x) for x in input().split()] for _ in range(Q)]
    for l, r in lr:
        cnt = 0
        for i in range(r-l):
            cnt += (S[l-1+i] == 'A' and S[l+i] == 'C')
        print(cnt)

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

cut = ""

conlist = []

for i in range(Q):
	cut = S[L[i][0]-1:L[i][1]]
	conlist.append(cut.count("AC"))
	print(cut)
print(max(conlist))

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):
    print(t[R[i]] - t[L[i]])

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
for i in range(n):
  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 = input()

for i in range(Q):
    cnt = 0
    l, r = map(int, input().split())
    T = S[l-1:r]
    for t in list(T):
        if t=="A":
            flag = True
        elif t=="T" and flag:
            cnt += 1
            flag = False
        else:
            flag = False
    print(cnt)

Submission status: Runtime Error

Solution code:
from sys import stdin


def main():
    lines = stdin.readlines()
    S = lines[1]
    lr = [[int(j) - 1 for j in i.split()] for i in lines[2:]]
    AC = []
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in lr:
        print(AC[r] - AC[l])
    return


main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
N , Q = map(int,input().split())

S = list(input())
l_list = []
r_list = []
slice_list = []
for _ in range(Q):
    l , r =map(int,input().split())
    slice_list.append([l - 1,r - 1])
cnt_list = [0] * (N + 1)
#print(cnt_list)

for i in range(len(S)):
    if S[i] == "A" and S[i + 1] == "C":
        cnt_list[i + 1] = cnt_list[i] + 1
    else:
        cnt_list[i + 1] = cnt_list[i]
#print(cnt_list)
for i in range(Q):
    #l, r = map(int, input().split())
    print(cnt_list[slice_list[i][1]] - cnt_list[slice_list[i][0]])

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
str = input()
length = [list(map(int, input().split())) for _ in range(Q)]

ans = [0 for _ in range(N)]
for i in range(1, N):
    if (str[i-1] == "A"):
        if (str[i] == "C"):
            ans[i] = ans[i-1] + 1
        else:
            ans[i] = ans[i-1]
    else:
        ans[i] = ans[i-1]
        ans[i+1] = ans[i-1]
        i += 1

for l1, l2 in length:
    # print(ans)
    print(ans[l2-1] - ans[l1-1])

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
str = input()
length = [list(map(int, input().split())) for _ in range(Q)]

ans = [0 for _ in range(N)]
for i in range(1, N):
    if (str[i-1] == "A")
        if (str[i] == "C"):
            ans[i] = ans[i-1] + 1
        else:
            ans[i] = ans[i-1]
    else:
        ans[i] = ans[i-1]
        ans[i+1] = ans[i-1]
        i += 1

for l1, l2 in length:
    # print(ans)
    print(ans[l2-1] - ans[l1-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)]
s_len = len(s)
account = s.count('AC')
count = 0
for i in range(q):
    center = len(s[l[i][0]-1:s[l[i][1]]])
    if center <= s_len:
        print(s[l[i][0]-1:s[l[i][1]]].count('AC'))
    else:
        '''
        left = s[0:]
        if s[l[i][0]-1:l[i][0]+1] == 'AC':
            count += 1
        if s[l[i][1]-1:l[i][1]+!] =='AC':
            count += 1
        print(account-)
        '''
        pass

Submission status: Runtime Error

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

cnt = 0
cnt_list = [0]
# インデックスの要素 = インデックスから始まる文字が"AC"
for i in range(n - 1):
    if s[i:i + 2] == "AC":
        cnt += 1
        cnt_list.append(cnt)

for start, end in ranges:
    print(cnt_list[end-1] - cnt_list[start-1])

Submission status: Runtime Error

Solution code:
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
i, c = 0, 0
while i < n:
    if s[i] == "A":
        ac[i] = c
        i += 1
        if s[i] == "C":
            c += 1
            ac[i] = c
        else: ac[i] = c
    else:
        ac[i] = c
        i += 1
print(ac)
for p in lr:
    l, r = p[0] - 1, p[1] - 1
    print(int(ac[r] - ac[l]))

Submission status: Runtime Error

Solution code:
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
for i in range(n):
    if s[i] != "A": continue
    elif s[i+1] != "C": continue
    else:
        ac[i] = 1
        ac[i+1] = 1
for p in lr:
    l, r = p[0] - 1, p[1]
    a = sum(ac[l:r])
    if s[l] == "C": a -= 1
    if s[r-1] == "A": a -= 1
    print(int(a/2))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from functools import lru_cache
N,Q = map(int,input().split())
S = list(input())
LR = [list(map(int,input().split())) for _ in range(Q)]
lis = []

@lru_cache(maxsize=None)
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        lis.append(i)
for i in range(Q):
    ans = 0
    for j in lis:
        if LR[i][0]-1 <= j and j+1 <= LR[i][1]-1:
            ans += 1
        if LR[i][1]-1<j+1:
            break
    print(ans)

Submission status: Runtime Error

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

for i in range(n):
    if s[i] == "A":
        if s[i+1] == "C":
            pos_list.append(i+1)

cnt = 0
for i in range(q):
    cnt = 0
    for pos in range(lr_list[i][0], lr_list[i][1]):
        if pos in pos_list:
            cnt += 1
    print(cnt)

Submission status: Runtime Error

Solution code:
S=input()
for i in range(Q):
    QL=list(map(int,input().split()))
    ans=0
    if "A" not in S[QL[0]-1 : QL[1]] or "C" not in S[QL[0]-1 : QL[1]] :
        pass
    else:
        for n in range(QL[1] - QL[0]) :
            if S[QL[0]-1+n] == "A" and S[QL[0]+n] =="C" :
                ans+=1
    print(ans)

Submission status: Runtime Error

Solution code:
S=input()
for i in range(Q):
    QL=list(map(int,input().split()))
    ans=0
    if "A" not in S[QL[0] : QL[1]] or "C" not in S[QL[0] : QL[1]] :
        pass
    else:
        for n in range(QL[1] - QL[0]) :
            if S[QL[0]-1+n] == "A" and S[QL[0]+n] =="C" :
                ans+=1
    print(ans)

Submission status: Runtime Error

Solution code:
N,Q= list(map(int, input().split()))
S=input()
li=[list(map(int,input().split())) for _ in range(Q)]
key=[]
i=0
for j in S:
    if j=='A':
        if S[i+1]=='C':
            key.append(i+1)
    i+=1
for i in li:
    print(len([1 for a in key if i[0]<=a and a<i[1]]))

Submission status: Runtime Error

Solution code:
n,q = map(int, input().split())
s = input()
c = []
for i in range(n+1):
  c.add(s[:i].count("AC"))
  
for i in range(q):
  l,r = map(int,input().split())
  print(c[r]-c[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())
  count = 0
  pre = s[l-1]
  for j in range(l, r):
    if pre == 'A' and s[j] == 'C':
      count += 1
    pre = s[j]
  print(cound)

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]).cound("AC")

Submission status: Runtime Error

Solution code:
N,Q = map(int, input().split())
S = input()
count = [0]*8
ans = []
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())
    ans.append(count[r-1]-count[l-1])
for i in  ans:
    print(i)

Submission status: Runtime Error

Solution code:
N,Q = map(int, input().split())
S = input()
count = [0]*8
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:
# C - GeT AC
N, Q = map(int, input().split())
S = str(input())
A = [list(map(int, input().split())) for i in range(Q)]
S1 = [0]*N
count = 0
for j in range(len(S)):
    if S[j] == 'A' and S[j + 1] == 'C':
        count = +1
        S1[j] = count
    else:
        pass
for k in range(Q):
    print(sum(S1[A[k][0]-1:A[k][1]-1]))

Submission status: Runtime Error

Solution code:
# C - GeT AC
N, Q = map(int, input().split())
S = str(input())
A = [list(map(int, input().split())) for i in range(Q)]
S1 = [0]*N
count = 0
for j in range(len(S)):
    if S[j] == 'A' and S[j + 1] == 'C':
        count = +1
        S1[j] = count
    else:
        pass
for i in range(Q):
    print(sum(S1[A[i][0]-1:A[i][1]-1]))

Submission status: Runtime Error

Solution code:
# C - GeT AC
N, Q = map(int, input().split())
S = str(input())
A = [list(map(int, input().split())) for i in range(Q)]
S1 = []

for j in range(len(S)):
    if S[j] == 'A' and S[j + 1] == 'C':
        S1.append(j+1)
    else:
        pass
print(S1)
for i in range(Q):
    count = 0
    ans = [k for k in S1 if A[i][0] <= k < A[i][1]]
    print(len(ans))

Submission status: Runtime Error

Solution code:
# C - GeT AC
N, Q = map(int, input().split())
S = str(input())
A = [list(map(int, input().split())) for i in range(Q)]
S1 = []

for j in range(len(S)):
    if S[j] == 'A' and S[j + 1] == 'C':
        S1.append(j+1)
    else:
        pass

for i in range(Q):
    count = 0
    for k in range(len(S1)):
        if A[i][0] <= S1[k] < A[i][1]:
            count += 1
        else:
            pass
    print(count)

Submission status: Runtime Error

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

L = []
R = []

for i in range(Q):
    l, r = map(int, input().split())
    L.append(l-1)
    R.append(r-1)

a = [0]*N
pre = ''

for i, s in enumerate(S):
    if pre=='A' and s=='C':
        a[i] = 1
    pre = s

cnt = 0
for i in range(Q):
    cnt = sum(a[:R[i]]) - sum(a[:L[i]])
	print(cnt)

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 += 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:
x,y = map(int,input().split())
str=input()
for i in range(y)
 a,b = map(int,input().split())
 print(str[a+1:b+1].count('AC'))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

    for l, r in lr:
        print((ruiseki[r] - ruiseki[l]))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,Q=map(int,input().split())
S=[i for i in input()]
t=[0]*(N+1)
for i in range(N):
  t[i+1]=t[i]+(1 if S[i]=='A' and S[i+1]=='C' 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()
retsu=[]
for i in range(len(s)):
  if s[i]=="A" and s[i+1]=="C":
    retsu.append(i+1)
#print(retsu)
#ここまではあってる

for i in range(q):
  temp=set(retsu)
  l,r=map(int,input().split())
  hani=set(range(l,r))
  #print(hani)
  hani&=temp

  print(len(hani))

Submission status: Runtime Error

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

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

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 temp in lr:
    l, r = temp
    print(t[r-1] - t[l-1])

Submission status: Runtime Error

Solution code:
import numpy as np
import re

def find_AC(S):
  ret = []
  for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
      ret.append(i)
  return re

N, Q = [int(x) for x in input().split()]
S = input()
result = find_AC(S)
#pos = np.array([res.start()+1 for res in result])
pos = [res.start()+1 for res in result]

for _ in range(Q):
  l, r = [int(x) for x in input().split()]
  ans = 0
  for p in pos:
    if p>=l and p<=r-1:
      ans += 1
  print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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())
    ans = ans.append(t[r-1] - t[l-1])
    
for i in range(Q):
    print(ans[i])

Submission status: Runtime Error

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

for i in range:
    l, r = map(int, input().split())
    print(S[l:r+1].count('AC'))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
r = sorted(int(input())**2 for i in range(int(input())),reverse=1)
print((sum(r[::2])-sum(r[1::2]))*3.14159265)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
r = sorted(int(input())**2 for i in range(int(input())),reverse=1)
print((sum(r[::2])-sum(r[1::2]))*3.14159265)

Submission status: Runtime Error

Solution code:
from itertools import accumulate

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

s = input()

problems = [list(map(int, input().split())) for _ in range(q)]


def count(total, i):
    return total + 1 if s[i-1] + s[i] == 'AC' else total


cumsum = [0, *accumulate(range(1, n), count)]

for l, r in problems:
    print(cumsum[r-1] - cumsum[l-1])

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    N, Q= map(int, input().split())
    S = str(input())
    L = [list(map(int, input().split())) for _ in range(Q)]
    
    nums = [0]*(N-1)
    
    for i in range(N):
        if S[i] == 'A' and S[i+1] == 'C':
            nums[i] += 1

    for i in range(1, len(nums)):
        nums[i] = nums[i] + nums[i-1]
    
    nums = [0] + nums
    
    for l, r in L:
        print(nums[r-1] - nums[l-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)]

ruisekiwa=[0]*(n+1)
for i in range(n):
    if s[i]=="A" and s[i+1]=="C":
        ruisekiwa[i+1]=ruisekiwa[i]+1
    else:
        ruisekiwa[i+1] = ruisekiwa[i]
for i in range(q):
    print(ruisekiwa[lr[i][1]-1]-ruisekiwa[lr[i][0]-1])

Submission status: Runtime Error

Solution code:
n,q = input().split("")
str = list(input())

for i in range(q):
  counter = 0
  a, b = input().split()
  for i in range(a,b):
    if 'A' in str[i]  and 'C' in str[i + 1]:
      counter += 1
    print(counter)

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
for q in range(Q):
  l, r = map(int, input(), split())
  tmp_s = S[l-1,r-1]
  i = 0
  count = 0
  while i <= len(tmp_s):
    if tmp_s[i] == 'A' and tmp_s[i+1] =='C':
      count+=1
      i += 2
    else:
      i +=1
  print(count)

Submission status: Runtime Error

Solution code:
N, Q = map(int,input().split())
S = list(input())
'''
dp[i]: 1 ~ i 番目までにacが何個あるのか　
 dp[i+1] = dp[i] (S[i]=="A" and S[i+1] == "C")
         = dp[i] (else)
'''
dp = [0 for i in range(N+10)]
for i in range(1,N+1):
    if S[i-1] == "A" and S[i] == "C" :
        dp[i] = dp[i-1] + 1
    else :
        dp[i] = dp[i-1]

for i in range(Q) :
    a,b = map(int,input().split())
    print("{}".format(dp[b-1]-dp[a-1]))

Submission status: Runtime Error

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

for i in range(1,N):
    if S[i-1:i+1]=="AC":
        C[i]+=1

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':

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

    for i in range(q):
        left,right = map(int,raw_input().split())

        for j in range(left-1,right-1):
            if s[j] == 'A' and s[j+1] == 'C':
                count += 1
        else:
            print count

Submission status: Runtime Error

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

indexes = []
for i in range(1, len(s)):
    if s[i-1] == 'A' and s[i] == 'C':
        indexes.append([i-1, i])

print('\n'.join([len([x for x in indexes if l-1 <= x[0] and x[1] <= r-1]) for l, r in lr]))

Submission status: Runtime Error

Solution code:
def input():
	return sys.stdin.readline().strip()

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

i = 0
num = 0
num_acc2 = [0]*N
for i in range(N - 1):
	if S[i:i + 2] == "AC":
		num += 1
	num_acc2[i + 1] = num

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