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:
n1, n2 = [int(i) for i in input().split()]
 
s1 = input()
 
na1 = [[0] * 2] * n2
 
for i1 in range(n2):
    na1[i1] = [int(j) for j in input().split()]
 
na2 = [0] * n2
 
f1 = False
 
for i2 in range(n1):
    if s1[i2] == "A":
        f1 = True
    elif s1[i2] == "C" and f1 == True:
        for i4 in range(len(na2)):
            if (i2) >= na1[i4][0] and (i2 + 1) <= na1[i4][1]:
                na2[i4] += 1
 
    else:
        f1 = False
 
 
for i5 in range(n2):
    print(na2[i5])
n1, n2 = [int(i) for i in input().split()]

s1 = input()

na1 = [[0] * 2] * n2

for i1 in range(n2):
    na1[i1] = [int(j) for j in input().split()]

na2 = [0] * n2

f1 = False

for i2 in range(n1):
    if s1[i2] == "A":
        f1 = True
    elif s1[i2] == "C" and f1 == True:
        for i4 in range(len(na2)):
            if (i2) >= na1[i4][0] and (i2 + 1) <= na1[i4][1]:
                na2[i4] += 1
        f1 = False

    else:
        f1 = False


for i5 in range(n2):
    print(na2[i5])

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,input().split())
s=input()
index=[]
num=0
for i in range(len(s)-1):
    if s[i:i+2]=='AC':
        index+=[[i+1,num+1]]
        num+=1
ans=[]
for i in range(q):
    l,r=map(int,input().split())
    j=0
    k=1
    while index[j][0]<l or index[k*(-1)][0]+1>r:
        if index[j][0]<l:
            j+=1
        if index[k*(-1)][0]+1>r:
            k+=1
    ans+=[index[k*(-1)][1]-index[j][1]+1]

for i in ans:
    print(i)

Submission status: Runtime Error

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

cc = []

for idx in range(len(S) - 1):
    if S[idx:idx + 2] == "AC":
        cc.append(1)
    else:
        cc.append(0)

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

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readlines()
n,q = map(int,input().split())
s = input()
l = []
r = []
cnt = []
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):
    cnt.append(s[l[i]-1:r[i]].count('AC'))
for i in range(len(cnt)):
    print(cnt[i])

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(999999999999)
input = sys.stdin.readlines()
n,q = map(int,input().split())
s = input()
l = []
r = []
cnt = []
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):
    cnt.append(s[l[i]-1:r[i]].count('AC'))
