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()
lr_list = [list(map(int,input().split())) for nesya in range(q)]
for lr in lr_list:
  hoge = s[lr[0]-1:lr[1]]
  print(hoge.count('AC'))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = list(map(str, input()))
# print(s)
for i in range(q):
    l, r = map(int, input().split())
    count = 0
    end = r
    while l < r:
        if s[l-1] + s[l] == "AC":
            count += 1
        l += 1
    print(count)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
Z=''
A=[]
for i in range(Q):
    cnt=0
    l,r=map(int,input().split())
    Z=S[l-1:r]
    for t in range(len(Z)-1):
        if Z[t:t+2]=='AC':
            cnt+=1
        else:
            continue
    A.append(cnt)
for a in A:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=str(input())
AC_list=[0]*N
for i in range(1,N):
  if S[i]=='C' and S[i-1]=='A':
    AC_list[i]=1
ans=0
for i in range(Q):
  l,r=map(int,input().split())
  ans=sum(AC_list[l:r])
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=str(input())
AC_list=[]
for i in range(1,N):
  if S[i]=='C' and S[i-1]=='A':
    AC_list.append([i,i+1])
ans=0
for i in range(Q):
  ans=0
  l,r=map(int,input().split())
  for j in AC_list:
    if l<=j[0] and j[1]<=r:
      ans+=1
  print(ans)

Submission status: Time Limit Exceeded

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

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

ans_list=[]
for i in range(Q):
    l, r = map(int, input().split())
    ans = 0
    for j in range(l-1,r-1,1):
        if arr[j] == 1:
            ans += 1
    ans_list.append(ans)

for i in range(len(ans_list)):
    print(ans_list[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"))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,q=MI()
s=input().rstrip()
lis=[]
for i in range(n-1):
    u=s[i:i+2]
    if u=="AC":
        lis.append(i+1)
#print(lis)

for i in range(q):
    a,b=MI()
    count=0
    for j in lis:
        if a<=j and b>=j+1:
            count+=1
    print(count)

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)]
cum = []
for i in range(N+1):
    cum.append(S[:i].count('AC'))
for l, r in LR:
    print(cum[r] - cum[l])

Submission status: Time Limit Exceeded

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

for _ in range(Q):
    li, ri = map(int, input().split())
    sliced_S = str(S[li-1:ri])
    sliced_S = sliced_S.replace("AC", "@")
    print(sliced_S.count("@"))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys

def main():
    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'))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# ABC122C

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 = 0
    for j in range(len(t)-1):
        if t[j:j+2] == 'AC':
            count += 1
    print(count)

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

ac_li = []
for i in range(n-1):
    if s[i] + s[i+1] == "AC":
        ac_li.append([i, i+1])
#print(ac_li)
for i in range(q):
    ans = 0
    l, r = map(int, input().split())
    for j in ac_li:
        if set(range(l-1, r)) & set(j) == set(j):
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
l, r = [0]*q, [0]*q
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()

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

Submission status: Time Limit Exceeded

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

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

for i in range(q):
    print(s[r[i]:l[i]].count('AC'))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = str(input())
for i in range(Q):
    l, r = map(int, input().split())
    cnt = int()
    tmp = S[l-1:r]
    # print(tmp)
    for j in range(r-l):
        if tmp[j:j+2] == 'AC':
            cnt += 1

    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n, q = [int(x) for x in input().split()]
