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 = list(map(int, input().split()))
S = input()
li = [list(map(int, input().split())) for i in range(Q)]

for num in range(Q):
    st = S[li[num][0] - 1:li[num][1]]
    if not "AC" in st:
        print(0)
    else:
        count = 0
        for i in range(len(st)-1):
            if st[i] == "A":
                if st[i+1] == "C":
                    count += 1
        print(count)

Submission status: Time Limit Exceeded

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

for num in range(Q):
    st = S[li[num][0] - 1:li[num][1]]
    count = 0
    for i in range(len(st)-1):
        if st[i] == "A":
            if st[i+1] == "C":
                count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N,Q=list(map(int,input().split(" ")))
inp=input()
data=[]
for i in range(Q):
  start,finish=list(map(int,input().split(" ")))
  temp=inp[start-1:finish]
  #print(temp)
  data.append(temp.count("AC"))
for i in data:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
N,Q=list(map(int,input().split(" ")))
str=input()
data=[]
for i in range(Q):
  start,finish=list(map(int,input().split(" ")))
  temp=str[start-1:finish]
  #print(temp)
  data.append(temp.count("AC"))
for i in data:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
l = [0]*Q
r = [0]*Q
for q in range(Q):
    l[q],r[q] = map(int,input().split())

for q in range(Q):
    cnt = 0
    for i in range((l[q]-1),r[q]-1):
        if S[i:i+2] == 'AC':
            cnt +=1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,Q=list(map(int,input().split(" ")))
