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:
# -*- coding: utf-8 -*-
"""
Created on Thu Apr  4 14:43:20 2019

@author: fumito
"""

def create_sub(lr,S):
    sub = S[int(lr[0])-1:int(lr[1])]
    list = [i for i in sub]
    return list

def A_index(sub):
    A_index = [i for i,x in enumerate(sub) if x == 'A']
    return A_index

def count(sub,index):
    count = 0
    for i in index:
        if sub[i+1] == 'C':
            count += 1
        else:
            pass
    return count

if __name__ == "__main__":
    N,Q = map(int,input().split())
    S = str(input())
    lr = [input().split() for i in range(Q)]
    
    ans = []
    for i in range(Q):
        Sub = create_sub(lr[i],S)
        Index = A_index(Sub)
        Count = count(Sub,Index)
        ans.append(Count)
    for j in ans:
        print(j)
    a = create_sub([1,4],'ACAAAC')   
    b = A_index(a)

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())
ac_index = []
k = 0
while(k < n - 1):
    while(s[k] != 'A'):
        k += 1
    k += 1
    if s[k] == 'C':
        ac_index.append(k - 1)
    k += 1

for i in range(0, q):
    count = 0;
    for j in ac_index:
        if l[i] - 1 <= j <  r[i] - 1:
            count += 1
    print(count)

Submission status: Runtime Error

Solution code:
from pip._vendor.pep517.check import ansi
n, q = map(int, input().split())
s = input()
ans = []
for i in range(0, q):
    l, r = map(int, input().split())
    ans.append(s[l-1: r].replace('AC', ' ').count(' '))
for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split())
s = str(input())
a = []
b = []
for i in range(q):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

ss = []
ll = []
for i in range(n):
    c = s[a[i]:b[i]]
    d = c.count('AC')
    print(d)

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split())
s = str(input())
a = []
b = []
for i in range(q):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

ss = []
ll = []
for i in range(n):
    c = s[a[i]:b[i]]
    d = c.count('AC')
    print(len(c)-len(d))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
s = input()
m = list(map(int,input().split for i in range(q)))
count = [0]*(N+1)

for i in range(n):
    if S[i:i+2] == 'AC':
        comu[i+1] = comu[i] + 1
    else:
        comu[i+1] = comu[i]

for l,r in list:
    print(count[r-1]-count[l-1])
~

Submission status: Runtime Error

Solution code:
n,q = map(int,(input().split()))
s = input()
m = list(map(int,input().split for i in range(q)))
count = [0]*(N+1)

for i in range(n):
    if S[i:i+2] == 'AC':
        comu[i+1] = comu[i] + 1
    else:
        comu[i+1] = comu[i]

for l,r in list:
    print(count[r-1]-count[l-1])
~

Submission status: Runtime Error

Solution code:
n,q = map(int(input().split()))
s = input()
m = list(map(int,input().split for i in range(q)))
count = [0]*(N+1)

for i in range(n):
    if S[i:i+2] == 'AC':
        comu[i+1] = comu[i] + 1
    else:
        comu[i+1] = comu[i]

for l,r in list:
    print(count[r-1]-count[l-1])
~

Submission status: Runtime Error

Solution code:
import re


dd = input().strip().split(' ')
N, Q = tuple(map(int, dd))
S = input().strip()

ac_indicies = []
cp = S.find('AC')
while cp != -1:
    ac_indicies.append(cp)
    cp = S.find('AC', cp + 1)

min_i = 0
ac = ac_indicies + [N]
l_index = []
for i in range(N):
    if i > ac[min_i]:
        min_i += 1
    l_index.append(min_i)

max_i = len(ac_indicies)
ac2 = [0] + ac_indicies
r_index = []
for i in range(N-1, -1, -1):
    if i < ac[max_i]:
        max_i -= 1
    r_index.append(max_i)
   
