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()
o=[]
for i in range(Q):
    l,r=map(int,input().split())
    o.append(str(S[l-1:r].count('AC')))
print('\n'.join(o))

Submission status: Time Limit Exceeded

Solution code:
s=list(map(int,input().split()))
N=s[0]
Q=s[1]
S=input()
out=''
for i in range(Q):
    s=list(map(int,input().split()))
    s=S[s[0]-1:s[1]]
    out+=str(s.count('AC'))+'\n'
print(out[:-1])

Submission status: Time Limit Exceeded

Solution code:
s=list(map(int,input().split()))
N=s[0]
Q=s[1]
S=input()
out=''
for i in range(0,Q):
    s=list(map(int,input().split()))
    s=S[int(s[0])-1:int(s[1])]
    out+=str(s.count('AC'))+'\n'
print(out[:-1])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
a,b = map(int, input().split())
c = str(input())
d = [list(map(int, input().split())) for i in range(0,b)]

for i in d:
    moji = c[i[0]-1:i[1]]
    count = 0
    for t in range(0,len(moji)-1):
        if moji[t]+moji[t+1] == "AC":
            count = count + 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
a,b = map(int, input().split())
c = str(input())

for i in range(0,b):
    d,e = map(int, input().split())
    moji = c[d-1:e]
    
    count = 0
    for t in range(0,len(moji)-1):
        if moji[t]+moji[t+1] == "AC":
            count = count + 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
a,b = map(int, input().split())
c = str(input())

for i in range(0,b):
    d,e = map(int, input().split())
    print(c[d-1:e].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]