for i in range(len(cnt)):
    print(cnt[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(N):
    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())
data = input()
result = [0] * N
for i in range(N-1):
  if data[i] == "A" and data[i+1]:
    result[i+1] = result[i] + 1
  else:
    result[i+1] = result[i

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

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=list(input())
#print(s)
i=0
a=[]
x=0
while i!=n:
 #if n<10000:

    if s[i]=="C" and a1==1:
        x=x+1
        a1=0
    elif s[i]=="A":
        a1=1
    else:
        a1=0
    i=i+1
    a.append(x)

#print(a)
i=0
while i!=q:
  try:
    l,r=map(int,input().split())
    i=i+1
    s=a[r-1]-a[l-1]
    print(s)
  except:
      break

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=list(input())
#print(s)
i=0
a=[]
x=0
while i!=len(s)-1:
 #if n<10000:

    if s[i]=="C" and a1==1:
        x=x+1
        a1=0
    elif s[i]=="A":
        a1=1
    else:
        a1=0
    i=i+1
    a.append(x)

#print(a)
i=0
while i!=q:
  try:
    l,r=map(int,input().split())
    i=i+1
    s=a[r-2]-a[l-1]
    print(s)
  except:
      break

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=list(input())
#print(s)
i=0
a=[]
x=0
while i!=len(s):
 if n>=10000:

    if s[i]=="C" and a1==1:
        x=x+1
        a1=0
    elif s[i]=="A":
        a1=1
    else:
        a1=0
    i=i+1
    a.append(x)

#print(a)
i=0
while i!=q:
  try:
    l,r=map(int,input().split())
    i=i+1
    s=a[r-1]-a[l-1]
    print(s)
  except:
      break

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=list(input())
#print(s)
i=0
a=[]
x=0
while i!=len(s):
 if n>100:

    if s[i]=="C" and a1==1:
        x=x+1
        a1=0
    elif s[i]=="A":
        a1=1
    else:
        a1=0
    i=i+1
    a.append(x)

#print(a)
i=0
while i!=q:
  try:
    l,r=map(int,input().split())
    i=i+1
    s=a[r-1]-a[l-1]
    print(s)
  except:
      break

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=list(input())
#print(s)
i=0
a=[]
x=0
while i!=len(s):

    if s[i]=="C" and a1==1:
        x=x+1
        a1=0
    elif s[i]=="A":
        a1=1
    else:
        a1=0
    i=i+1
    a.append(x)

#print(a)
i=0
while i!=q:
  try:
    l,r=map(int,input().split())
    i=i+1
    s=a[r-1]-a[l-1]
    print(s)
  except:
      break

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=list(input())
#print(s)
i=0
a=[]
x=0
while i!=len(s):
    if s[i]=="C" and a1==1:
        x=x+1
        a1=0
    elif s[i]=="A":
        a1=1
    else:
        a1=0
    i=i+1
    a.append(x)
#print(a)
i=0
while i!=q:
  try:
    l,r=map(int,input().split())
    i=i+1
    s=a[r-1]-a[l-1]
    print(s)
  except:
      break

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=list(input())
#print(s)
i=0
a=[]
x=0
while i!=len(s):
    if s[i]=="C" and a1==1:
        x=x+1
        a1=0
    elif s[i]=="A":
        a1=1
    else:
        a1=0
    i=i+1
    a.append(x)
#print(a)
i=0
while i!=q:
    l,r=map(int,input().split())
    i=i+1
    s=a[r-1]-a[l-1]
    print(s)

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=list(input())
#print(s)
i=0
a=[]
while i!=len(s):
    if s[i]=="C" and a1==1:

        a.append(1)
        a1=0
    elif s[i]=="A":
        a.append(0)
        a1=1
    else:
        a1=0
        a.append(0)
    i=i+1
#print(a)
i=0
while i!=q:
    l,r=map(int,input().split())
    i=i+1
    s=a[l:r]
    #print(s)
    print(s.count(1))

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=list(input())
#print(s)
i=0
a=[]
while i!=len(s):
    if s[i]=="C" and a1==1:

        a.append(1)
    elif s[i]=="A":
        a.append(0)
        a1=1
    else:
        a1=0
        a.append(0)
    i=i+1
#print(a)
i=0
while i!=q:
    l,r=map(int,input().split())
    i=i+1
    s=a[l:r]
    #print(s)
    print(s.count(1))

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=list(input())
#print(s)
i=0
a=[]
while i!=len(s):
    if s[i]=="C" and a1==1:

        a.append(1)
    else:
        a.append(0)
    if s[i]=="A":
        a1=1
    else:
        a1=0
    i=i+1
#print(a)
i=0
while i!=q:
    l,r=map(int,input().split())
    print(a[l:r].count(1))
    i=i+1

Submission status: Runtime Error

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

cnt = [0] * 20010

for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        cnt[i] += 1

s = [0] * 20010
flag = [0] * 20010
for i in range(len(cnt) - 1):
    if cnt[i] > 0 :
        flag[i + 1] = 1
    s[i + 1] = s[i] + cnt[i]

for i in range(Q):
    l, r = map(int, input().split())
    ans = s[r] - s[l - 1]
    if flag[r] != 0 : ans -= 1
    print("{}".format(ans))

Submission status: Runtime Error

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

cnt = [0] * 10010

for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        cnt[i] += 1

s = [0] * 10010
flag = [0] * 10010
for i in range(len(cnt) - 1):
    if cnt[i] > 0 :
        flag[i + 1] = 1
    s[i + 1] = s[i] + cnt[i]

for i in range(Q):
    l, r = map(int, input().split())
    ans = s[r] - s[l - 1]
    if flag[r] != 0 : ans -= 1
    print("{}".format(ans))

Submission status: Runtime Error

Solution code:
def resolve():
    (N, Q) = list(map(int, input().split(" ")))
    S = input()
    LRs = [list(map(int, input().split(" "))) for i in range(Q)]
    mem = [S[i:i+2] == "AC" for i in range(N-1)]

    for (l, r) in LRs:
        print(mem[l-1:r-1].sum(True))

if '__main__' == __name__:
    resolve()

Submission status: Runtime Error

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

for i in range(n):
    x[i+1] = x[i] + (1 if s[i:i+2] == "AC" else 0)

for i 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()
x = []

for i in range(q):
    s1, e1 = [int(i) for i in input().split()]
    x.append(s[s1-1:e1])

for i in x:
    print(i.count("AC"))

Submission status: Runtime Error

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

flg = []

for i in range(n-1):
    tmp = s[i:i+2]
    if tmp == 'AC':
        flg.append(1)
    else:
        flg.append(0)
    
flg2 = [0] + flg
flg2 = list(accumulate(flg2))

for l in a:
    print(flg2[l[1]-1] - flg2[l[0]-1])

Submission status: Runtime Error

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

#初めに累積和を計算しておく
sum_l = [0]
i = 0
cnt = 0
while i < N:
    if (S[i] == "A") and (S[i+1] == "C"):
        cnt += 1
        sum_l.append(cnt)
    else:
        sum_l.append(cnt)
    i += 1

ans = []
for i in range(Q):
    l = sum_l[lst[i][0]-1]
    r = sum_l[lst[i][1]-1] 
    ans.append(r - l)
    
for i in ans:
    print(i)

Submission status: Runtime Error

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

#初めに累積和を計算しておく
sum_l = [0]
i = 0
while i < N:
    if (S[i] == "A") and (S[i+1] == "C"):
        sum_l.append(1)
    else:
        sum_l.append(0)
    i += 1

ans = []
for i in range(Q):
    l = lst[i][0]
    r = lst[i][1] 
    a = sum(sum_l[l:r])
    ans.append(a)
    
for i in ans:
    print(i)
    
#print(ans)
#print(lst)
#print(sum_l)

Submission status: Runtime Error

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

n,q=map(int,input().split())
s=input()
list=[0]
answerlist=[]

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


for i in range(q):
	count=0
	l,r=map(int,input().split())
	answerlist.append(sum(list[0:r])-sum(list[0:l]))


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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding: utf-8

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

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

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

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
for _ in range(Q):
  l, r = map(int, input().split())
  print(len(re.findall('AC', S[l - 1:r])))

Submission status: Runtime Error

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

L=[0]*(n+1)
R=[0]*(n+1)
ans=0
for i in range(n):
    L[i]=math.gcd(L[i-1],a[i])
for i in reversed(range(n)):
    R[i]=math.gcd(R[i-1],a[i])
for i in range(n):
    if math.gcd(L[i-1],R[i+1]) > ans:
        ans=math.gcd(L[i-1],R[i-1])

print(ans)

Submission status: Runtime Error

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

S = input()

for _ in range(N):
    l,r = map(int,input().split())	
    print(len(re.findall('AC', S[l-1:r])))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

m = []
i = 0
while i < n:
    if s[i] == 'A' and s[i+1] == 'C':
        m.append(i)
    i += 1

ans = 0
for i in range(q):
    lt, gt = l[i]-1, r[i]-1
    for j in m:
        if j >= lt:
            if j+1 <= gt:
                ans += 1

    print(ans)
    ans = 0

Submission status: Runtime Error

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

l=[]
for _ in range(Q):
    l.append(list(map(int,input().split())))

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

for j in range(len(t)):
    print(sum(t[l[j][0]:l[j][1]]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=map(int,input().split())
s=input()
l1,r1=map(int,input().split())
l2,r2=map(int,input().split())
l3,r3=map(int,input().split())

s1=s[(l1-1):r1]
s2=s[(l2-1):r2]
s3=s[(l3-1):r3]

print(s1.count("AC"))
print(s2.count("AC"))
print(s3.count("AC"))

Submission status: Runtime Error

Solution code:
#N,Q=8,3
#S="ACACTACG"
#L = [3,2,1]
#R = [7,3,8]

N,Q=map(int, input().split(" "))
S=input()
L=[]
R=[]
for _ in range(Q):
    l,r=map(int,input.split(" "))
    L.append(l)
    R.append(r)


sh=[0]
n=0
for i in range(1,N):
    if S[i-1] == "A" and S[i] == "C":
        n+=1
    sh.append(n)
for (l,r) in zip(L, R):
    print(sh[r-1]-sh[l-1])

Submission status: Runtime Error

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

for i in range(Q):
    l, r = map(int, input().split())
    query.append(S[l-1:r-1])
    
for i in range(Q):
    print(query[i].count("AC"))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,q = map(int, input().split())
s = list(input())
lr_list = [list(map(int,input().split())) for _ in range(q)]
tmp_list = [0]*(n+1)

for i in range(n):
    if s[i]=='A' and s[i+1]=='C':
        tmp_list[i+1] = tmp_list[i]+1
    else:
        tmp_list[i+1] = tmp_list[i]
        
for l,r in lr_list:
    print(tmp_list[r-1]-tmp_list[l-1])

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input().split()
rList = list()
lList = list()
for i in range(Q):
    l, r = map(int, input().split())
    lList.append(l - 1)
    rList.append(r)
def AcNum(List):
    c = 0
    for i in range(len(List) - 1):
        if List[i] == "A" and List[i + 1] == "C":
            c += 1
    return c
for i in range(N):
    print(AcNum(S[lList[i]:rList[i]]))

Submission status: Runtime Error

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

for i in range(q):
    print(s[lr[i][0] - 1:lr[i][1]])
    print(s[lr[i][0] - 1:lr[i][1]].count('AC'))

Submission status: Runtime Error

Solution code:
import time


def main():

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

    sum = [0] * (N + 100)

    for i in range(N+1):
        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])


if __name__ == '__main__':
    start = time.perf_counter()

    main()

    end = time.perf_counter()
    # print(end - start)

Submission status: Runtime Error

Solution code:
import time


def main():

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

    sum = [0] * (N + 100)

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


if __name__ == '__main__':
    start = time.perf_counter()

    main()

    end = time.perf_counter()
    # print(end - start)

Submission status: Runtime Error

Solution code:
import time


def main():

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

    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):
        print(sum[r[i]-1] - sum[l[i]-1])


if __name__ == '__main__':
    start = time.perf_counter()

    main()

    end = time.perf_counter()
    # print(end - start)

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:
import time


def main():

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


if __name__ == '__main__':
    start = time.perf_counter()

    main()

    end = time.perf_counter()
    # print(end - start)

Submission status: Runtime Error

Solution code:
import time


def main():

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

    sum = [0] * 100010

    for i in range(0, 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(0, Q):
        l, r = map(int, input().split())
        print(sum[r-1] - sum[l-1])


if __name__ == '__main__':
    start = time.perf_counter()

    main()

    end = time.perf_counter()
    # print(end - start)

Submission status: Runtime Error

Solution code:


def main():

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

    sum = [0] * 100010

    for i in range(0, 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(0, Q):
        l, r = map(int, input().split())
        print(sum[r-1] - sum[l-1])


if __name__ == '__main__':
    start = time.perf_counter()

    main()

    end = time.perf_counter()
    # print(end - start)

Submission status: Runtime Error

Solution code:
import time


def main():

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

    sum = [0]

    for i in range(0, N):
        if S[i] == 'A' and S[i+1] == 'C': sum.append(sum[i] + 1)
        else: sum.append(sum[i])

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


if __name__ == '__main__':
    start = time.perf_counter()

    main()

    end = time.perf_counter()
    # print(end - start)

Submission status: Runtime Error

Solution code:
import time


def main():

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

    sum = [0]

    for i in range(0, 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(0, Q):
        l, r = map(int, input().split())
        print(sum[r] - sum[l])


if __name__ == '__main__':
    start = time.perf_counter()

    main()

    end = time.perf_counter()
    print(end - start)

Submission status: Runtime Error

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

for _ in range(q):
  li,ri = map(int,input())
  if len(a) is 0:
    print(0)
    continue
  print(len([aa for aa in a if li<=a<ri]))

Submission status: Runtime Error

Solution code:
#入力
N ,Q = list(map(int, input().split()))
S = input()
lr_array = []
for i in range(Q):
    
    lr_array.append(list(map(int, input().split())))
#本体
patent_var = 0
ans = 0
blank_array = [0] * (N+1)
for j in range(N+2):
    if S[j:j + 2] =="AC":
        patent_var += 1
        blank_array[j+2] = patent_var
    else:
        blank_array[j+2] = patent_var

for k in range(Q):
    left = lr_array[k][0]
    right = lr_array[k][1]
    ans = blank_array[right] - blank_array[left]
    print(ans)
    ans = 0

Submission status: Runtime Error

Solution code:
#入力
N ,Q = list(map(int, input().split()))
S = input()
lr_array = []
for i in range(Q):
    
    lr_array.append(list(map(int, input().split())))
#本体
patent_var = 0
ans = 0
blank_array = [0] * (N+1)
for j in range(N):
    if S[j:j + 2] =="AC":
        patent_var += 1
        blank_array[j+2] = patent_var
    else:
        blank_array[j+2] = patent_var

for k in range(Q):
    left = lr_array[k][0]
    right = lr_array[k][1]
    ans = blank_array[right] - blank_array[left]
    print(ans)
    ans = 0

Submission status: Runtime Error

Solution code:
#入力
N ,Q = list(map(int, input().split()))
S = input()
lr_array = []
for i in range(Q):
    
    lr_array.append(list(map(int, input().split())))
#本体
patent_var = 0
ans = 0
blank_array = [0] * (N+1)
for j in range(N):
    if S[j:2] =="AC":
        patent_var += 1
        blank_array[j+2] = patent_var
    else:
        blank_array[j+2] = patent_var

for k in range(Q):
    left = lr_array[k][0]
    right = lr_array[k][1]
    ans = blank_array[right] - blank_array[left]
    print(ans)
    ans = 0

Submission status: Runtime Error

Solution code:
#入力
N ,Q = list(map(int, input().split()))
S = input()
lr_array = []
for i in range(Q):
    
    lr_array.append(list(map(int, input().split())))
#本体
patent_var = 0
ans = 0
blank_array = [0] * (N+3)
for j in range(N):
    if S[j] == "A" and S[j+1]=="C":
        patent_var += 1
        blank_array[j+2] = patent_var
    else:
        blank_array[j+2] = patent_var

for k in range(Q):
    left = lr_array[k][0]
    right = lr_array[k][1]
    ans = blank_array[right] - blank_array[left]
    print(ans)
    ans = 0

Submission status: Runtime Error

Solution code:
#入力
N ,Q = list(map(int, input().split()))
S = input()
lr_array = []
for i in range(Q):
    
    lr_array.append(list(map(int, input().split())))
#本体
patent_var = 0
ans = 0
blank_array = [0] * (N+3)
for j in range(N):
    if S[j] == "A" and S[j+1]=="C":
        patent_var += 1
        blank_array[j+2] = patent_var
    else:
        blank_array[j+2] = patent_var

for k in range(Q):
    left = lr_array[k][0]
    right = lr_array[k][1]
    ans = blank_array[right - 1] - blank_array[left]
    print(ans)
    ans = 0

Submission status: Runtime Error

Solution code:
#入力
N ,Q = list(map(int, input().split()))
S = input()
lr_array = []
for i in range(Q):
    
    lr_array.append(list(map(int, input().split())))
#本体
patent_var = 0
ans = 0
blank_array = [0] * (N+3)
for j in range(N):
    if S[j] == "A" and S[j+1]=="C":
        patent_var += 1
        blank_array[j+2] = patent_var
    else:
        blank_array[j+2] = patent_var
print(lr_array)
for k in range(Q):
    left = lr_array[k][0]
    right = lr_array[k][1]
    ans = blank_array[right] - blank_array[left]
    print(ans)
    ans = 0

Submission status: Runtime Error

Solution code:
#入力
N ,Q = list(map(int, input().split()))
S = input()
lr_array = []
for i in range(Q):
    
    lr_array.append(list(map(int, input().split())))
#本体
patent_var = 0
ans = 0
blank_array = [0] * (N+3)
for j in range(N):
    if S[j] == "A" and S[j+1]=="C":
        patent_var += 1
        blank_array[j+2] = patent_var
    else:
        blank_array[j+2] = patent_var
print(lr_array)
for k in range(Q):
    left = lr_array[k][0]
    right = lr_array[k][1]
    ans = blank_array[right -1] - blank_array[left]
    print(ans)
    ans = 0

Submission status: Runtime Error

Solution code:
#入力
N ,Q = list(map(int, input().split()))
S = input()
lr_array = []
for i in range(Q):
    
    lr_array.append(list(map(int, input().split())))
#本体
patent_var = 0
ans = 0
blank_array = [0] * (N+3)
for j in range(N):
    if S[j] == "A" and S[j+1]=="C":
        patent_var += 1
        blank_array[j+2] = patent_var
    else:
        blank_array[j+2] = patent_var

for k in range(Q):
    left = lr_array[k][0]
    
    right = lr_array[k][1]
    
    ans = blank_array[right] - blank_array[left]
    print(ans)
    ans = 0

Submission status: Runtime Error

Solution code:
#入力
N ,Q = list(map(int, input().split()))
S = input()
lr_array = []
for i in range(Q):
    
    lr_array.append(list(map(int, input().split())))
#本体
patent_var = 0
ans = 0
blank_array = [0] * (N+2)
for j in range(N):
    if S[j] == "A" and S[j+1]=="C":
        patent_var += 1
        blank_array[j+2] = patent_var
    else:
        blank_array[j+2] = patent_var

for k in range(Q):
    left = lr_array[k][0]
    
    right = lr_array[k][1]
    
    ans = blank_array[right] - blank_array[left]
    print(ans)
    ans = 0

Submission status: Runtime Error

Solution code:
#入力
N ,Q = list(map(int, input().split()))
S = input()
lr_array = []
for i in range(Q):
    
    lr_array.append(list(map(int, input().split())))
#本体
patent_var = 0
ans = 0
blank_array = [0] * (N+2)
for j in range(N):
    if S[j] == "A" and S[j+1]=="C":
        patent_var += 1
        blank_array[j+2] = patent_var
    else:
        blank_array[j+2] = patent_var
print(blank_array)
for k in range(Q):
    left = lr_array[k][0]
    
    right = lr_array[k][1]
    ans = blank_array[right+1] - blank_array[left+1]
    print(ans)
    ans = 0

Submission status: Runtime Error

Solution code:
#入力
N ,Q = list(map(int, input().split()))
S = input()
lr_array = []
for i in range(Q):
    
    lr_array.append(list(map(int, input().split())))
#本体
patent_var = 0
ans = 0
blank_array = [0] * (N+2)
for j in range(N):
    if S[j] == "A" and S[j+1]=="C":
        patent_var += 1
        blank_array[j+2] = patent_var
    else:
        blank_array[j+2] = patent_var
print(blank_array)
for k in range(Q):
    left = lr_array[k][0]
    
    right = lr_array[k][1]
    ans = blank_array[right] - blank_array[left]
    print(ans)
    ans = 0

Submission status: Runtime Error

Solution code:
#入力
import pdb; 
N ,Q = list(map(int, input().split()))
S = input()
lr_array = []
for i in range(Q):
    
    lr_array.append(list(map(int, input().split())))
#本体
patent_var = 0
ans = 0
blank_array = [0] * (N+2)
for j in range(N):
    if S[j] == "A" and S[j+1]=="C":
        patent_var += 1
        blank_array[j+2] = patent_var
    else:
        blank_array[j+2] = patent_var
print(blank_array)
for k in lr_array:
    left = k[0]
    right = k[1]
    ans = blank_array[right] - blank_array[left]
    print(ans)
    ans = 0

Submission status: Runtime Error

Solution code:
#入力
import pdb; 
N ,Q = list(map(int, input().split()))
S = input()
lr_array = []
for i in range(Q):
    
    lr_array.append(list(map(int, input().split())))
#本体
patent_var = 0
ans = 0
blank_array = [0] * (N+2)
for j in range(N):
    if S[j] == "A" and S[j+1]=="C":
        patent_var += 1
        blank_array[j+2] = patent_var
    else:
        blank_array[j+2] = patent_var
print(blank_array)
for k in lr_array:
    left = k[0]
    right = k[1]
    print(blank_array[right+1])
    print(blank_array[left+1])
    ans = blank_array[right+1] - blank_array[left]
    print(ans)
    ans = 0