str=input()
for i in range(Q):
  start,finish=list(map(int,input().split(" ")))
  temp=str[start-1:finish]
  #print(temp)
  print(temp.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
l = [0]*Q
r = [0]*Q
for q in range(Q):
    l[q],r[q] = map(int,input().split())

for q in range(Q):
    s = S[l[q]-1:r[q]]
    #print(s)
    cnt = 0
    for i in range(len(s)-1):
        if s[i:i+2] == 'AC':
            cnt +=1
            #print('y')
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
first_input = input().split(' ')

s_length = int(first_input[0])
num_of_Q = int(first_input[1])

input_string = input()

for q in range(num_of_Q):
    l_r = input().split(' ')
    l = int(l_r[0])
    r = int(l_r[1])

    sub_str = input_string[l-1:r]
    num_of_ac = sub_str.count('AC')

    print(num_of_ac)

Submission status: Time Limit Exceeded

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

for q in range(Q):
    l, r = [int(x) for x in input().split()]
    str = S[l - 1: r]
    # print(str)
    print(str.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
listA=[] 
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        
l = list(s)
li=[0]*n

for i in range(n-1):
  if l[i]=="A" and l[i+1]=="C":
    li[i]+=1
    
#print(li)   
 
    
ans=0
for j in range(q):
  a=listA[j][0]-1
  b=listA[j][1]-1
  #print(a,b)
  for k in range(a,b):
    if li[k]==1:
      ans+=1
  print(ans)
  ans=0

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, Q = map(int, input().split())
S = input()
L_R = np.array([input().split() for _ in range(Q)], dtype=int)
L = L_R[:,0]
R = L_R[:,1]

for l, r in zip(L, R):
    s = np.array(list(S[l-1:r]))
    print(len(np.intersect1d(np.where(s=='A')[0]+1, np.where(s=='C')[0])))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, Q = map(int, input().split())
S = input()
L_R = np.array([input().split() for _ in range(Q)], dtype=int)
L = L_R[:,0]
R = L_R[:,1]

for l, r in zip(L, R):
    s = np.array(list(S[l-1:r]))
    print(len(np.intersect1d(np.where(s=='A')[0]+1, np.where(s=='C')[0])))

Submission status: Time Limit Exceeded

Solution code:
input1 = input().split()
N = input1[0]
Q = input1[1]
S = input()

flag = 0
count = 0
result = []

for q in range(int(Q)):
	
	input3 = input().split()
	
	l = int(input3[0])
	r = int(input3[1])+1
	
	for s in (range(l,r)):
		
		#print(s)
		if(S[s-1] == 'A'):
			flag = 1
			
		elif ((S[s-1] == 'C') and (flag == 1)):
			count += 1
			flag = 0			
	result.append(count)
	count = 0
	flag = 0
for i in result:
	print(i)

Submission status: Time Limit Exceeded

Solution code:
input1 = input().split()
N = input1[0]
Q = input1[1]
S = input()

flag = 0
count = 0
result = []

for q in range(int(Q)):
	
	input3 = input().split()
	
	l = int(input3[0])
	r = int(input3[1])+1
	
	for s in (range(l,r)):
		
		#print(s)
		if(S[s-1] == 'A'):
			flag = 1
			
		elif ((S[s-1] == 'C') and (flag == 1)):
			#flag += 1
			count += 1
			flag = 0
		
		#if flag == 2:
	#		count += 1
	#		flag = 0
			
	result.append(count)
	
	count = 0
	flag = 0
	
for i in result:
	print(i)

Submission status: Time Limit Exceeded

Solution code:
input1 = input().split()
N = input1[0]
Q = input1[1]
S = input()

flag = 0
count = 0
result = []

for q in range(int(Q)):
	
	input3 = input().split()
	
	l = int(input3[0])
	r = int(input3[1])+1
	
	for s in (range(l,r)):
		
		#print(s)
		if((S[s-1] == 'A') and (flag % 2 == 0)):
			flag += 1
			
		elif ((S[s-1] == 'C') and (flag % 2 == 1)):
			flag += 1
			
		
		#if flag == 2:
	#		count += 1
	#		flag = 0
			
	result.append(int(flag/2))
	
	count = 0
	flag = 0
	
for i in result:
	print(i)

Submission status: Time Limit Exceeded

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

cnt=[]
for i in range(Q):
    ans=0
    l,r = map(int,input().split())
    s = S[l-1:r]
    j = 0
    while j+2 <= len(s):
        if s[j:j+2] == 'AC':
            ans += 1
        j += 1
    cnt.append(ans)

for answer in cnt:
    print (answer)

Submission status: Time Limit Exceeded

Solution code:
input1 = input().split()
N = input1[0]
Q = input1[1]
S = input()

flag = 0
count = 0
result = []

for q in range(int(Q)):
	
	input3 = input().split()
	
	l = int(input3[0])
	r = int(input3[1])+1
	
	for s in (range(l,r)):
		
		#print(s)
		if S[s-1] == 'A':
			flag = 1
			
		elif S[s-1] == 'C':
			if flag == 1:
				count += 1
				flag = 0

		else:
			flag = 0
			
	result.append(count)
	
	count = 0
	flag = 0
	
for i in result:
	print(i)

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split(" "))
ar = input()
for i in range(b):
    count = 0
    l,r = map(int,input().split(" "))
    br = ar[l-1:r]
    if "AC" in br:
        for j in range(len(br)-1):
            if br[j:j+2] == "AC":
                count += 1
        print(count)
    else:
        print(0)

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.count("AC", l - 1, r))

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline

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

place_of_AC = []
for i in range(len(s) - 1):
  if s[i:i+2] == "AC":
    place_of_AC.append(1)
  else:
    place_of_AC.append(0)
    
for _ in range(q):
  l, r = map(int, input().split(" "))
  out = sum(place_of_AC[l-1:r-1])
  print(out)

Submission status: Time Limit Exceeded

Solution code:
input1 = input().split()
N = input1[0]
Q = input1[1]
S = input()

flag = 0
count = 0
result = []

for q in range(int(Q)):
	
	input3 = input().split()
	
	l = int(input3[0])
	r = int(input3[1])+1
	
	for s in (range(l,r)):
		
		#print(s)
		if S[s-1] == 'A':
			flag = 1
			
		elif S[s-1] == 'C':
			flag += 3
			if flag == 4:
				count += 1
				flag = 0

		else:
			flag = 0
			
	result.append(count)
	
	count = 0
	flag = 0
	
for i in result:
	print(i)

Submission status: Time Limit Exceeded

Solution code:
input1 = input().split()
N = input1[0]
Q = input1[1]
S = input()

flag = 0
count = 0
result = []