for l, r in lr:
    sub = S[l-1:r]
    dp = [0 for _ in range(len(sub))]
    for i in range(len(dp)):
        if sub[i:i+2] == "AC":
            dp[i] = 1
    print(sum(dp))

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())
    sr = s[l-1:r]
    print(sr.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
import re
s, q = input().split()
a = input()
ac = re.compile('AC')

for i in range(int(q)):
  l, r = input().split()
  print(len(ac.findall(a[int(l)-1:int(r)])))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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


for x in range(0,Q):
    l,r = map(int,input().split())
    lls.append(l)
    rls.append(r)

returnList = []
flag = False
for x in range(0,len(S)):
    if S[x] == "A":
        flag = True
    elif S[x] == "C" and flag:
        flag = False
        returnList.append(x)
    else:
        flag = False

for x in range(0,Q):
    count = 0
    l = lls[x]
    r = rls[x]
    
    for y in range(l,r):
        if y in returnList:
            count += 1

    print(count)


"""
for x in range(0,Q):
    l,r = map(int,input().split())
    lls.append(l)
    rls.append(r)

def ACcount(b):
    count = 0
    flag = False
    for x in b:
        if x == "A":
            flag = True
        elif x == "C" and flag:
            flag = False
            count += 1
        else:
            flag = False
    return count

for x in range(0,len(lls)):
    print(ACcount(S[lls[x]-1:rls[x]]))
"""

Submission status: Time Limit Exceeded

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

for x in range(0,Q):
    l,r = map(int,input().split())
    lls.append(l)
    rls.append(r)

def ACcount(b):
    count = 0
    flag = False
    for x in b:
        if x == "A":
            flag = True
        elif x == "C" and flag:
            flag = False
            count += 1
        else:
            flag = False
    return count

for x in range(0,len(lls)):
    print(ACcount(S[lls[x]-1:rls[x]]))

Submission status: Time Limit Exceeded

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

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

aclist = []

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

def account(num,arr):
    cnt = 0
    for i in range(len(arr)):
        if arr[i] + 1 <= num - 1:
            cnt += 1
    return cnt

for i in range(q):
    ans = account(r[i],aclist) - account(l[i],aclist)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re


def judge(x, y, listJ):
    count = 0
    for n in range(x, y):
        if n in listJ:
            count += 1
    return count


L1 = input()
L1 = L1.split()
N = int(L1[0])
Q = int(L1[1])
S = input()
k = re.finditer('AC', S)
listJ = []
for each in k:
    listJ.append(each.start()+1)
inputList = []
for i in range(1, Q+1):
    inputList.append(input())
for i in range(0, Q):
    a = inputList[i]
    a = a.split()
    result = judge(int(a[0]), int(a[1]), listJ)
    print(result)

Submission status: Time Limit Exceeded

Solution code:
L1 = input()
L1 = L1.split()
N = int(L1[0])
Q = int(L1[1])
S = input()
inputList = []
for i in range(1, Q+1):
    inputList.append(input())
for i in range(0, Q):
    a = inputList[i]
    a = a.split()
    b = S[int(a[0])-1:int(a[1])]
    c = b.count('AC')
    print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(Q):

    L = (list(map(int,input().split())))
    M = S[L[0]-1:L[1]]
    print(M.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
s = input()
l_to_r = [list(map(int, input().split())) for _ in range(Q)]

for qq in range(Q):
    left = l_to_r[qq][0]-1
    right = l_to_r[qq][1]-1
    counter = 0
    for i in range(right - left):
        if s[left+i:left+i+2] == 'AC':
            counter += 1
    print(counter)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
s = input()
l_to_r = [list(map(int, input().split())) for _ in range(Q)]

for qq in range(Q):
    left = l_to_r[qq][0]-1
    right = l_to_r[qq][1]-1
    counter = 0
    for i in range(right - left):
        if s[left+i] == 'A' and s[left+i+1] == 'C':
            counter += 1
    print(counter)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
s = input()
k = 0

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
s = input()
k = 0

for i in range(Q):
	l, r = map(int, input().split())
	a = s[l - 1: r]
	for j in range(len(a) - 1):
		if (a[j] == "A"):
			if (a[j + 1] == "C"):
				k += 1
	print(k)
	k = 0

Submission status: Time Limit Exceeded

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

ac_place = [False] * N
for i in range(N - 1):
    if(S[i] == 'A' and S[i + 1] == 'C'):
        ac_place[i] = True

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

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())
    s = S[l - 1: r] 
    print(s.count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(q):
    string = s[nums[i][0]-1:nums[i][1]]
    count = 0
    for j in range(len(string)-1):
        if string[j] == 'A':
            if string[j+1] == 'C':
                count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
tmp = input()
L = int(tmp.split(" ")[0])
Q = int(tmp.split(" ")[1])
S = input()
ans = []
preans = 0

for i in range(Q) :
    tmp = input()
    left = int(tmp.split(" ")[0])
    right = int(tmp.split(" ")[1])
    for j in range(left-1,right-1) :
        test = S[j:j+2]
        if test == "AC":
            preans += 1
    ans.append(preans)
    preans = 0

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

Submission status: Time Limit Exceeded

Solution code:
#C問題  
N,Q=map(int,input().split())
S=str(input())
Slist=list(S)
LR=[list(map(int,input().split())) for i in range(Q)]
pile=[0 for i in range(N)]
for i in range(N-1):
    if Slist[i] == "A" and Slist[i+1] == "C":
        pile[i]=1
pile_sum=[0 for i in range(N)]
for i in range(N):
    pile_sum[i]=sum(pile[:i])
for i in range(Q):
    right=pile_sum[LR[i][1]-1]
    left=pile_sum[LR[i][0]-1]
    print(right-left)

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

memo = []

def main():
    N,Q = map(int,input().split())
    S = input()
    # for i in range(N-1):
    #     if S[i:i+2] == "AC":
    #         memo.append(i)
    # print(memo)

    for i in range(Q):
        li,ri = map(int,input().split())
        # count = len(memo)
        # 両方の範囲に入る最初と最後
        start = -1
        end = -1
        count = 0
        # print(li,ri)
        for i in range(li-1,ri-1):
            # print("debug"+str(i))
            if S[i] == "A" and S[i+1] == "C":
                count += 1
        #         start = i
        #         break
        # if start < 0:
        #     count = 0
        # else: 
        #     for i in reversed(range(li-1,ri+1)):
        #         if S[i-1] == "A" and S[i] == "C":
        #             end = i-1
        #             break
        #     print(start,end)
        #     count = memo.index(end) - memo.index(start) + 1


        # for i in range(len(memo)):
        #     if ac_check(i,li,ri):
        #         start = i
        #         break
        # if start < 0:
        #     count = 0
        # else:
        #     for i in reversed(range(len(memo))):
        #         if ac_check(i,li,ri):
        #             end = i
        #             break
        #     # print(start,end)
        #     count = count - (start) - (len(memo)-end) + 1
        print(count)

# def ac_check(i,li,ri):
#     if memo[i] >= li-1 and memo[i]+1 <= ri-1:
#         return True
#     return False

# def ac_check(sub_s):
#     count = 0
#     for i in range(len(sub_s)-1):
#         if sub_s[i:i+2] == "AC":
#             count += 1
#     return count


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#C問題  
N,Q=map(int,input().split())
S=str(input())
Slist=list(S)
LR=[list(map(int,input().split())) for i in range(Q)]
pile=[0 for i in range(N)]
for i in range(N-1):
    if Slist[i] == "A" and Slist[i+1] == "C":
        pile[i]=1
for i in range(Q):
    right=sum(pile[:LR[i][1]-1])
    left=sum(pile[:LR[i][0]-1])
    print(right-left)

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

memo = []

def main():
    N,Q = map(int,input().split())
    S = input()
    for i in range(N-1):
        if S[i:i+2] == "AC":
            memo.append(i)
    # print(memo)
    for i in range(Q):
        li,ri = map(int,input().split())
        count = len(memo)
        # 両方の範囲に入る最初と最後
        start = -1
        end = -1

        for i in range(len(memo)):
            if ac_check(i,li,ri):
                start = i
                break
        if start < 0:
            count = 0
        else:
            for i in reversed(range(len(memo))):
                if ac_check(i,li,ri):
                    end = i
                    break
            # print(start,end)
            count = count - (start) - (len(memo)-end) + 1

        print(count)

def ac_check(i,li,ri):
    if memo[i] >= li-1 and memo[i]+1 <= ri-1:
        return True
    return False

# def ac_check(sub_s):
#     count = 0
#     for i in range(len(sub_s)-1):
#         if sub_s[i:i+2] == "AC":
#             count += 1
#     return count


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

S = input()
AC ='AC'

for i in range(Q):
    l_i, r_i = input().split(' ')
    l_i = int(l_i)
    r_i = int(r_i)
    print(S[l_i-1:r_i].count(AC))

Submission status: Time Limit Exceeded

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

S = input()
AC ='AC'

indices = []
for i in range(Q):
    l_i, r_i = input().split(' ')
    l_i = int(l_i)
    r_i = int(r_i)
    indices.append((l_i, r_i))

for idx in indices:
    print(S[idx[0]-1:idx[1]].count(AC))

Submission status: Time Limit Exceeded

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

S = input()
AC ='AC'

indices = []
for i in range(Q):
    l_i, r_i = input().split(' ')
    indices.append((int(l_i), int(r_i)))

for idx in indices:
    print(S[idx[0]-1:idx[1]].count(AC))

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

memo = []

def main():
    N,Q = map(int,input().split())
    S = input()
    for i in range(N-1):
        if S[i:i+2] == "AC":
            memo.append(i)
    # print(memo)
    for i in range(Q):
        li,ri = map(int,input().split())
        count = 0
        # 両方の範囲に入る最初と最後
        start = -1
        end = -1

        for i in range(len(memo)):
            if ac_check(i,li,ri):
                count+=1
        #         break

        # for i in reversed(range(len(memo))):
        #     if ac_check(i,li,ri):
        #         end = i
        #         break

        # print(start,end)
        # if start < 0 
        # count = end - start

        print(count)

def ac_check(i,li,ri):
    if memo[i] >= li-1 and memo[i]+1 <= ri-1:
        return True
    return False

# def ac_check(sub_s):
#     count = 0
#     for i in range(len(sub_s)-1):
#         if sub_s[i:i+2] == "AC":
#             count += 1
#     return count


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

def main():
    N,Q = map(int,input().split())
    S = input()
    for i in range(Q):
        li,ri = map(int,input().split())
        temp = S[li-1:ri]
        # print(temp)
        print(ac_check(temp))


def ac_check(sub_s):
    count = 0
    for i in range(len(sub_s)-1):
        if sub_s[i:i+2] == "AC":
            count += 1
    return count


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline

N, Q = map(int, input().split())
str = input()
for _ in range(Q):
    l, r = map(int, input().split())
    print(str.count('AC', l-1, r))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(Q):
    li,ri = (int(j) for j in input().split())
    count=0
    for j in range(li,ri):
        if S[j-1] == 'A' and S[j] == 'C':
           count+=1
    list.append(count) 

for x in list:
    print(x)

Submission status: Time Limit Exceeded

Solution code:

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

li_flg = [0] * len(s)

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


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


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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
pl = ""
count = 0

for l, r in lr:
    for st in S[l-1:r]:
        if st == "C" and pl == "A":
            count+=1
        pl = st

    print(count)
    count=0

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(len(S)-1):
    if (S[i] +S[i+1] == 'AC'):
        num.append(i+1)

for j in range(Q):
    lq,rq = map(int,input().split())
    count = 0
    for k in num:
        if lq <= k and (k+1) <= rq:
            count += 1 
    print(count)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
S = list(input())
l = [0]*q
r = [0]*q
for i in range(q):
    l,r = map(int,input().split())
    count = 0
    for i in range(l-1,r-1): #最後にAが出ても意味ないのでr-1でカット
        if(S[i]=='A'):
            if(S[i+1]=='C'):
                count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
def ACcount(l,r):
    count = 0
    for i in range(l-1,r-1): #最後にAが出ても意味ないのでr-1でカット
        if(S[i]=='A'):
            if(S[i+1]=='C'):
                count += 1
    return count

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

for i in range(q):
    print(ACcount(l[i],r[i]))
"""

Submission status: Time Limit Exceeded

Solution code:
def ACcount(l,r):
    count = 0
    for i in range(l-1,r-1): #最後にAが出ても意味ないのでr-1でカット
        if(S[i]=='A'):
            if(S[i+1]=='C'):
                count += 1
    return count

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

for i in range(q):
    print(ACcount(l[i],r[i]))

Submission status: Time Limit Exceeded

Solution code:
import re

n, q = map(int, input().split())
s = input()
li_lr = list()
pt = re.compile('AC')

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

for l in li_lr:
    print(len(re.findall(pt, s[l[0] - 1: l[1]])))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

main()

Submission status: Time Limit Exceeded

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

S = input()

acList = list()

for c in range(0,Q-1):
    if S[c] == 'A' and S[c+1]=='C':
        acList.append(c)

for c in range(0,N):
    li,ri = map(int,input().split())
    cnt = 0
    for num in acList:
        if num < (li-1):
            continue
        elif num >= ri-1:
            break
        else:
            cnt+=1
    print(cnt)

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:
n, q = map(int, input().split())
s = input()
for i in range(q):
  start, end = map(int, input().split())
  print(s[start-1:end].count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

C = []
for i in range(0, N, 100):
  if N >= i + 101:
    C.append(S[i: i + 101].count('AC'))

for i in range(Q):
  l, r = map(int, input().split())
  if (r - 1) // 100 - (l - 1) // 100 < 2:
    ans = S[l - 1: r].count('AC')
  else:
    ans  = S[l - 1: ((l - 1) // 100) * 100 + 101].count('AC')
    for j in range((l - 1) // 100 + 1, (r - 1) // 100):
      ans += C[j]
    ans += S[((r - 1) // 100) * 100 - 1: r].count('AC')
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
def checkstr(s):
    cnt = 0
    check1 = False
    for c in s:
        if c == "A":
            check1 = True
        elif c == "C":
            if check1:
                cnt += 1
            check1 = False
        else:
            check1 = False
    return cnt

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

S = input()

for i in range(0,N):
    li,ri  = map(int, input().split())
    acCounter = checkstr(S[li-1:ri])
    print(acCounter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
argv = input().split()

n = int(argv[0])
q = int(argv[1])

s = input()

for i in range(q):
    argv = input().split()
    l = int(argv[0])
    r = int(argv[1])
    count = 0
    for k in range(r-l):
        if s[l - 1 + k] == "A" and s[l + k] == "C":
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
argv = input().split()

n = int(argv[0])
q = int(argv[1])

s = input()

for i in range(q):
    argv = input().split()
    l = int(argv[0])
    r = int(argv[1])
    count = 0
    for k in range(r-l):
        if s[l - 1 + k] == "A" and s[l + k] == "C":
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
argv = input().split()

n = int(argv[0])
q = int(argv[1])

s = input()

for i in range(q):
    argv = input().split()
    l = int(argv[0])
    r = int(argv[1])
    ss = s[l - 1:r]
    count = 0
    for k in range(len(ss) - 1):
        if ss[k: k + 2] == "AC":
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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

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'))
  T = S[l - 1: r]
  R = T.replace('AC', '')
  print((len(T) - len(R)) // 2)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n, q = [int(i) for i in input().split()]
    l = [""]*q
    r = [""]*q
    S = input()
    for i in range(q):
        l[i], r[i] = [int(j) for j in input().split()]
    for i in range(q):
        print(S[l[i] - 1 : r[i]].count('AC'))

main()

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(lambda x : int(x) ,input().split(' '))
s = input()

for x in range(0, q):
  st, ed = map(lambda x : int(x) ,input().split(' '))
  tgt = s[st - 1: ed ]
  print(tgt.count('AC'))

Submission status: Time Limit Exceeded

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

numlist = []

for x in range(0, q):
  st, ed = map(lambda x : int(x) ,input().split(' '))
  numlist.append( {'start' : st, 'end' : ed})

for x in numlist:
  tgt = s[x.get('start') - 1: x.get('end') ]
  print(tgt.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
def main():
    C = []
    n, q = [int(i) for i in (input().split())]
    *S, = input()
    for i in range(q):
        count = 0
        l, r = [int(k) for k in (input().split())]
        *T, = S[l - 1:r]
        for m in range(len(T) - 1):
            if T[m] + T[m + 1] == "AC":
                count += 1
        C.append(count)
    for g in C:
        print(g)
main()

Submission status: Time Limit Exceeded

Solution code:
nq = [int(i) for i in input().split(" ")]
s = input()

sll = []
for i in range(nq[1]):
  sll.append([int(j) for j in input().split(" ")])
  
for sl in sll :
  part = s[sl[0]-1:sl[1]]
  print(len(part.split("AC")) - 1)

Submission status: Time Limit Exceeded

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

for l,r in lr:
  l,r = int(l),int(r)
  s = S[l-1:r]
  print(s.count("AC"))

Submission status: Time Limit Exceeded

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

s = input()

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

Submission status: Time Limit Exceeded

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

s = input()

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

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:
import re
N,Q = map(int, input().split())
S = input()
for i in range(Q):
  l,r = map(int, input().split())
  #print(S[l-1:r], re.findall('AC', S[l-1:r]))
  print(len(re.findall('AC', S[l-1:r])))

Submission status: Time Limit Exceeded

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

T = "AC"

for val in range(len(lr)):
	counter = 0
	lr_part = S[lr[val][0]-1:lr[val][1]]
	counter = lr_part.count(T)
	print(counter)

Submission status: Time Limit Exceeded

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

T = "AC"

for val in range(len(lr)):
	lr_part = S[lr[val][0]-1:lr[val][1]]

	counter = 0
	for i in range(0, len(lr_part)-1):
		if lr_part[i] + lr_part[i+1] == T:
			counter += 1

	print(counter)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

i = 0
aclist = np.array([], dtype=np.uint)
while i < N-1:
    if( S[i:i+2] == "AC"):
        aclist = np.append( aclist, i+1 )
        i+=1
    i+=1
for i in range(Q):
    l, r = map(int, input().split())
    print(len( aclist[(aclist>=l) & (aclist < r)]))