total = len(ac_indicies)
for i in range(int(Q)):
    l, r = tuple(map(int, input().strip().split(' ')))
    print(total - l_index[l-1] - r_index[r-1])

Submission status: Runtime Error

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

n, q = map(int,input().split())
s = list(input())
l = [0] * q
r = [0] * q
for i in range(q):
    l[i],r[i] = map(int,input().split())

aclist = []

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

for i in range(q):
    print(aclist[r[i]-1] - aclist[l[i]-1])

Submission status: Runtime Error

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

ac = [0] * (N + 1)
for i in range(N):
    ac[i + 1] = ac[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(ac[r-1] - ac[l-1])

Submission status: Runtime Error

Solution code:
# 答案
N,Q = map(int,input().split())
S = input()
l,r = 0,0
csum = [0]*(N+1)

# 累積和
for ctr in range(N):
    if S[ctr]=='A' and S[ctr+1]=='C':
        csum[ctr+1] = csum[ctr] + 1
    else:
        csum[ctr+1] = csum[ctr]

# 出力
for ctr in range(Q):
    l,r=map(int,input().split())
    print(csum[r-1] - csum[l-1])

Submission status: Runtime Error

Solution code:
def main():
	n, q = map(int, input().split())
	s = input()
	acs = [0]*(n+1)
	for i in range(1, n+1):
		if s[i-1] == "A" and s[i] == "C":
			acs[i] = acs[i-1] + 1
		else:
			acs[i] = acs[i-1]
	results = [0]*q
	for i in range(q):
		l, r = map(int, input().split())
		if l == r:
			continue

		results[i] = acs[r] - acs[l]
		if s[r-1] == "A":
			results[i] -= 1
		if s[l-1] == "A" and s[l] == "C":
			results[i] += 1
	for result in results:
		print(result)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
	n, q = map(int, input().split())
	s = input()
	acs = [0]*(n+1)
	for i in range(1, n+1):
		if s[i-1] == "A" and s[i] == "C":
			acs[i] = acs[i-1] + 1
		else:
			acs[i] = acs[i-1]
	results = [0]*q
	for i in range(q):
		l, r = map(int, input().split())
		results[i] = acs[r] - acs[l]
		if s[r-1] == "A" and l != r:
			results[i] -= 1
		if s[l-1] == "A" and l != r:
			results[i] += 1
	for result in results:
		print(result)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

li_flg = [0] * len(s)

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


for idx, v in enumerate(s):
    if v == 'A':
        if idx != len(s) and s[idx + 1] == 'C':
            li_flg[idx] = 1


for l in li_lr:
    li_w = li_flg[l[0] - 1: l[1]]
    if li_w[-1] == 1:
        print(sum(li_w) - 1)
    else:
        print(sum(li_w))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random

n,q = map(int,input().split())
s = list(str(input()))
L = []
for i in range(q):
    l,r = map(int,input().split())
    L.append([l,r])

# count_ac = np.zeros([n])
count_ac = []
count = 0
i = 0
while True:
    if i>=n:
        count_ac.append(count)
        break
    if s[i] == "A" and s[i+1] == "C":
        count_ac.append(count)
        count += 1
        count_ac.append(count)
        i += 2
    else:
        count_ac.append(count)
        i += 1


# print(count_ac)
for i in range(q):
    ans = count_ac[L[i][1]-1]-count_ac[L[i][0]-1]
    print(int(ans))

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random

n,q = map(int,input().split())
s = list(str(input()))
L = []
for i in range(q):
    l,r = map(int,input().split())
    L.append([l,r])

# count_ac = np.zeros([n])
count_ac = []
count = 0
i = 0
while True:
    if i==n:
        count_ac.append(count)
        break
    if s[i] == "A" and s[i+1] == "C":
        count_ac.append(count)
        count += 1
        count_ac.append(count)
        i += 2
    else:
        count_ac.append(count)
        i += 1


# print(count_ac)
for i in range(q):
    ans = count_ac[L[i][1]-1]-count_ac[L[i][0]-1]
    print(int(ans))

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random

n,q = map(int,input().split())
s = list(str(input()))
L = []
for i in range(q):
    l,r = map(int,input().split())
    L.append([l,r])

# count_ac = np.zeros([n])
count_ac = []
count = 0
i = 0
while (i<n-1):
    if s[i] == "A" and s[i+1] == "C":
        count_ac.append(count)
        count += 1
        count_ac.append(count)
        i += 2
    else:
        count_ac.append(count)
        i += 1


for i in range(q):
    ans = count_ac[L[i][1]-1]-count_ac[L[i][0]-1]
    print(int(ans))

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random

n,q = map(int,input().split())
s = list(str(input()))
L = []
for i in range(q):
    l,r = map(int,input().split())
    L.append([l,r])

# count_ac = np.zeros([n])
count_ac = []
count = 0
i = 0
while (i<n):
    if s[i] == "A" and s[i+1] == "C":
        count_ac.append(count)
        count += 1
        count_ac.append(count)
        i += 2
    else:
        count_ac.append(count)
        i += 1


for i in range(q):
    ans = count_ac[L[i][1]-1]-count_ac[L[i][0]-1]
    print(int(ans))

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random

n,q = map(int,input().split())
s = list(str(input()))
L = []
for i in range(q):
    l,r = map(int,input().split())
    L.append([l,r])

# count_ac = np.zeros([n])
count_ac = []
count = 0
i = 0
while (i<n):
    if s[i] == "A" and s[i+1] == "C":
        count_ac.append(count)
        count += 1
        count_ac.append(count)
        i += 2
    else:
        count_ac.append(count)
        i += 1


print(count_ac)
for i in range(q):
    ans = count_ac[L[i][1]-1]-count_ac[L[i][0]-1]
    print(int(ans))

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random

n,q = map(int,input().split())
s = list(str(input()))
L = []
for i in range(q):
    l,r = map(int,input().split())
    L.append([l,r])

count_ac = np.zeros([len(s)])
for i in range(len(s)):
    if s[i]=="A" and i<len(s):
        if s[i+1]=="C":
            count_ac[i+1:] += 1

# print(count_ac)
for i in range(q):
    ans = count_ac[L[i][1]-1]-count_ac[L[i][0]-1]
    print(int(ans))

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random

n,q = map(int,input().split())
s = list(str(input()))
L = []
for i in range(q):
    l,r = map(int,input().split())
    L.append([l,r])

count_ac = np.zeros([len(s)])
for i in range(len(s)):
    if s[i]=="A" and i<len(s):
        if s[i+1]=="C":
            count_ac[i+1:] += 1

print(count_ac)
for i in range(q):
    ans = count_ac[L[i][1]-1]-count_ac[L[i][0]-1]
    print(int(ans))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
N, Q = map(int, raw_input().split())
S = raw_input()
L = np.zeros(Q)
R = np.zeros(Q)
for i in range(Q):
    L[i], R[i] = map(int, raw_input().split())
num = np.zeros(Q)
for i in range(N):
    if S[i] == "A":
        if S[i+1] == "C":
            for j in range(Q):
                if int(L[j]-1) <= i and i < int(R[j]-1):                                                            
                   num[j] += 1
for i in num:
    print int(i)

Submission status: Runtime Error

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

for i in range(n-1):
    if s[i:i+2]=='AC':
        V[i]+=1

for i in range(q):
    ans=sum(V[X[i][0]-1:X[i][1]])
    if s[X[i][1]-1]=='A' and s[X[i][1]]=='C':
        ans-=1
    print(ans)

Submission status: Runtime Error

Solution code:
input_num=list(input())
input_str=list(input())
anslen=[]
for i in range(input_num[1]):
  divpoint=list(input())
  k=''.join(input_str[divpoint[0]:divpoint[1]])
  anslen.append(k.count("AC"))
for i in range(input_num[1]):
  print(anslen[i])

Submission status: Runtime Error

Solution code:
input_num=(input().split())
input_str=input().split()
anslen=[]
for i in range(input_num[1]):
  divpoint=(input().split())
  k=''.join(input_str[divpoint[0]:divpoint[1]])
  anslen.append(k.count("AC"))
for i in range(input_num[1]):
  print(anslen[i])

Submission status: Runtime Error

Solution code:
input_num=(input().split())
input_str=input()
anslen=[]
for i in range(input_num[1]):
  divpoint=(input().split())
  k=input_str[divpoint[0]:divpoint[1]+1]
  anslen.append(k.count("AC"))
for i in range(input_num[1]):
  print(anslen[i])

Submission status: Runtime Error

Solution code:
import numpy as np

def count(s):
    prev = ""
    cnt = 0
    dp = np.zeros(len(s)+1, dtype=int)
    for i, c in enumerate(s):
        if (prev == "A") and (c == "C"):
            cnt += 1
        prev = c
        dp[i+1] = cnt
    return dp

def solve(n, q, s, l, r):
    dp = count(s)
    for i in range(q):
        print(dp[r[i]] - dp[l[i]])

n, q = map(int, input().split())
s = input()
l = np.zeros(n, dtype=int)
r = np.zeros(n, dtype=int)
for i in range(q):
    l[i], r[i] = map(int, input().split())
solve(n, q, s, l, r)

Submission status: Runtime Error

Solution code:
import numpy as np

def count(s):
    prev = ""
    cnt = 0
    dp = np.zeros(len(s)+1, dtype=int)
    for i, c in enumerate(s):
        if (prev == "A") and (c == "C"):
            cnt += 1
        prev = c
        dp[i+1] = cnt
    return dp

def solve(n, q, s, l, r):
    dp = count(s)
    for i in range(q):
        print(dp[r[i]] - dp[l[i]])

n, q = map(int, input().split())
s = input()
l = np.zeros(n, dtype=int)
r = np.zeros(n, dtype=int)
for i in range(q):
    l[i], r[i] = map(int, input().split())
print(solve(n, q, s, l, r))

Submission status: Runtime Error

Solution code:
a,b,c=int(input().split()[1]),input(),[]
for i in range(len(b)-1):c+=[i if b[i:i+2]=='AC']
for i in range(a):d=input().split();print(len([0 for j in c if(int(d[0])-2<j)*(int(d[1])-1>j)]))

Submission status: Runtime Error

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

for j in range(Q):
  ns = S[inf[j][0]-1:inf[j][1]]
  c = 0
  for h in range(len(ns)):
    if (h != len(ns)-1) and (ns[h] = "A"):
      if ns[h+1] = "C":
        c += 1
  print(c)

Submission status: Runtime Error

Solution code:
N, Q = [int(s) for s in input().split()]
S = input()

ac = []
for i in range(len(S)):
    if S[i] == 'A' and S[i+1] == 'C':
        ac.append((i + 1, i + 2))
    i += 1
# print(ac)

for i in range(Q):
    l, r = [int(s) for s in input().split()]
    ans = 0
    for a, b in ac:
        if l <= a and b <= r:
            ans += 1
    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
from collections import Counter
import collections
import numpy as np 
from scipy import sqrt, power, exp, log10
from scipy.fftpack import fft, ifft, fftfreq
import tarfile
import re
import os
import glob
from datetime import datetime
import time
import numpy.linalg as LA
 
round = lambda x:(x*2+1)//2
a,b = list(map(int,input().split()))
S = input()
sub= "AC"
for i in range(b):
    r,l = list(map(int,input().split()))
    n = S1.count(sub,r-1,l-1)
    print(n)

Submission status: Runtime Error

Solution code:
import numpy as np
from collections import Counter
import collections
import numpy as np 
from scipy import sqrt, power, exp, log10
from scipy.fftpack import fft, ifft, fftfreq
import tarfile
import re
import os
import glob
from datetime import datetime
import time
import numpy.linalg as LA

round = lambda x:(x*2+1)//2
a,b = list(map(int,input().split()))
S = input()
sub= "AC"
for i in range(b):
    r,l = list(map(int,input().split()))
	S1 = S[r-1:l]
    n = S1.count(sub)
    print(n)

Submission status: Runtime Error

Solution code:
import numpy as np
from collections import Counter
import collections
import numpy as np 
from scipy import sqrt, power, exp, log10
from scipy.fftpack import fft, ifft, fftfreq
import tarfile
import re
import os
import glob
from datetime import datetime
import time
import numpy.linalg as LA

round = lambda x:(x*2+1)//2
a,b = list(map(int,input().split()))
S = input()
sub= "AC"
for i in range(b):
    r,l = list(map(int,input().split()))
    print(S1)
    n = S1.count(sub)
    print(n)

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split())
s = input()
num = [list(map(int, input().split())) for i in range(q)]
arr = [0]
tmp = 0
for i in range(n):
    if s[i] == 'A' and s[i + 1] == 'C':
        tmp += 1
    arr.append(tmp)

