Problem:


Score : 300 points

Problem Statement

You are given a string S of length N consisting of A, C, G and T. Answer the following Q queries:

Query i (1 \leq i \leq Q): You will be given integers l_i and r_i (1 \leq l_i < r_i \leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does AC occurs as a substring?

Notes

A substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.

For example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and  (the empty string), but not AC.

Constraints

2 \leq N \leq 10^5

1 \leq Q \leq 10^5

S is a string of length N.

Each character in S is A, C, G or T.

1 \leq l_i < r_i \leq N

Input

Input is given from Standard Input in the following format:

N Q
S
l_1 r_1
:
l_Q r_Q

Output

Print Q lines. The i-th line should contain the answer to the i-th query.

Sample Input 1

8 3
ACACTACG
3 7
2 3
1 8

Sample Output 1

2
0
3

Query 1: the substring of S starting at index 3 and ending at index 7 is ACTAC. In this string, AC occurs twice as a substring.

Query 2: the substring of S starting at index 2 and ending at index 3 is CA. In this string, AC occurs zero times as a substring.

Query 3: the substring of S starting at index 1 and ending at index 8 is ACACTACG. In this string, AC occurs three times as a substring.



Sample input:
8 3
ACACTACG
3 7
2 3
1 8


Sample output:
2
0
3

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from __future__ import print_function
import sys
import numpy as np

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

N,Q = map(int,input().split())  # Nは文字列Sの長さ．Qは質問の個数．
S = input()
S=S+"0"

cnt=np.zeros(100000)
now_x=0
for i in range(1,N+1):
    if S[i-1]=='A' and S[i]=='C':
        cnt[i]=now_x+1
        now_x=cnt[i]
    else:
        cnt[i]=now_x

for i in range(Q):
    left,right=map(int,input().split())
    left-=1
    right-=1
    print(cnt[right]-cnt[left])
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #
    #

Submission status: Runtime Error

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

answers = []

for i in range(Q):
    l, r = map(int, input().split())
    l -= 1
    r -= 2
    
    low = 0
    high = len(position)
    t = (low + high)//2
   
    while low<=high:
        
        if l == position[t]:
            break
        elif l > position[t]:
            if l < position[t-1]:
                break
            else:
                low = t + 1
        elif l < position[t]:
            high = t - 1
        
        tmp = (low + high) // 2
        if 0 <= tmp <= len(position) - 1:
            t = tmp
        else:
            break
    
     
    low = 0
    high = len(position)
    s = (low + high)//2
    while low<=high:
       
        if r == position[s]:
            break
        elif r > position[s]:
            low = s + 1
        elif r < position[s]:
            if r > position[s+1]:
                break
            else:
                high = s - 1
        tmp = (low + high) // 2
        if 0 <= tmp <= len(position) - 1:
            s = tmp
        else:
            break
    
    answer = s - t + 1
    if s == t:
        if not l <= position[s] <= r:
            answer = 0
    
        
    answers.append(answer)
    
for x in answers:
    print(x)

Submission status: Runtime Error

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

for cnt in range(q):
  l, r = list(map(int , input()))
  print(s[l-1:r].count('AC'))

Submission status: Runtime Error

Solution code:
# coding: utf-8

n,q =map(int,input().split())
l = input()
Count = [0] * q

for i in range(q):
    a, b = map(int, input().split())
    enki_hairetu = l[a-1:b]
    Count[q] = enki_hairetu.count("AC")

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

Submission status: Runtime Error

Solution code:
import re
 
a = []
for i in range(5):
    a.append(input().split())
n = int(a[0][0])
q = int(a[0][1])
str = a[1][0]
b = a[2:]
for i in b:
  l = int(i[0])
  r = int(i[1])
  sub_str = str[(l-1):r]
  print(len(re.findall('AC', sub_str)))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import re

a = []
for i in range(5):
    a.append(input().split())
n = int(a[0][0])
q = int(a[0][1])
str = a[1][0]
b = a[2:]
for i in b:
  l = int(i[0])
  r = int(i[1])
  sub_str = str[(l-1):r]
  print(len(re.findall('AC', sub_str)))

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
s = input()
t = [0] * (n + 1)
for i in range(q):
  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()
t = [0] * (n + 1)
for i in range(q):
  t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)