for q in range(int(Q)):
	
	input3 = input().split()
	
	l = int(input3[0])
	r = int(input3[1])+1
	
	for s in (range(l,r)):
		
		#print(s)
		if S[s-1] == 'A':
			flag = 1
			
		if S[s-1] == 'C':
			flag += 3
			
		if flag == 4:
			count += 1
			flag = 0
			
	result.append(count)
	
	count = 0
	flag = 0
	
for i in result:
	print(i)

Submission status: Time Limit Exceeded

Solution code:
input1 = input().split()
N = input1[0]
Q = input1[1]
S = input()

flag = 0
count = 0
result = []

for q in range(int(Q)):
	
	input3 = input().split()
	
	l = int(input3[0])
	r = int(input3[1])
	
	for s in (range(l,r)):
		
		#print(s)
		if S[s-1] == 'A':
			if S[s] == 'C':
				count += 1
			
	result.append(count)
	
	count = 0
	
for i in result:
	print(i)

Submission status: Time Limit Exceeded

Solution code:
input1 = input().split()
N = input1[0]
Q = input1[1]
S = input()

flag = 0
count = 0
result = []

for q in range(int(Q)):
	
	input3 = input().split()
	
	l = int(input3[0])
	r = int(input3[1])
	
	for s in (range(l,r)):
		
		#print(s)
		if S[s-1] != 'A':
			continue
		else :
			if S[s] == 'C':
				count += 1
			
	result.append(count)
	
	count = 0
	
for i in result:
	print(i)

Submission status: Time Limit Exceeded

Solution code:
input1 = input().split()
N = input1[0]
Q = input1[1]
S = input()

flag = 0
count = 0
result = []

for q in range(int(Q)):
	
	input3 = input().split()
	
	l = int(input3[0])
	r = int(input3[1])
	
	for s in (range(l,r)):
		
		#print(s)
		if S[s-1] == 'A' and S[s] == 'C':
			count += 1
			
	result.append(count)
	
	count = 0
	
for i in result:
	print(i)

Submission status: Time Limit Exceeded

Solution code:
input1 = input().split()
N = input1[0]
Q = input1[1]
S = input()

flag = 0
count = 0
result = []

for q in range(int(Q)):
	
	input3 = input().split()
	
	l = int(input3[0])
	r = int(input3[1])+1
	
	for s in (range(l,r)):
		
		#print(s)
		if S[s-1] == 'A':
			flag = 1
			
		if ((S[s-1] == 'C') and (flag == 1)):
			count += 1
			flag = 0
			
		if S[s-1] != 'A':
			flag = 0
			
	result.append(count)
	
	count = 0
	flag = 0
	
for i in result:
	print(i)

Submission status: Time Limit Exceeded

Solution code:
input1 = input().split()
N = input1[0]
Q = input1[1]
S = input()

flag = 0
count = 0
result = []

for q in range(int(Q)):
	
	input3 = input().split()
	
	l = int(input3[0])
	r = int(input3[1])+1
	
	for s in (range(l,r)):
		
		#print(s)
		if S[s-1] == 'A':
			flag += 1
			
		elif ((S[s-1] == 'C') and (flag == 1)):
			count += 1
			flag = 0
			
		else:
			flag = 0
			
	result.append(count)
	
	count = 0
	flag = 0
	
for i in result:
	print(i)

Submission status: Time Limit Exceeded

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

for i in range(q):
    count = 0
    start = b[i][0]-1
    end = b[i][1]-1
    for j in range(start, end):
        if s[j:j+2] == "AC":
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import re
n, q = map(int, input().split())
s = input()
count = 0

for i in range(q):
    n_, q_ = map(int, input().split())
    s_ = s[n_-1:q_]
    print(len(re.findall("AC", s_)))

Submission status: Time Limit Exceeded

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

for i in range(q):
    n_, q_ = map(int, input().split())
    s_ = s[n_-1:q_]
    for j in range(len(s_)-1):
        if s_[j] == "A" and s_[j+1] == "C":
            count += 1
    print(count)
    count = 0

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def ac_count(s):
    cnt = 0
    for i in range(len(s)-1):
        if s[i:i+2] == 'AC':
            cnt += 1
    return cnt


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