for left, right in num:
    ans = arr[right - 1] - arr[left - 1]
    print(ans)

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split())
s = input()
num = [list(map(int, input().split())) for i in range(q)]
arr = [0]
tmp = 0
for i in range(n):
    arr.append(tmp)
    if s[i] == 'A' and s[i + 1] == 'C':
        tmp += 1

for left, right in num:
    ans = arr[right] - arr[left]
    print(ans)

Submission status: Runtime Error

Solution code:
class Test:
    def __init__(self):
        pass
 
class CustomUtils:
    def __init__(self):
        pass
    def to_int(self, inputs, sp=' '):
        if sp == '':
            return [int(d) for d in list(inputs)]
        else:
            return [int(d) for d in inputs.split(sp)]
    def debug_print(self, inputs, debug=False):
        if debug:
            print(inputs)
 
# 引用　python する man,「Pythonでの再帰関数とメモ化」, PSM, ２０１７、７/４
# http://muromura.hatenablog.com/entry/2017/07/04/204908#%E3%83%A1%E3%83%A2%E5%8C%96
def memorize(f):
    table = {}
    def func(*args):
        if not args in table:
            table[args] = f(*args)
        return table[args]
    return func
debug = False
 
 
 
# REVIEW:
# re
# 文字列の先頭がパターンにマッチするかを調べるmatch()
# 先頭に限らずパターンにマッチするかを調べるsearch()
# マッチする部分すべてをリストで返すfindall()
# マッチする部分すべてをイテレータで返すfinditer()
# マッチした部分を置換するsub()、subn()
# パターンで文字列を分割するsplit()
# 正規表現オブジェクトをコンパイルするcompile()
 
 
u = CustomUtils()
 