for i in range(q):
  l,r = map(int,input().split())
  print(t[r-1] - t[l-1])

Submission status: Runtime Error

Solution code:
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]

ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]

i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())

ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]

def main(N, Q, S, lrs):
    S2 = [0] * (N+1)
    for i in range(N):
        if S[i] == 'A' and S[i+1] == 'C':
            S2[i+1] = S2[i] + 1
        else:
            S2[i+1] = S2[i]
    for l, r in lrs:
        count = S2[r-1] - S2[l-1] 
        print(count)

N, Q = i2nn()
S = i2s()
lr = ss2nnn(ii2ss(Q))
main(N, Q, S, lr)

Submission status: Runtime Error

Solution code:
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]

ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]

i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())

ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]

def main(N, Q, S, lrs):
    S2 = [0] * (N+1)
    for i in range(N):
        if S[i] == 'A' and S[i+1] == 'C':
            S2[i+1] = S2[i] + 1
        else:
            S2[i+1] = S2[i]
    print(S2)
    for l, r in lrs:
        count = S2[r-1] - S2[l-1] 
        print(count)

N, Q = i2nn()
S = i2s()
lr = ss2nnn(ii2ss(Q))
main(N, Q, S, lr)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import re

N, Q = map(int, input().split())
S = input()
count = 0
for i in range(Q):
    l, r = map(int, input().split())
    for j in range(l - 1, r):
        if S[j] == "A" and S[j + 1] == "C" and j + 1 < r:
            count += 1
    print(count)
    count = 0

Submission status: Runtime Error

Solution code:
8 3
ACACTACG
3 7
2 3
1 8

Submission status: Runtime Error

Solution code:
import re

n,q=map(int,input().split())
s=str(input())
ans = 0
for _ in range(q):
  l,r=map(int,input().split())
  for i in re.finditer('AC', s[l-1:r])
  	ans += 1
  print(ans)

Submission status: Runtime Error

Solution code:
a = list(map(int, input().split()))
b = input()

for i in range(3):
  c = list(map(int, input().split()))
  d = 0
  for j in range(c[0], c[1]):
    if(b[j] == "A" and b[j+1] == "C"):
      d += 1
  print(d)

Submission status: Runtime Error

Solution code:
NQ = input()
N = int(NQ[0])
Q = int(NQ[2])
string_list= input()
lr_list = [input().split() for j in range(3)]
 
for i in range(Q):
  count = 0
  for j in range(int(lr_list[i][0]), min(int(lr_list[i][1]), N)):
    if string_list[j-1] == "A":
      if (string_list[j] == "C") and (j != int(lr_list[i][1])):
        count += 1
  print("%d"%count)

Submission status: Runtime Error

Solution code:
NQ = input()
N = int(NQ[0])
Q = int(NQ[2])
string_list= input()
lr_list = [input().split() for j in range(3)]
 
for i in range(Q):
  count = 0
  for j in range(int(lr_list[i][0]), min(int(lr_list[i][1]), N-1)):
    if string_list[j-1] == "A":
      if (string_list[j] == "C") and (j != int(lr_list[i][1])):
        count += 1
  print("%d"%count)

Submission status: Runtime Error

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

s = []
List = [i for i, x in enumerate(S) if x == 'A' and S[i + 1] == 'C']

for i in range(Q):
    ans = 0
    for j in range(len(List)):
        if (List[j] in range(lr[i][0] - 1, lr[i][1])) and ((List[j] + 1) in range(lr[i][0] - 1, lr[i][1])):
            ans += 1
    print(ans)

Submission status: Runtime Error

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

s = []
for i in range(Q):
    s.append(S[(lr[i][0] - 1) : lr[i][1]])
for i in range(Q):
    print(s[i].count('AC'))

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
s = input()
num = []
for Q in range(q):
	l,r = map(int,input().split())
	num.append(int(s[l - 1:r].count('AC')))