for i in range(Q):
    print(ac_count(S[l[i]-1:r[i]]))

Submission status: Time Limit Exceeded

Solution code:



def start_process(length, q_num, char):
    for i in range(q_num):
        start_ind, fin_ind = map(int, input().split())
        now_str = char[start_ind - 1:fin_ind]
        print(now_str.count('AC'))



def main():
    length, q_num = map(int, input().split())
    char = input()
    start_process(length, q_num, char)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for i in range(q):
    a = s[li[i][0]-1:li[i][1]]
    print(a.count("AC"))

Submission status: Time Limit Exceeded

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

for i in range(Q):
  l, r = map(int,input().split())
  Si = S[l-1:r]
  
  len_Si = len(Si)
  for i in range(len_Si-1):
    if Si[i:i+2] == 'AC':
      count += 1
  print(count)
  count = 0

Submission status: Time Limit Exceeded

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

for i in range(Q):
  l, r = map(int,input().split())
  Si = S[l-1:r]
  
  len_Si = len(Si)
  for i in range(len_Si-1):
    if Si[i] == 'A'and Si[i+1] == 'C':
      count += 1
  print(count)
  count = 0

Submission status: Time Limit Exceeded

Solution code:
import re
N, Q = map(int, input().split())  # N: len(S)
S = input()
A = [list(map(int, input().split())) for _ in range(Q)]

for l, r in A:
    print(len(re.findall('AC', S[l - 1:r])))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