n, q = u.to_int(input())
s = input()
 
import re
 
for _ in range(q):
    l, r = u.to_int(input())
#     文字列をreで
    result = len(re.findall('AC', s[l-1:r]))
    print("{}".format(result))
class Test:
    def __init__(self):
        pass

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

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



# REVIEW:
# re
# 文字列の先頭がパターンにマッチするかを調べるmatch()
# 先頭に限らずパターンにマッチするかを調べるsearch()
# マッチする部分すべてをリストで返すfindall()
# マッチする部分すべてをイテレータで返すfinditer()
# マッチした部分を置換するsub()、subn()
# パターンで文字列を分割するsplit()
# 正規表現オブジェクトをコンパイルするcompile()


u = CustomUtils()

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

import re

for _ in range(q):
    l, r = u.to_int(input())
#     文字列をreで
    result = len(re.findall('AC', s[l-1:r]))
    print("{}".format(result))

Submission status: Runtime Error

Solution code:
class Test:
    def __init__(self):
        pass
 
class CustomUtils:
    def __init__(self):
        pass
    def to_int(self, inputs, sp=' '):
        if sp == '':
            return [int(d) for d in list(inputs)]
        else:
            return [int(d) for d in inputs.split(sp)]
    def debug_print(self, inputs, debug=False):
        if debug:
            print(inputs)
 