print('/n'.join(num))

Submission status: Runtime Error

Solution code:
NQ = input()
N = int(NQ[0])
Q = int(NQ[2])
string_list= input()
lr_list = [input().split() for j in range(3)]
 
for i in range(Q):
  count = 0
  for j in range(int(lr_list[i][0]), min(int(lr_list[i][1]), N)):
    if string_list[j-1] == "A":
      if j < N:
      	if (string_list[j] == "C"):
        	count += 1
  print("%d"%count)

Submission status: Runtime Error

Solution code:
NQ = input()
N = int(NQ[0])
Q = int(NQ[2])
string_list= input()
lr_list = [input().split() for j in range(3)]
 
for i in range(Q):
  count = 0
  for j in range(int(lr_list[i][0]), int(lr_list[i][1])):
    if string_list[j-1] == "A":
      if (string_list[j] == "C") and (j != int(lr_list[i][1])):
        count += 1
  print("%d"%count)

Submission status: Runtime Error

Solution code:
NQ = input()
N = int(NQ[0])
Q = int(NQ[2])
string_list= input()
lr_list = [input().split() for j in range(3)]

for i in range(Q):
  count = 0
  for j in range(int(lr_list[i][0]), int(lr_list[i][1])):
    if string_list[j-1] == "A":
      if (string_list[j] == "C") and (j != int(lr_list[i][1])-1):
        count += 1
  print("%d"%count)

Submission status: Runtime Error

Solution code:
NQ = input()
N = int(NQ[0])
Q = int(NQ[2])
string_list= input()
lr_list = [input().split() for j in range(3)]

for i in range(Q):
  count = 0
  for j in range(int(lr_list[i][0]), int(lr_list[i][1])):
    if string_list[j-1] == "A":
      if string_list[j] == "C":
        count += 1
  print("%d"%count)

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split())
S = input()
 
counts = [0 for i in range(n)]
cnt = 0
 
for i in range(n):
  if (S[i-1:i+1] == "AC":)
    cnt += 1
    counts[i] = cnt
    
for i in range(q):
    l, r = map(int, input().split())
    print(counts[r-1] - counts[l-1])

Submission status: Runtime Error

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

counts = [0 for i in range(N)]
cnt = 0

for i in range(n):
  if S[i-1:i+1] == "AC":
    cnt += 1
    counts[i] = cnt
    
for i in range(q):
  l, r = map(int, input().split())
  print (counts[r-1] - counts[l-1])

Submission status: Runtime Error

Solution code:
N,Q=map(int,(input()).split())
S=input()
l_list=[]
r_list=[]
for i in range(Q):
  l,r=input().split()
  l_list.append(int(l))
  r_list.append(int(r))
count=0
AC_count=[]
for i in range(1,N):
  if S[i-1:i+1]=="AC":
    count+=1
  AC_count.append(count)
k=0
for j in range(Q):
  k=AC_count[r_list[j]-1]-AC_count[l_list[j]-1]
  print(k)

Submission status: Runtime Error

Solution code:
N,Q=map(int,(input()).split())
S=input()
l_list=[]
r_list=[]
for i in range(Q):
  l,r=input().split()
  l_list.append(int(l))
  r_list.append(int(r))
for i in range(Q):
  S_i=S[int(l_list[i])-1,int(r_list[i])]
  n=0
  while "AC" in S_i:
    n+=1
  print(n)

Submission status: Runtime Error

Solution code:
N,Q=map(int,(input()).split())
S=input()
l_list=[]
r_list=[]
for i in range(Q):
  l,r=input().split()
  l_list.append(int(l))
  r_list.append(int(r))
for i in range(Q):
  S_i=S[l_list[i]-1,r_list[i]]
  n=0
  while "AC" in S_i:
    n+=1
  print(n)

Submission status: Runtime Error

Solution code:
N,Q=int(input()).split()
S=input()
l_list=[]
r_list=[]
for i in range(Q):
  l,r=int(input()).split()
  l_list.append(l)
  r_list.append(r)
