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: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
ac_list = [i+j=='AC' for i,j in zip(s[:-1],s[1:])]
for _ in range(q):
    l,r=map(int,input().split())
    print(sum(ac_list[l-1:r-1]))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
ac_list = [s[i]+s[i+1]=='AC' for i in range(n-1)]
for _ in range(q):
    l,r=map(int,input().split())
    print(sum(ac_list[l-1:r-1]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

#行列の受け取り
a = [list(map(int, input().split())) for _ in range(Q)]
    
for j in range(Q):
    S_cut = S[(a[j][0]-1):(a[j][1])]
    ans = S_cut.count("AC")
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

for i in range(Q):
    ac2=ac
    p=lr[i][0]-1
    q=lr[i][1]-1
    ac2.append(p)
    ac2.append(q)
    ac2.sort()

    num1=ac2.index(p)
    if num1%2!=0:
        num1+=1
    num2=ac2.index(q)
    if num2<len(ac2)-1:
        if ac2[num2]==ac2[num2+1]:
            num2+=1

    ac2.pop(ac2.index(p))
    ac2.pop(ac2.index(q))
    print((num2-num1-1)//2)

Submission status: Time Limit Exceeded

Solution code:
"""
n = int(sys.stdin.readline())
a, b = map(int, sys.stdin.readline().split())
c = list(map(int, sys.stdin.readline().split()))
s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

a = 100
b = 0.987654321
print('{0:06d}-{1:6f}'.format(a,b))  # 0埋め, 小数点出力桁指定時のときの出力
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)


mod = 1000000007

if __name__ == "__main__":
    N, Q = map(int, sys.stdin.readline().split())
    origin = sys.stdin.readline()
    for _ in range(Q):
        l, r = map(int, sys.stdin.readline().split())
        s = origin[l-1:r]
        a_flag = False
        ac_num = 0
        for w in s:
            if w == "A":
                a_flag = True
            if a_flag and w == "C":
                ac_num += 1
                a_flag = False
        print(ac_num)

Submission status: Time Limit Exceeded

Solution code:
import re

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

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

Submission status: Time Limit Exceeded

Solution code:
# import math
N, Q = map(int, input().split())
# line = list(map(int, input().split()))
# line = input()
S = input()
question = []
ans = []
for _ in range(Q):
    question.append(list(map(int, input().split())))

for i in range(Q):
    start = question[i][0] - 1
    end = question[i][1]
    count = 0
    for j in range(start,end-1):
        if S[j] == 'A' and S[j+1] == 'C':
            count += 1
    ans.append(count)

for i in range(len(ans)):
    print(ans[i])

Submission status: Time Limit Exceeded

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

for i in range(0,q):
    start = l[i] - 1
    end = r[i]
    strv = s[ start:end ]

    ans = 0
    for j in range(0,len(strv) - 1):
        if strv[j] == "A" and strv[j + 1] == "C":
            ans += 1

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re

n,q=map(int,input().split())
s=input()
pat=r'.*?AC.*?'
regex=re.compile(pat)
res=0

for i in range(q):
	l,r=map(int,input().split())
	l-=1
	res=len(regex.findall(s[l:r]))
	print(res)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=str(input())
lr=[list(map(int, input().split())) for _ in range(q)]
for i in range(q):
  x=s[lr[i][0]-1:lr[i][1]]
  print(x.count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n, q = map(int, input().split())
s = input()
l_ = np.zeros(q)
r_ = np.zeros(q)

for i in range(q):
    l_tmp, r_tmp = map(int, input().split())
    l_[i] = l_tmp
    r_[i] = r_tmp
l_ = l_ - 1
r_ = r_ - 1
for i in range(q):
    cnt = 0
    t = s[int(l_[i]) : int(r_[i]) + 1]
    for j in range(len(t) - 1):
        if t[j : j + 2] == "AC":
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = str(input())
lstr=[]
lstl=[]
for i in range(Q):
    r,l = map(int,input().split())
    snp = S[r-1:l]
    snp_new = snp.replace("AC",'')
    ans = (len(snp)-len(snp_new))/2
    print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = list(input())
index_A = [i for i, v in enumerate(S) if v == 'A']

for i in range(Q):
    ans = 0
    l, r = map(int, input().split())
    for j in index_A:
        if l-1 <= j <= r-2:
            if S[i + 1] == 'C':
                ans += 1
    print(ans)

Submission status: Time Limit Exceeded

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

q_list = [0] * Q

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

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

Submission status: Time Limit Exceeded

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

place = set()
index = -1
while True:
  index = s.find("AC",index + 1)
  if index == -1:
    break
  place.add(index)

for i in range(q):
  l,r = map(int,input().split())
  tmp = len(place&set(range(l-1,r)))
  if r-1 in place:
    print(tmp-1)
  else:
    print(tmp)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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()]
    na1[i1].append(i1+1)

na2 = []

t2 = 0
while True:
    t1 = s1.find("AC")

    if t1 == -1:
        break
    else:
        na2.append(t1 + t2)
        s1 = s1[t1 + 2: n1]
        t2 = t2 + t1 + 2


na1.sort(key=lambda x: x[1])

na3 = [0] * n2
for i7 in range(n2):
    na3[i7] = [na1[i7][2], 0]

nt1 = 0
n5 = 0
for i2 in range(len(na2)):
    n5 += nt1
    nt1 = 0
    for i3 in range(n2):
        if na2[i2] + 1 >= na1[i3][0] and  na2[i2] + 2  <= na1[i3][1] :
            na3[i3][1] += 1
        if i2 > na1[i3 + n5][1]:
            nt1 += 1

na3.sort()
for i5 in range(n2):
    print(na3[i5][1])

Submission status: Time Limit Exceeded

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()]
    na1[i1].append(i1+1)

na2 = []

t2 = 0
while True:
    t1 = s1.find("AC")

    if t1 == -1:
        break
    else:
        na2.append(t1 + t2)
        s1 = s1[t1 + 2: n1]
        t2 = t2 + t1 + 2


na1.sort(key=lambda x: x[1])

na3 = [0] * n2
for i7 in range(n2):
    na3[i7] = [na1[i7][2], 0]

nt1 = 0
n5 = 0
for i2 in range(len(na2)):
    n5 += nt1
    nt1 = 0
    for i3 in range(n2):
        if na2[i2] + 1 >= na1[i3][0] and  na2[i2] + 2  <= na1[i3][1] :
            na3[i3][1] += 1


na3.sort()
for i5 in range(n2):
    print(na3[i5][1])

Submission status: Time Limit Exceeded

Solution code:
n1, n2 = [int(i) for i in input().split()]

s1 = input()

na1 = [[0] * 2] * n2

ma1 = 0
mi1 = 100000
for i1 in range(n2):
    na1[i1] = [int(j) for j in input().split()]
    na1[i1].append(i1+1)
    if ma1 <= na1[i1][1]:
        ma1 = na1[i1][1]
    if mi1 >= na1[i1][0]:
        mi1 = na1[i1][0]

na1.sort(key=lambda x: x[1])

na2 = [0] * n2
for i7 in range(n2):
    na2[i7] = [na1[i7][2], 0]

f1 = False
n6 = mi1 - 1
n5 = 0
nt1 = 0


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

    if (i2 + n6) >= ma1:
        break

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

Submission status: Time Limit Exceeded

Solution code:

n1, n2 = [int(i) for i in input().split()]

s1 = input()

na1 = [[0] * 2] * n2

ma1 = 0
mi1 = 100000
for i1 in range(n2):
    na1[i1] = [int(j) for j in input().split()]
    na1[i1].append(i1+1)
    if ma1 <= na1[i1][1]:
        ma1 = na1[i1][1]
    if mi1 >= na1[i1][0]:
        mi1 = na1[i1][0]

na1.sort(key=lambda x: x[1])

na2 = [0] * n2
for i7 in range(n2):
    na2[i7] = [na1[i7][2], 0]

f1 = False
n6 = mi1 - 1
n5 = 0
nt1 = 0


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

    if (i2 + n6) >= ma1:
        break

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

Submission status: Time Limit Exceeded

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

for i in range(Q):
    r = a[i]
    S1 = S[r[0]-1:r[1]]
    print(S1.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=list(input())
value=[0]
ans_list=[]
length=[]
s_length=len(s)

for i in range(s_length-1):
  if s[s_length-i-1]=='C' and s[s_length-i-2]=='A':
    value.insert(0,value[0]+1)
  else:
    value.insert(0,value[0])

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

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=list(input())
value=[0]
ans_list=[]
length=[]
s_length=len(s)

for i in range(s_length-1):
  if s[s_length-i-1]=='C' and s[s_length-i-2]=='A':
    value.insert(0,value[0]+1)
  else:
    value.insert(0,value[0])

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

Submission status: Time Limit Exceeded

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

for i in range(q):
  ans=0
  l,r=map(int,input().split())
  sublist=s[l-1:r]
  for j in range(len(sublist)-1):
    if sublist[j]=='A' and sublist[j+1]=='C':
      ans=ans+1
  ans_list.append(ans)
  
for i in range(q):
  print(ans_list[i])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = list(input())
l = []
p = []
for i in range(n-1):
        if s[i] == "A" and s[i+1] == "C":
                l.append(i+1)
for j in range(q):
        k,t = map(int,input().split())
        b = len([1 for x in l if x >= k and x < t])
        p.append(b)
for i in range(len(p)):
        print(p[i])

Submission status: Time Limit Exceeded

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

for _ in range(q):
	l,r=map(int,input().split())
	# list_=[s[l-1:r]]
	# print(s[l-1:r])
	ans=0
	for i in range(l-1,r-1):
		if s[i] == 'A' and s[i+1] == 'C':
			ans +=1



	print(ans)

Submission status: Time Limit Exceeded

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

for i in range(q):
    l,r = map(int,input().split())
    s1 = s[l-1:r]
    s2 = "".join(s1)
    t1 = s2.count("AC")
    t.append(t1)
for x in range(len(t)):
        print(t[x])

Submission status: Time Limit Exceeded

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

for _ in range(q):
	l,r=map(int,input().split())
	# list_=[s[l-1:r]]
	# print(s[l-1:r])
	ans=0
	for i in range(l-1,r-1):
		if s[i] == 'A' and s[i+1] == 'C':
			ans +=1



	print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = list(input())
t = []
for i in range(q):
    l,r = map(int,input().split())
    s1 = s[l-1:r]
    count = 0
    for x in range(len(s1)-1):
        if s1[x] ==  "A" and s1[x+1] == "C":
            count = count + 1
    t.append(count)
for j in range(len(t)):
    print(t[j])

Submission status: Time Limit Exceeded

Solution code:
n,q = list(map(int,input().split()))
s = input()
s_len = []
ans  = []
for _ in range(q):
    t,l = list(map(int,input().split()))
    ans.append(s[t-1:l].count("AC"))
for a in ans:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
n,q = list(map(int,input().split()))
s = input()
s_len = []
lt_li = [list(map(int,input().split())) for x in range(q)]
ans = [s[t-1:l].count("AC") for t,l in lt_li]
for a in ans:
    print(a)

Submission status: Time Limit Exceeded

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

check = [0 for i in range(N+2)]

for i in range(N):
    if S[i:i+2] == "AC":
        check[i+1] = 1

ans = [0 for i in range(Q)]

for i in range(Q):
    l, r = map(int, input().split())
    ans[i] = sum(check[l:r])

for i in range(Q):
    print(ans[i])

Submission status: Time Limit Exceeded

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 q in range(Q):
  l,r=map(int,input().split())
  s=S[l-1:r]
  print(t[r-1] - t[l-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
def count(l,r):
    s = S[l-1:r]
    cnt = 0
    for i in range(len(s)-1):
        if s[i] == "A" and s[i+1] == "C":
            cnt += 1
    return cnt
    
for i in range(Q):
    l,r = map(int,input().split())
    print(count(l,r))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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


num_ac = [0] * n

for i in range(n):
    num_ac[i] = s[:i+1].count("AC")

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

for a in ans:
    print(a)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, stdout

n, q = [int(x) for x in stdin.readline().rstrip().split()]
s = stdin.readline().rstrip()

for i in range(q):
	l, r = [int(x) for x in stdin.readline().rstrip().split()]
	stdout.write(str(s[l - 1:r].count("AC")) + "\n")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(q):
    li, ri = map(int, input().split())
    t = s[li - 1:ri]
    a_flag = False
    cnt = 0
    for j in range(len(t)):
        if t[j] == 'A':
            a_flag = True
        elif t[j] == 'C':
            if a_flag:
                cnt += 1
                a_flag = False
        else:
            a_flag = False

    print(cnt)

Submission status: Time Limit Exceeded

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

cc = []

for idx in range(N):
    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: Time Limit Exceeded

Solution code:
import sys

N, Q = map(int, sys.stdin.readline().split())
S = sys.stdin.readline().strip()
for _ in range(Q):
    l, r = map(int, sys.stdin.readline().split())
    print(len(S[l - 1:r].split("AC")) - 1)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
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: Time Limit Exceeded

Solution code:
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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
AC_or_No=[]
ans=[]
n=0

while n<=N-2:
    if S[n]=="A":
        if S[n+1]=="C":
            AC_or_No.append(1)
            AC_or_No.append(0)
            n+=2
    else:
        AC_or_No.append(0)
        n+=1

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

for i in ans:
    print(i)

Submission status: Time Limit Exceeded

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

for _ in range(Q):
    l,r=map(int,input().split())
    continuous=0
    while l<=r-1:
        if S[l-1]=="A":
            if S[l]=="C":
                continuous+=1
                l+=2
        else:
            l+=1
    ans.append(continuous)

for j in ans:
    print(j)

Submission status: Time Limit Exceeded

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

li = []

for i in range(n-1):
    if s[i:i+2] == "AC":
        li.append(i)

for i in range(q):
    ans = 0
    a,b = map(int, input().split())
    data1 = list(filter(lambda x: a-1 <= x <=b-2, li))
    print(len(data1))

Submission status: Time Limit Exceeded

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

for i in range(q):
    x,y = map(int, input().split())
    
    print(s[x-1:y].count("AC"))

Submission status: Time Limit Exceeded

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 = [False] * (N-1)
    ptr = 0
    while(True):
        ptr = S.find("AC", ptr)
        if ptr == -1:
            break
        mem[ptr] = True
        ptr = ptr + 1

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

if '__main__' == __name__:
    resolve()

Submission status: Time Limit Exceeded

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

if '__main__' == __name__:
    resolve()

Submission status: Time Limit Exceeded

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(len(S)-1)]

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

if '__main__' == __name__:
    resolve()

Submission status: Time Limit Exceeded

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

    for (l, r) in LRs:
        print(S[l-1:r].count("AC"))

if '__main__' == __name__:
    resolve()

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
anslst = []
for i in range(Q):
    l1, l2 = map(int,input().split())
    compStr = S[l1 - 1:l2]
    anslst.append(compStr.count('AC'))

for i in anslst:
    print(i)

Submission status: Time Limit Exceeded

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

start = []
end = []
c = s.count("AC")

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

for i in range(c):
    list[i] = s.find("AC")
    s = s.replace("AC", "XX", 1)

result = [0]*q

for i in range(q):
    for j in range(c):
        #print(str(start[i]) + " : " + str(end[i]))
        if start[i] <= list[j] < end[i]:
            result[i] += 1


for i in result:
    print(i)

Submission status: Time Limit Exceeded

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

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

for i in list:
    print(i)

Submission status: Time Limit Exceeded

Solution code:

def checkATCG(S) :

    default = len(S)
    change = len(S.replace("AC",""))
    cnt = default - change
    cnt = cnt /2

    return cnt

fstInp = input()
fstInp = fstInp.split()
N = int(fstInp[0])
Q = int(fstInp[1])
S = input()
inList = []
cnt = 0
while cnt < Q:
    inputNum = input()
    inputNum = inputNum.split()
    num1 = int(inputNum[0])
    num2 = int(inputNum[1])
    
    inList.append(num1)
    inList.append(num2)
    cnt += 1

ansList = []
cnt = 0
while cnt < len(inList):
    checkStr = S[inList[cnt] -1:inList[cnt + 1]]
    print(int(checkATCG(checkStr)))
    cnt += 2

Submission status: Time Limit Exceeded

Solution code:
import copy
n, q = map(int, input().split())
s = list(input())
cnt = 0
ans = []
for _ in range(q) :
        l, r = map(int, input().split())
        for i in range(l-1,r) :
                if s[i] == 'A' :
                        if i+1 < r and s[i+1] == 'C' :
                                cnt += 1
        ans.append(copy.deepcopy(cnt))
        cnt = 0
for i in ans :
        print(i)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import re
rex = r"AC"
N, Q = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
X = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(Q)]
for k in range(Q):
    print(len(re.findall(rex, S[X[k][0] - 1:X[k][1]])))

Submission status: Time Limit Exceeded

Solution code:
# ABC122C - GeT AC
import sys
input = sys.stdin.readline

n, q = list(map(int, input().rstrip().split()))
s = input().rstrip()
arr = [list(map(int, input().rstrip().split())) for _ in range(q)]
cnt = [0] * (n - 1)
for i in range(n - 1):
    if s[i : i + 2] == "AC":
        cnt[i] += 1
for i, j in arr:
    print(cnt[i - 1 : j - 1].count(1))

Submission status: Time Limit Exceeded

Solution code:
# ABC122C - GeT AC
import sys
input = sys.stdin.readline

n, q = list(map(int, input().rstrip().split()))
s = input().rstrip()
arr = [list(map(int, input().rstrip().split())) for _ in range(q)]
cnt = [0] * (n - 1)
for c, (i, j) in enumerate(zip(s, s[1:])):
    if i + j == "AC":
        cnt[c] += 1
for i, j in arr:
    print(cnt[i - 1 : j - 1].count(1))

Submission status: Time Limit Exceeded

Solution code:
# ABC122C - GeT AC
import sys
input = sys.stdin.readline

n, q = list(map(int, input().rstrip().split()))
s = input().rstrip()
arr = [list(map(int, input().rstrip().split())) for _ in range(q)]
cnt = []
for i, j in zip(s, s[1:]):
    if i + j == "AC":
        cnt += [1]
    else:
        cnt += [0]
for i, j in arr:
    print(cnt[i - 1 : j - 1].count(1))

Submission status: Time Limit Exceeded

Solution code:
# ABC122C - GeT AC
n, q = list(map(int, input().rstrip().split()))
s = input().rstrip()
arr = [list(map(int, input().rstrip().split())) for _ in range(q)]
for i, j in arr:
    cnt = 0
    for k, l in zip(s[i - 1 : j - 1], s[i:]):
        if k + l == "AC":
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
 # -*- coding: utf-8 -*-
     
[N, Q] = [int(i) for i in input().split()]

S = input()

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

ac_position_list = []
ac_position = 0
base = 0
while (True):
    ac_position = S[base:].find('AC')
    if ac_position == -1:
        break
    
    ac_position
    ac_position_list.append(ac_position + base)
    base += ac_position + 2

#print(ac_position_list)
for q in range(Q):
    l = lr[q][0]
    r = lr[q][1]
    #print(lr[q])

    count = 0
    for ac_position in ac_position_list:
        if ac_position >= l-1 and ac_position <= r-2:
            count += 1

    print(count)

Submission status: Time Limit Exceeded

Solution code:
import re
N = [int(i) for i in input().split()]
S = input()
lr = [[int(i) for i in input().split()]for i in range(N[1])]
[print(i) for i in [len([j for j in re.findall('AC', S[lr[i][0]-1:lr[i][1]])]) for i in range(N[1])]]

Submission status: Time Limit Exceeded

Solution code:
import re
N = [int(i) for i in input().split()]
S = input()
lr = [[int(i) for i in input().split()]for i in range(N[1])]
f = [len([j for j in re.findall('AC', S[lr[i][0]-1:lr[i][1]])]) for i in range(N[1])]
[print(i) for i in f]

Submission status: Time Limit Exceeded

Solution code:
import re
N = [int(i) for i in input().split()]
S = input()
lr = [[int(i) for i in input().split()]for i in range(N[1])]
for i in range(N[1]):
    f = [j for j in re.findall('AC', S[lr[i][0]-1:lr[i][1]])]
    print(len(f))

Submission status: Time Limit Exceeded

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

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

for i in list:
    print(i)