t = [1 if S[j:j+2] == "AC" else 0 for j in range(N)]
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(int(np.sum(t[l-1:r-1])))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
for i in range(Q):
  l, r = list(map(int, input().split()))
  print(int(np.sum([1 for j in range(l-1, r-1) if S[j:j+2] == "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())
    T=S[l-1:r]
    count=T.count("AC")
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
for i in range(0, Q):
    li, ri = map(int, input().split())
    count = 0
    for j in range(li-1, ri-1):
        if S[j]=="A" and S[j+1]=="C":
            count +=1
    print("{}".format(count))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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())
  print(S.count('AC',l-1, r))

Submission status: Time Limit Exceeded

Solution code:
import sys
import re
lines = sys.stdin.readlines()
for line in lines[2:]:
    l, r = map(int, line.split())
    match = re.findall("(AC)", lines[1][l-1:r])
    print(len(match))

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())
    match = re.findall("(AC)", S[l-1:r])
    print(len(match))

Submission status: Time Limit Exceeded

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

for i in lr:
  print(S[i[0]-1:i[1]].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

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

hit = [False] * N

for i in range(0, N):
    if S[i:i + 2] == 'AC':
        hit[i] = True

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = [int(nq) for nq in input().split(" ")]
S = input()
for i in range(Q):
    li, ri = [int(lr) for lr in input().split(" ")]
    print(S[li-1:ri].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N, Q = [int(nq) for nq in input().split(" ")]
S = input()
s = S.replace("AC", "NM")
for i in range(Q):
    li, ri = [int(lr) for lr in input().split(" ")]
    print(s[li-1:ri].count("NM"))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#!/usr/bin/env python3

import sys


def main():
    input = sys.stdin.readline
    n, q = [int(i) for i in input().split()]
    s = input().strip()
    qs = [[int(i) for i in input().split()] for _ in range(q)]
    for (l, r) in qs:
        print(s[l - 1 : r].count("AC"))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys


def main():
    input = sys.stdin.readline
    n, q = [int(i) for i in input().split()]
    s = input()
    qs = [[int(i) for i in input().split()] for _ in range(q)]
    hoges = [False] + [s[i : i + 2] == "AC" for i in range(n - 1)]
    for (l, r) in qs:
        print(sum(hoges[l:r]))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#n=int(input())
#li=input().split()
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math

lis=[]
#N Q
li=list(map(int,input().split()))
S=input()
for i in range(li[1]):
    #l_i r_i
    lr=list(map(int,input().split()))
    lis.append(lr)
L=[0]*(li[0]-1)
for i in range(li[0]-1):
    if S[i:i+2]=="AC":
        L[i]+=1
ans=[]
for i in range(li[1]):
    ans.append(sum(L[lis[i][0]-1:lis[i][1]-1]))
for i in range(li[1]):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
import sys
 
N, Q = map(int, input().split())
 
S = input()
 
lr = [list(map(int, i.split())) for i in sys.stdin]
  
for q in lr:
  st = q[0]-1
  en = q[1]
  left = st
  right = st
  s = S[st:en]
  ans = 0
  while right < en+1:
    dif = right - left
    if dif == 2:
      if S[left:right] == 'AC':
        ans += 1
      left += 1
    elif dif == 1:
      right += 1
    elif dif == 0:
      right += 1
      
  print(ans)

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())
  ACsum=S[L-1:R].split("AC")
  print(len(ACsum)-1)

Submission status: Time Limit Exceeded

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

for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        an[i] = 1
# print(an)
for i in range(Q):
    print(an[a[i][0] - 1:a[i][1] - 1].count(1))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = [int(x) for x in input().split(" ")]
S = input()
LR = [[int(x) for x in input().split(" ")] for _ in range(Q)]

print('\n'.join([str(S[l-1:r].count('AC')) for l, r in LR]))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import math
import itertools
import re
import sys
sys.setrecursionlimit(10**8)
 
 
def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]
 
dp = {}
T = {}
 
def solve(input_string):
    N, Q = map(int, input_string[0].split())
    S = input_string[1]
    intMatrix = makeIntMatrix(input_string[2:])
    #print(input_string[2:])
    #for i in range(Q):
    for line in intMatrix:
        t=[0]*(N+1)
        for i in range(N):
            t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
        l, r = line
        #print(l, r)
        #print(S[l:r+1])
        #cnt = len(re.findall(r'AC', S[l-1:r]))
        #totalCnt = cntAC(L, R, S)
        totalCnt = t[r-1] - t[l-1]
        print(totalCnt)
    return
 

"""
wrong answer
def cntAC(l, r, D, S, cnt):
    global dp
    global T
    if r-l == D+1:
        return cnt
    if str(l)+str(r) not in T:
        T[str(l)+str(r)] = S[l-1:r]
        t = T[str(l)+str(r)]
    if str(l)+str(r) not in dp:
        #print(t)
        dp[str(l)+str(r)] = len(t.split('AC'))-1
        cnt = dp[str(l)+str(r)]
        return cntAC(l-1, r, D, S, cnt)
    else:
        cnt = dp[str(l)+str(r)]
        return cntAC(l-1, r, D, S, cnt)
"""
 

"""
wrong answer
def cntAC(L, r, S):
    global dp
    global T
    for l in range(L, r)[::-1]:
        if str(l)+str(r) not in T:
            T[str(l)+str(r)] = S[l-1:r]
            t = T[str(l)+str(r)]
        else:
            t = T[str(l)+str(r)]
        if str(l)+str(r) not in dp:
            dp[str(l)+str(r)] = len(t.split('AC'))-1
            cnt = dp[str(l)+str(r)]
        else:
            cnt = dp[str(l)+str(r)]
    return cnt
"""
 
def cntAC(L, R, S):
    cnt = 0
    for l in range(L, R):
        t = S[l-1:l+1]
        cnt +=  1 if t == 'AC' else 0
    return cnt

def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    #print(answer)
 
 
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import math
import itertools
import re
import sys
sys.setrecursionlimit(10**8)
 
 
def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]
 
dp = {}
T = {}
 
def solve(input_string):
    S = input_string[1]
    intMatrix = makeIntMatrix(input_string[2:])
    #print(input_string[2:])
    for line in intMatrix:
        L, R = line
        #print(l, r)
        #print(S[l:r+1])
        #cnt = len(re.findall(r'AC', S[l-1:r]))
        totalCnt = cntAC(L, R, S)
        print(totalCnt)
    return
 

"""
wrong answer
def cntAC(l, r, D, S, cnt):
    global dp
    global T
    if r-l == D+1:
        return cnt
    if str(l)+str(r) not in T:
        T[str(l)+str(r)] = S[l-1:r]
        t = T[str(l)+str(r)]
    if str(l)+str(r) not in dp:
        #print(t)
        dp[str(l)+str(r)] = len(t.split('AC'))-1
        cnt = dp[str(l)+str(r)]
        return cntAC(l-1, r, D, S, cnt)
    else:
        cnt = dp[str(l)+str(r)]
        return cntAC(l-1, r, D, S, cnt)
"""
 

"""
wrong answer
def cntAC(L, r, S):
    global dp
    global T
    for l in range(L, r)[::-1]:
        if str(l)+str(r) not in T:
            T[str(l)+str(r)] = S[l-1:r]
            t = T[str(l)+str(r)]
        else:
            t = T[str(l)+str(r)]
        if str(l)+str(r) not in dp:
            dp[str(l)+str(r)] = len(t.split('AC'))-1
            cnt = dp[str(l)+str(r)]
        else:
            cnt = dp[str(l)+str(r)]
    return cnt
"""
 
def cntAC(L, R, S):
    cnt = 0
    for l in range(L, R):
        t = S[l-1:l+1]
        cnt +=  1 if t == 'AC' else 0
    return cnt

def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    #print(answer)
 
 
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = [int(x) for x in input().split(" ")]
S = input()
LR = [[int(x) for x in input().split(" ")] for _ in range(Q)]

for ans in [str(S[l - 1:r].count('AC')) for l, r in LR]:
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import math
import itertools
import re
import sys
sys.setrecursionlimit(10**8)
 
 
def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]
 