for i in range(Q):
  S_i=S[l_list[i]-1,r_list[i]]
  n=0
  while "AC" in S_i:
    n+=1
  print(n)

Submission status: Runtime Error

Solution code:
S = input()
import re
def appear(i, j)
 T = S[i:j+1]
 T.count('AC')

Submission status: Runtime Error

Solution code:
from sys import stdin
n, q = stdin.readline().split()
s = stdin.readline().strip()
count = 0
for i in range(q):
  l, r = map(int, stdin.readline().split())
  for j in range(l-1, r-1):
    if s[j] + s[j+1] == 'AC':
      count += 1
      
  print(count)

Submission status: Runtime Error

Solution code:
n, q = map(input().split())
s = input()
for _ in range(q):
  l, r = map(input().split())
  print(s[l:r].count('AC'))

Submission status: Runtime Error

Solution code:
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
for j, temp in enumerate(a):
    str_sub = string[temp[0]-1:temp[1]]
    try:
        print(test_dict[str_sub])
    except:
        test_dict[str_sub] = str_sub.count('AC')
        print(test_dict[str_sub])
    #print(test_dict[str_sub])

Submission status: Runtime Error

Solution code:
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))

Submission status: Runtime Error

Solution code:
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
for j, temp in enumerate(a):
    #print(temp)
    str_sub = string[temp[0]-1:temp[1]]
    if j == 0:
        test_dict[str_sub] = str_sub.count('AC')
        result = str(test_dict[str_sub])
    if test_dict.get(str_sub):
        #print(test_dict.get(str_sub))
        result += '\n' + str(test_dict.get(str_sub))
        continue
    test_dict[str_sub] = str_sub.count('AC')
    result += '\n' + str(test_dict[str_sub])
    #print(test_dict[str_sub])

Submission status: Runtime Error

Solution code:
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
result = ''
for temp in a:
    try:
        result += '\n' + str(test_dict[string[temp[0]-1:temp[1]]])
    except:
        test_dict[string[temp[0]-1:temp[1]]] = string[temp[0]-1:temp[1]].count('AC')
        result += '\n' + str(test_dict[string[temp[0]-1:temp[1]]])
print(result.lstrip())

Submission status: Runtime Error

Solution code:
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
result = ''
for temp in a:
    if test_dict.get(string[temp[0]-1:temp[1]]):
        result += '\n' + str(test_dict.get(string[temp[0]-1:temp[1]]))
        continue
    test_dict[string[temp[0]-1:temp[1]]] = string[temp[0]-1:temp[1]].count('AC')
    result += '\n' + str(test_dict[string[temp[0]-1:temp[1]]])
print(result.lstrip())

Submission status: Runtime Error

Solution code:
test_dict = {}
result = ''
for temp in a:
    try:
        result += '\n' + str(test_dict[string[temp[0]-1:temp[1]]])
    except:
        test_dict[string[temp[0]-1:temp[1]]] = string[temp[0]-1:temp[1]].count('AC')
        result += '\n' + str(test_dict[string[temp[0]-1:temp[1]]])
print(result.lstrip())

Submission status: Runtime Error

Solution code:
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
result = ''
for temp in a:
    if test_dict.get(string[temp[0]-1:temp[1]]):
        result += '\n' + str(test_dict.get(string[temp[0]-1:temp[1]]))
        continue
    test_dict[string[temp[0]-1:temp[1]]] = string[temp[0]-1:temp[1]].count('AC')
    result += '\n' + str(test_dict[string[temp[0]-1:temp[1]]])
print(result.lstrip)

Submission status: Runtime Error

Solution code:
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
result = ''
for temp in a:
    if test_dict.get(string[temp[0]-1:temp[1]]):
        result += '\n' + str(test_dict.get(string[temp[0]-1:temp[1]]))
        continue
    test_dict[string[temp[0]-1:temp[1]]] = string[temp[0]-1:temp[1]].count('AC')
    result += '\n' + str(test_dict[string[temp[0]-1:temp[1]]])
print(result)

Submission status: Runtime Error