# 引用　python する man,「Pythonでの再帰関数とメモ化」, PSM, ２０１７、７/４
# http://muromura.hatenablog.com/entry/2017/07/04/204908#%E3%83%A1%E3%83%A2%E5%8C%96
def memorize(f):
    table = {}
    def func(*args):
        if not args in table:
            table[args] = f(*args)
        return table[args]
    return func
debug = False
 
 
 
# REVIEW:
# re
# 文字列の先頭がパターンにマッチするかを調べるmatch()
# 先頭に限らずパターンにマッチするかを調べるsearch()
# マッチする部分すべてをリストで返すfindall()
# マッチする部分すべてをイテレータで返すfinditer()
# マッチした部分を置換するsub()、subn()
# パターンで文字列を分割するsplit()
# 正規表現オブジェクトをコンパイルするcompile()
 
 
u = CustomUtils()
 
n, q = u.to_int(input())
s = input()
 
import re
 
for _ in range(q):
    l, r = u.to_int(input())
#     文字列をreで
    result = len(re.findall('AC', s[l-1:r], re.IGNORECASE))
    print("{}".format(result))
class Test:
    def __init__(self):
        pass

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

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



# REVIEW:
# re
# 文字列の先頭がパターンにマッチするかを調べるmatch()
# 先頭に限らずパターンにマッチするかを調べるsearch()
# マッチする部分すべてをリストで返すfindall()
# マッチする部分すべてをイテレータで返すfinditer()
# マッチした部分を置換するsub()、subn()
# パターンで文字列を分割するsplit()
# 正規表現オブジェクトをコンパイルするcompile()