s = input()
for _ in range(q):
    l, r = [int(x) for x 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()
lr=[[0]*2 for i in range(q)]
for i in range(q):
    lr[i]=list(map(int,input().split()))
    
for lri in lr:
    print(s[lri[0]-1:lri[1]].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n, q = [int(i) for i in input().split()]
s = input()
m = [0] * (len(s) - 1)
for i in range(len(m)):
    if s[i] + s[i+1] == "AC": m[i] = 1

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

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, Q = MAP()
S = input()
lr = [LIST() for _ in range(Q)]

for i in range(Q):
	SS = S[lr[i][0]-1:lr[i][1]]
	cnt = 0
	for j in range(lr[i][1]-lr[i][0]):
		if SS[j] == "A" and SS[j+1] =="C":
			cnt += 1
	print(cnt)

Submission status: Time Limit Exceeded

Solution code:

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

lr = [list(map(int,input().split())) for i in range(q)]

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

Submission status: Time Limit Exceeded

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

for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        cnt_AC[i] += 1

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

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(1)
  else:
    ac.append(0)
for j in range(q):
  l,r = map(int, input().split())
  if r == q:
    r -= 1
  ls = ac[l-1:r-1]
  print(ls.count(1))

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(1)
  else:
    ac.append(0)
for j in range(q):
  l,r = map(int, input().split())
  if r == q:
    r -= 1
  ls = ac[l-1:r-1]
  print(sum(ls))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n, q = MI()
    S = input()
    for _ in range(q):
        l, r = MI1()
        s = S[l:r+1]
        # print(s, s.count('AC'))
        print(s.count('AC'))

if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
def get_ac(n, q, s, lrli):

    ans = []
    for i in lrli:
        ans.append(s[i[0]-1:i[1]].count("AC"))

    return ans

def main():
    n, q = map(int, input().split())
    s = str(input())
    lrli = [list(map(int, input().split()))for i in range(q)]
    ans = get_ac(n, q, s, lrli)
    for i in ans:
        print(i)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def get_ac(n, q, s, lrli):

    ans = []
    for i in lrli:
        ans.append(s[i[0]-1:i[1]].count("AC"))

    return ans

def main():
    n, q = map(int, input().split())
    s = str(input())
    lrli = [list(map(int, input().split()))for i in range(q)]
    ans = get_ac(n, q, s, lrli)
    for i in ans:
        print(i)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N,M = list(map(int,input().split()))
l_n = list(input())
for i in range(N-1):
    if l_n[i] == "A" and l_n[i+1] == "C":
        l_n[i] = "a"
for i in range(M):
    B = list(map(int,input().split()))
    C = l_n[B[0]-1:B[1]-1].count("a")
    print(C)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
A = []
B = [0]*Q
for n in range(N-1):
    if S[n:n+2] == "AC":
        A.append(n)
for n in range(Q):
    l, r = map(int, input().split())
    for m in range(len(A)):
        if A[m] >= l-1:
            if A[m] <= r-2:
                B[n] += 1
            else:
                break;
for n in range(Q):
    print(B[n])

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
A = []
B = [0]*Q
for n in range(N-1):
    if S[n:n+2] == "AC":
        A.append(n)
for n in range(Q):
    l, r = map(int, input().split())
    for m in range(len(A)):
        if A[m] >= l-1 and A[m] <= r-2:
            B[n] += 1
for n in range(Q):
    print(B[n])

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
A = [0]*(N-1)
B = []
for n in range(N-1):
    if S[n:n+2] == "AC":
        A[n] += 1
for n in range(Q):
    l, r = map(int, input().split())
    B.append(sum(A[l-1:r-1]))
for n in range(Q):
    print(B[n])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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 = [0]*Q
r = [0]*Q
for i in range(Q):
    l[i], r[i] = map(int,input().split())

def ATcounter(instr):
    ans = 0
    flg = 0
    for i in range(len(instr)):
        if instr[i] == 'A':
            flg = 1
        elif instr[i] == 'C' and flg == 1:
            ans += 1
            flg = 0
        else:
            flg = 0
    return ans

for i in range(Q):
    print(ATcounter(S[l[i]-1:r[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())
    cnt = s[l-1:r].count("AC")
    print(cnt)

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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
list = []
for i in range(N):
    if S[i:i+2] == 'AC':
        list.append(i)
count = 0
for i in range(Q): #l,rをそれぞれ代入
    l, r = map(int, input().split())
    for k in list: 
        if l-1 <= k <= r-1 and l-1 <= k+1 <= r-1:
            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):
    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 = [list(map(int, input().split())) for i in range(Q)]
for i in range(Q):
    print(S[lr[i][0]-1:lr[i][1]].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
def ans(a,b):
  a=b[a[0]-1:a[1]]
  ar=0
  an=0
  for i in a:
    if i=="A":
      ar=1
    else:
      if ar==1 and i=="C":
      	an+=1
      	ar=0
      elif ar==1 and i!="C":
      	ar=0
  print(an)

a,b=map(int,input().split())
st=input()
lis=[list(map(int,input().split())) for i in range(b)]
for i in lis:
  ans(i,st)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
L = []
R = []
B = []
for _ in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

for a, b in zip(L,R):
    A = S[a-1:b]
    print(A.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
L = []
R = []
B = []
for _ in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

for a, b in zip(L,R):
    A = S[a-1:b]
    B.append(A.count("AC"))

for b in B:
    print(b)

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:
#2問目
NQ = input().split()
N,Q = int(NQ[0]), int(NQ[1])
S = input()
Answer = ""
P = [input().split() for i in range(Q)]
for i in range(Q):
    Answer += str(S.count("AC", int(P[i][0])-1, int(P[i][1]))) + "\n"
print(Answer)

Submission status: Time Limit Exceeded

Solution code:
#2問目
NQ = input().split()
N,Q = int(NQ[0]), int(NQ[1])
S = input()
P = [input().split() for i in range(Q)]
for i in range(Q):
    print(S.count("AC", int(P[i][0])-1, int(P[i][1])))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
import itertools


def sr():
    return sys.stdin.readline().rstrip()


def ir():
    return int(sr())


def lr():
    return list(map(int, sr().split()))


N, Q = lr()
S = sr()

ac = [0] * (N - 1)
for i, x in enumerate(zip(S[:], S[1:])):
    if x[0] == 'A' and x[1] == 'C':
        ac[i] = 1

for _ in range(Q):
    l, r = lr()
    print(sum(ac[l - 1: r - 1]))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split(' '))
S = input()
ans = 0
ans_list = []
for i in range(Q):
    l, r = map(int, input().split(' '))
    s = S[l - 1: r]
    cnt = 0
    for i in range(1, len(s), 2):
        if (i + 1) == len(s):
            break
        if s[i] == 'A':
            if s[i + 1] == 'C':
                cnt += 1
        elif s[i] == 'C':
            if s[i - 1] == 'A':
                cnt += 1
    ans_list.append(cnt)
[print(ans) for ans in ans_list]

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys


def main():
    input = sys.stdin.readline
    n, q = map(int, input().split())
    s = input()
    li = [map(int, input().split()) for i in range(q)]

    for i, j in li:
        count = 0
        for k in range(i-1, j-1):
            if s[k:k+2] == "AC":
                count += 1
        print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys


def main():
    input = sys.stdin.readline
    n, q = map(int, input().split())
    s = input()
    li = [map(int, input().split()) for i in range(q)]

    for i, j in li:
        count = 0
        cache = s[i-1]
        for k in range(i, j):
            if cache == "A" and s[k] == "C":
                count += 1
            cache = s[k]
        print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys


def main():
    input = sys.stdin.readline
    n, q = map(int, input().split())
    s = input()
    li = [list(map(int, input().split())) for i in range(q)]

    for i, j in li:
        count = 0
        cache = s[i-1]
        for k in range(i, j):
            if cache == "A" and s[k] == "C":
                count += 1
            cache = s[k]
        print(count)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

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

A.append(0)
print

for i in range(Q):
	l = int(lr[i][0])
	r = int(lr[i][1])
	if A[r-1] == 1:
		r -= 1
	print(A[l-1 :r].count(1))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = list(input())
holder = []
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        holder.append(i)
for _ in range(Q):
    l, r = map(int, input().split())
    count = 0
    for index in holder:
        if index+1 >= l and index+2 <= r:
            count += 1
    print(count)

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())
    line = S[l-1:r]
    count = 0
    for i in range(r-l):
        if line[i] == 'A' and line[i+1] == 'C':
            count += 1
    print(count)

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 l,r in lr:
  l -= 1
  print(S[l:r].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n, q = [int(i) for i in input().split()]
s = input()
m = [0] * (len(s) - 1)
for i in range(len(m)):
    if s[i:i+2] == "AC": m[i] = 1

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

Submission status: Time Limit Exceeded

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

for k in range(N):
  List[k] = S[:k+1].count("AC")
  
for i in range(Q):
  l , r = map(int, input().split())
  print(List[r-1]-List[l-1])

Submission status: Time Limit Exceeded

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

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 i in range(q):
  t=s[lr[i][0]-1:lr[i][1]]
  print(t.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
a_list = []
for i in range(len(s)-1):
    if (s[i] == 'A') and (s[i+1] == 'C'):
        a_list.append(i)
    
for i in range(q):
    cnt = 0
    l,r =  map(int,input().split())
    for j in a_list:
        if j+1 in range(l,r+1) and  j+2 in range(l,r+1):
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys


input = sys.stdin.readline

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

    print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys


input = sys.stdin.readline

N, Q = map(int, input().split())
S = input()
qlist = [(int(n)-1 for n in input().split()) for _ in range(Q)]
for l, r in qlist:
    count = 0
    while l < r:
        if S[l]+S[l+1] == "AC":
            count += 1
        if S[r-1]+S[r] == "AC":
            count += 1
        l += 1
        r -= 1
    print(count)

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

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

for i in range(Q):
  print(sum(dp[lr[i][0]:lr[i][1]]))

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

for i in range(Q):
  ans = S[lr[i][0]-1:lr[i][1]].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())
  print(S[l-1:r].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import re
from collections import Counter
n, q = map(int, input().split())
s = input()
word = re.findall('AC', s)
C1 = Counter(word)
for _ in range(q):
    l, r = map(int, input().split())
    C2 = Counter(re.findall('AC', s[:l]))
    C3 = Counter(re.findall('AC', s[r-1:]))
    print(C1['AC']-(C2['AC']+C3['AC']))

Submission status: Time Limit Exceeded

Solution code:
import re
from collections import Counter
n, q = map(int, input().split())
s = input()
for _ in range(q):
    l, r = map(int, input().split())
    word = re.findall('AC', s[l-1:r])
    C = Counter(word)
    print(C['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())
    print(s[l-1:r].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,q = readInts()
    s = input()
    LR = []
    for i in range(q):
        l,r = readInts()
        #print(LR)
        LR.append((l,r))
    for i in range(q):
        #print(i)
        l,r = LR[i]
        l -=1 # zero based index
        S = s[l:r]
        print(S.count('AC'))

if __name__ == '__main__':
  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(int, input().split())
s = input()
ans = [0 for _ in range(n)]
for i in range(len(s) - 1):
    if s[i] == "A" and s[i + 1] == "C":
        ans[i] = 1
for j in range(q):
    l, r = map(int, input().split())
    print(sum(ans[l - 1:r - 1]))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int,input().split())
S = list(input())
lr = [list(map(int,input().split())) for i in range(Q)]
ans = ''
skip = 0
for i in range(N-1):
  if skip == 0:
    if S[i] + S[i+1] == 'AC':
      ans += '12'
      skip = 1
    else:
      ans += '0'
  else:
    skip = 0
  
  if i == N - 2:
    ans += '0'
else:
  for i in range(Q):
    l = lr[i][0]
    r = lr[i][1]
    string = ans[l-1:r]
    print(string.count('12'))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int, input().split())
s=input()
ans=[]
for i in range(q):
    a,b=map(int, input().split())
    ans.append((s[a-1:b].count("AC")))

for i in ans:
    print(i)

Submission status: Time Limit Exceeded

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

for i in range(len(s)-1):
    if s[i] == "A" and s[i+1] == "C":
        ans[i] = 1
for k in range(q):
    print(sum(ans[l[k] - 1:r[k] - 1]))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n, q = map(int,input().split())
s = input()

tmp = [0 for _ in range(n)]
for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        tmp[i] = 1
        tmp[i + 1] = 3
#print(tmp)

for i in range(q):
    l, r = map(int,input().split())
    ans = sum(tmp[l-1:r])
    if tmp[l-1] == 3:
        ans -= 3
    if tmp[r-1] == 1:
        ans -= 1
    print(ans // 4)

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 = list(map(int, input().split()))
S = list(input())
l = []
r = []
for _ in range(Q):
    L,R = list(map(int, input().split()))
    l.append(L)
    r.append(R)
flag = False
ac = [0]*N

for j in range(N):
        if S[j] == 'A':
            flag = True
            continue
        if S[j] == 'C' and flag:
            ac[j] += 1
        flag = False


for i in range(Q):
    print(sum(ac[l[i]:r[i]]))

Submission status: Time Limit Exceeded

Solution code:
N,Q = list(map(int, input().split()))
S = list(input())
l = []
r = []
for _ in range(Q):
    L,R = list(map(int, input().split()))
    l.append(L)
    r.append(R)
flag = False


for i in range(Q):
    count = 0
    for j in range(l[i]-1,r[i]):
        if S[j] == 'A':
            flag = True
            continue
        if S[j] == 'C' and flag:
            count += 1
        flag = False
    print(count)

Submission status: Time Limit Exceeded

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

P = [list(map(int,input().split())) for i in range(Q)]

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