Solution code:
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
result = ''
for temp in a:
    if test_dict.get(string[temp[0]-1:temp[1]]):
        result += '\n' + str(test_dict.get(string[temp[0]-1:temp[1]]))
        continue
    test_dict[string[temp[0]-1:temp[1]]] = string[temp[0]-1:temp[1]].count('AC')
    result += '\n' + str(test_dict[string[temp[0]-1:temp[1]]])

Submission status: Runtime Error

Solution code:
# dict形式で既出分をもたせる
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
test_dict = {}
test_dict = {}
result = ''
for temp in a:
    if test_dict.get(string[temp[0]-1:temp[1]]):
        result += str(test_dict.get(string[temp[0]-1:temp[1]]))
        continue
    test_dict[string[temp[0]-1:temp[1]]] = string[temp[0]-1:temp[1]].count('AC')
    result += str(test_dict[string[temp[0]-1:temp[1]]])

Submission status: Runtime Error

Solution code:
import re
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],re.S)))

Submission status: Runtime Error

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

for count in range(3):
    l, r = map(int, input().split())
    ans = 0
    count = 0

    for i in S[l-1: r]:
        if i =="A" or i == "T":    
            count += 1
        else:
            ans = max(count, ans)
            count = 0
    ans = max(count, ans)
    print(ans)

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
t=[0]*n
for i in range(n):
  t[i+1]=t[i]+(1 if s[i:i+2]=='AC' else 0)
for j 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()
t = [0] * (n + 1)
nl = set(range(nl))
for i in nl:
    t[i + 1] = t[i] + (1 if s[i:i + 2] == 'AC' else 0)
ql = set(range(q))
for i in ql:
    l1, l2 = map(int, input().split())
    ans = t[l2-1] - t[l1-1]
    print(ans)

Submission status: Runtime Error

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

S_count = []
count = 0
A_flag = False

for i in range(len(S)):
    if A_flag == True:
        if S[i] == "C" :
            count += 1
    else:
        if S[i] == "A" :
            A_flag = True
        else:
            A_flag = False
    S_count.append(count)

for i in range(Q):
    print(S_count[R[i]] - S_count[L[i]])

Submission status: Runtime Error

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

S_count = []
count = 0
A_flag = False

for i in range(len(S)):
    if A_flag == True:
        if S[i] == "C" :
            count += 1
    else:
        if S[i] == "A" :
            A_flag = True
        else:
            A_flag = False
    S_count = count

for i in range(Q):
    print(S_count[R[i]] - S_count[L[i]])

Submission status: Runtime Error

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

S_count = []
count = 0
A_flag = False

for i in range(len(S)):
    if A_flag == True:
        if S[i] == "C" :
            count += 1
    else:
        if S[i] == "A" :
            A_flag = True
        else:
            A_flag = False
    S_count = count

for i in range(Q):
    print(S[R[i]] - S[L[i]])

Submission status: Runtime Error

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

ixs = []
for i in range(int(q)):
    start, end = list(map(int, input().split(" ")))
    ixs.append([start-1, end-1])

cnts = [0 for i in range(int(n))]
for i in range(int(n)):
    if s[i] =="A":
        if s[i+1] == "C":
            cnts[i]=1

for start, end in ixs:
    print(cnts)
    print(sum(cnts[start:end]))

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
L, R = [None] * N, [None] * N

S = input()

for i in range(Q):
    L[i], R[i] = map(int, input().split())


counts = [0] * N
count_tmp = 0

for i in range(1, N):
    if S[i-1] == 'A' and S[i] == 'C':
        count_tmp += 1
    counts[i] = count_tmp

# print(counts)

for i in range(Q):
    print(counts[R[i] - 1] - counts[L[i] - 1])

Submission status: Runtime Error

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces


li = []
n = int(input())
for i in range(5):
    li.append(int(input()))
if n <= min(li):
    print(5)