dp = {}
T = {}
 
def solve(input_string):
    S = input_string[1]
    intMatrix = makeIntMatrix(input_string[2:])
    #print(input_string[2:])
    for line in intMatrix:
        L, R = line
        #print(l, r)
        #print(S[l:r+1])
        #cnt = len(re.findall(r'AC', S[l-1:r]))
        totalCnt = cntAC(L, R, S)
        print(totalCnt)
    return
 

"""
wrong answer
def cntAC(l, r, D, S, cnt):
    global dp
    global T
    if r-l == D+1:
        return cnt
    if str(l)+str(r) not in T:
        T[str(l)+str(r)] = S[l-1:r]
        t = T[str(l)+str(r)]
    if str(l)+str(r) not in dp:
        #print(t)
        dp[str(l)+str(r)] = len(t.split('AC'))-1
        cnt = dp[str(l)+str(r)]
        return cntAC(l-1, r, D, S, cnt)
    else:
        cnt = dp[str(l)+str(r)]
        return cntAC(l-1, r, D, S, cnt)
"""
 

def cntAC(L, r, S):
    global dp
    global T
    for l in range(L, r)[::-1]:
        if str(l)+str(r) not in T:
            T[str(l)+str(r)] = S[l-1:r]
            t = T[str(l)+str(r)]
        else:
            t = T[str(l)+str(r)]
        if str(l)+str(r) not in dp:
            dp[str(l)+str(r)] = len(t.split('AC'))-1
            cnt = dp[str(l)+str(r)]
        else:
            cnt = dp[str(l)+str(r)]
    return cnt
 

def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    #print(answer)
 
 
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

    #for i in range(int(Q)):
      #  list.append(map(int, input().split()))

    for i in range(int(Q)):
        #a, b = list[i]
        a, b = map(int, input().split())
        sss = S[a - 1:b]
        count = sss.count("AC")
        print(count)

    return 0


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

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

for d in data:
    ans = 0
    flag = False
    for t in s[d[0]-1:d[1]]:
        if flag and t == "C":
            ans += 1
            flag = False
        else:
            flag = False
        if t == "A":
            flag = True

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
l = []
r = []
for i in range(Q):
    li, ri = map(int, input().split())
    l += [li]
    r += [ri]

S_tf = [S[ind:ind+2] == "AC" for ind in range(N)]

for ind in range(Q):
    print(sum(S_tf[max(0, l[ind]-1) : min(r[ind]-1, N)]))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
s = input()
lis = []
for i in range(len(s)-1):
    if(s[i:i+2] == "AC"): lis.append(i)
n = len(lis)
for i in range(Q):
    cnt = 0
    in0, in1 = map(int, input().split())
    for j in lis:
        if((in0-1)<= j < (in1-1)): cnt += 1
    print(cnt)