u = CustomUtils()

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

import re

for _ in range(q):
    l, r = u.to_int(input())
#     文字列をreで
    result = len(re.findall('AC', s[l-1:r]))
    print("{}".format(result))

Submission status: Runtime Error

Solution code:
AC = 'AC'
Q, N = map(int, input().split())
S = str(input())
ans = []
for n in range(N):
    l,r = map(int, input().split())
    l = l - 1
    QS = S[l:r]
    c = re.findall(AC, QS)
    ans.append(str(len(c)))
print(' '.join(ans))

Submission status: Runtime Error

Solution code:
AC = 'AC'
Q, N = map(int, input().split())
S = str(input())
ans = []
for n in range(N):
    l,r = map(int, input().split())
    l = l - 1
    QS = S[l:r]
    c = re.findall(AC, QS)
    ans.append(len(c))
print(' '.join(a))

Submission status: Runtime Error

Solution code:
AC = 'AC'
Q, N = map(int, input().split())
S = str(input())
ans = []
for n in range(N):
    l,r = map(int, input().split())
    l = l - 1
    QS = S[l:r]
    c = re.findall(AC, QS)
    ans.append(len(c))
print(' ',join(a))

Submission status: Runtime Error

Solution code:
AC = 'AC'
Q, N = map(int, input().split())
S = str(input())
ans = []
for n in range(N):
    l,r = map(int, input().split())
    l = l - 1
    QS = S[l:r]
    c = re.findall(AC, QS)
    ans.append(len(c))
for a in ans:
    print(a)

Submission status: Runtime Error

Solution code:
n,q = [int(i) for i in input().split()]
s = input()
ac_loc = []
for i in range(n):
  if s[i] =='A':
    if s[i+1] == 'C':
      ac_loc.append(i)
      i+=1 