else:
    if n % min(li) == 0:
        print(5 + n // min(li) -1)
    else:
        print(5 + n // min(li))

Submission status: Runtime Error

Solution code:
li = []
n = int(input())
for i in range(5):
    li.append(int(input()))
print(5 + n // min(li))

Submission status: Runtime Error

Solution code:
import re

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

Submission status: Runtime Error

Solution code:
import re

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

Submission status: Runtime Error

Solution code:
ls,n = [int(i) for i in input().split(' ')]
s = input()
count = 0
for i in range(n):
    l,r = [int(i) for i in input().split(' ')]
    st = s[l-1:r]
    for x in range(len(st)):
        print(st)
        try: 
            if st[x]+st[x+1] == "AC":
                count += 1
        except:
            pass
    print(count)
    count = 0

Submission status: Runtime Error

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


def fnc(l,r):
    cnt = 0
    for i in range(l-1,r):
        if S[i] == "A" and S[i+1] == "C" and i != r-1:
            cnt += 1
    print(cnt)
    
for i in range(Q):
    L,R = map(int,input().split())
    fnc(L,R)

Submission status: Runtime Error

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

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

A=[]

for i in range(q):
    l,r=map(int,input().split())
    ans=(X[l-1:r]).count(1)
    if s[r-1]=='A' and s[r]=='C':
        A.append(ans-1)
    else:
        A.append(ans)
        
for x in A:
    print(x)

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
L = list(input())
count, num = 0, 0
for i in range(Q):
  l, r = map(int, input().split())
  S = L[l-1:r]
  while True:
    if S[num] == 'A' and i < len(S)-1:
      if S[num+1] == 'C':
        count += 1
        num += 1
    if num >= len(S)-1:
      break
    num += 1
  print(count)
  count, num  = 0, 0

Submission status: Runtime Error

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

atgc_list= []

flag = 0
memo =0

for i in range (len(S)):
    if S[i]=='A':
        flag = 1
    elif flag == 1 and S[i] == 'C':
        memo+=1
    elif S[i] in ['T','G','C']:
        flag = 0
    atgc_list.append(memo)
        
atgc_list_np = np.array(atgc_list)

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

Submission status: Runtime Error

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

atgc_list= []

flag = 0
memo =0

for i in range (len(S)):
    if S[i]=='A':
        flag = 1
    if flag == 1 and S[i] == 'C':
        memo+=1
    if S[i] in ['T','G']:
        flag = 0
    atgc_list.append(memo)
        
atgc_list_np = np.array(atgc_list)

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

Submission status: Runtime Error

Solution code:
n,q = (int(x) for x in input().split())
s = str(input())
ans = []
for i in range(q):
  ans.insert(i, 0)
  l,r = (int(x) for x in input().split())
  ss = s[l:r]
  for j in range(len(ss)):
    if ss[j] == "A" and ss[j+1] == "C":
      ans[i] = ans[i] + 1
for i in range(q):
  print("{}".format(ans[i]))

Submission status: Runtime Error

Solution code:
n,q = int(input().split())
s = str(input())
ans = []
for i in range(q):
  ans[i] = 0
  l,r = int(input().split())
  ss = s[l:r]
  ll = len(ss) - 1
  for j in range(ll):
    if ss[j] == "A" and ss[j+1] == "C":
      ans[i] = ans[i] + 1
for i in range(q):
  print("{}".format(ans[i]))

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split(' '))
s = input()
A = []
for _ in range(q):
  A.append(list(map(int, input().split(' '))))
ac = [0]*n  # AC index search
for i in range(n):
  if sub[i:i+2] == 'AC':
    ac[i] = 1

for l,r in A:
  ans = sum(ac[l-1:r])
  if ac[l-1:r][-1] == 1:
    ans -= 1
  print(ans)

Submission status: Runtime Error

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

list1 = []

for i in range(Q):
    l,r = map(int,input().split())
    l = l - 1
    w_string = S[l:r]
    for j in w_string:
        if 'AC' in s[j:j+1]:
            count = count + 1
    list1.append(count)
    count = 0

for i in list1:
    print(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)]
t=[0]*(n+1)
for i in range(n):
    #i桁目までに登場するACを計算する
    t[i+1]=t[i]+(1 if s[i:i+2] == "AC" else 0)
for i in range(q):
    l,r=lr[i][0]-1,lr[i][1]-1
    print(t[r-1]-t[l-1])

Submission status: Runtime Error

Solution code:

x = input().split()
n = int(x[0]) # n == 比較文字列の長さ
q = int(x[1]) # q == 検討する回数
s = input()

        
t = [0] * n
if s[0] == "A":
    t[0] = 1
    
for i in range(0,n-1):
    if s[i:i+2] == "AC":
        
        if (i == 0) :
            t[i] =  + 1
        else:
            t[i] = t[i-1] + 1
    else :
        if i == 0:
            t[i] = 0
        else:
            t[i] = t[i-1]



def sc():
    global t
    global s
    global n
    global q
    global idbox
    maxx = 0
    count = 0
    com = [int(s)-1 for s in input().split()]
    
    idbox = ind_Multi(com[0],com[1])
    print(t[com[1]-1] - t[com[0]-1])
        
    

    

for i in range(q):
    
    sc()

Submission status: Runtime Error

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

for i  in range(N-1):
    if S[i]=='A' and S[i+1]=='C':
        A.append(i+2)
for i in range(Q):
    L=list(map(int,input().split()))
    minA=bisect_left(A,L[0])
    maxA=bisect_left(A,L[1])
    print(maxA-minA)

Submission status: Runtime Error

Solution code:
n,q = int(input().split())
s = str(input())
ans = []
for i in range(q):
  ans[i] = 0
  l,r = int(input().split())
  ss = s[l:r]
  for j in range(len(ss)):
    if (ss[j] == "A") and (ss[j+1] == "C"):
      ans[i] = ans[i] + 1
for i in range(q):
  print("{}".format(ans[i]))

Submission status: Runtime Error

Solution code:
n,q = int(input().split())
s = str(input())
ans = []
for i in range(q):
  ans[i] = 0
  l,r = int(input().split())
  ss = s[l:r]
  for j in ss:
    if (ss[j] == "A") and (ss[j+1] == "C"):
      ans[i] = ans[i] + 1
for i in range(q):
  print("{}".format(ans[i]))

Submission status: Runtime Error

Solution code:
import re
ACGT = ['A', 'C', 'G', 'T']
try:
    N, Q = input().split()
except:
    print('2つのパラメータを入力してください')
    exit(0)
try:
    S = input()
    if len(S) != int(N):
        raise
    # 文字列がACGTのみであること
except:
    print('Nと文字数が一致していません')

inputArray = []
for i in range(int(Q)):
    l = input().split()
    inputArray.append(l)

for j in inputArray:
    # lからrまでの区間を抽出
    _string = S[ int(j[0])-1:int(j[1]) ]
    # 抽出した文字列の中にACがいくつ含まれるか
    print(_string)
    print(_string.count('AC'))

Submission status: Runtime Error

Solution code:
ソースコード 

Copy
Copy
_, num_query = list(map(int,input().split()))
string = input()
for _ in range(num_query):
  left, right = list(map(int,input().split()))
  sub_string = string[left-1:right]
  print(sub_string.count("AC"))

Submission status: Runtime Error

Solution code:
N,Q = map(int,input().split())
S = str(input())
l,r = map(int,input().split())
count_list = []
for i in range(1,N-1):
    if S[i-1] == "A" and S[i] == "C":
        count_list.append(1)
    else:
        count_list.append(0)
    
for j in range(Q):
    sub_count = count_list[l[j]-1:r[j]-1]
    print(sum(sub_count))

Submission status: Runtime Error

Solution code:
N,Q = map(int,input().split())
S = str(input())
lr = [input().split() for i in range(Q)]
for i in range(Q):
    sub = S[int(lr[i][0])-1:int(lr[i][1])]
    A_index = [i for i,x in enumerate(sub) if x == 'A']
    count = 0
    for j in A_index:
        if i == len(sub)-1:
            pass
        elif sub[i+1] == 'C':
            count += 1
        else:
            pass
    print(count)

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 i == len(sub):
            pass
        elif 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)