for i in range(q):
  l, r = [int(j) for j in input().split()]
  l -= 1
  r -= 1
  ans = sum((l<=j and j+1<=r) for j in ac_loc)
  print(ans)

Submission status: Runtime Error

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

b, t = 0, [0]*N
for i in range(1, N):
  if S[i-1:i+1] == 'AC':
    t[i] += 1
  else: t[i] = t[i-1]

for i in range(Q):
  print(t[lr[i][1]] - t[lr[i][0]])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N=int(input());
Q=int(input());
s = input();
charList=list(s);
AClist=[0]*N;

for i in range(N-1):
 if charList[i]=='A' and charList[i+1]=='C':
  AClist[i+1]=AClist[i]+1;
 else:
  AClist[i+1]=AClist[i];

result=[0]*Q;
for i in range(Q):
 l, r = map(int, input().split())
 result[i]=AClist[r-1]-AClist[l];
 if result[i]<0:
  result[i]=0;
for i in range(Q):
 print(result[i]);

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
s = list(input())
cum = [0 for i in range(n+1)]
i = 0
while i < n:
    if s[i] == "A" and s[i+1] == "C":
        cum[i+1] = cum[i]
        cum[i+2] = 1+cum[i+1]
        i += 2
    else:
        cum[i+1] = cum[i]
        i += 1

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

Submission status: Runtime Error

Solution code:
import sys
from itertools import accumulate

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

t = [0] * N

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

T = list(accumulate(t))
 
for i in lr:
    print(T[i[1]] - T[i[0]])

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
S = input()
d = [0] * n
for i in range(n - 1):
        if S[i]+S[i + 1] == 'AC':
                d += 1
for i in range(q):
        r,l = map(int,input().split())
        su = 0
        for j in range(r-1,l):
                su += d[j]
        print(su-d[r-1])

Submission status: Runtime Error

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


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

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

Submission status: Runtime Error

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


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

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

Submission status: Runtime Error

Solution code:
N,Q = list(map(int, input().split()))
S = str(input())
lr=[]
for i in range(Q):
    lr.append(list(map(int, input().split())))
 
import numpy as np
 
count=np.array([0 for i in range(N)])
for i in range(N-1):
    if S[i]=="A" and S[i+1]=="C":
        count[i+1:]+=1
 
for i,j in lr:
    print(count[j-1]-count[i-1])

Submission status: Runtime Error

Solution code:
n, q = list(map(int, input().split()))
s = input()
tmp = "g"
acc = []
for c in s:
  if tmp = "A":
    if c == "C":
      acc.append(acc[-1] + 1)
      tmp = "G"
    elif c == "A":
      tmp = "A"
    else;
		tmp = "G"
  else:
    if c == "A":
      tmp = "A"
      
for i in range(q):
  l,r = list(map(int, input().split()))
  print(acc[r-1] - acc[l-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

int N,Q;
string S;

// dp[i+1]: i文字目までの「ACのA」個数
vector<int> dp;

int main()
{
  cin >> N >> Q;
  cin >> S;

  dp.resize(N+1,0);
  dp[0] = 0;
  REP(i,0,N) {
    // i文字目まで
    if (S.substr(i,2) == "AC") {
      dp[i+1] = dp[i] + 1;
    } else {
      dp[i+1] = dp[i];
    }
  }

  REP(i,0,Q) {
    int l,r;
    cin >> l >> r;
    --l; --r;
    // 添字ずれ
    cout << dp[r] - dp[l] << endl;
  }

  return 0;
}

Submission status: Runtime Error

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

for i in range(Q):
    lq,rq = map(int,input().split())
    s = S[lq-1:rq]
    count = 0
    while(s.find('A') != -1):
        j = s.find('A')
        if(s[j+1] == 'C'):
            count+=1
            s = s[j+2:]
        else:
            s = s[j+1:]
    print(count)