Buggy python submission (verdict: Time Limit Exceeded):
import sys

input=sys.stdin.readline

N,Q=map(int,input().split())
S=input()
A=[]
B=[]
l=[]

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

for i in range(Q):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

for i in range(Q):    
    count=0
    for item in l:    
        if A[i]<=item and (item+1)<=B[i]:
            count+=1
    print(count)

Fixed submission:
import sys

input=sys.stdin.readline

N,Q=map(int,input().split())
S=input()
A=[]
B=[]
l=[0]

for _ in range(Q):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

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

for i in range(Q):
    print(l[B[i]-1]-l[A[i]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
A=[]
B=[]
l=[]

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

for i in range(Q):
    a,b=map(int,input().split())
    A.append(a-1)
    B.append(b-1) 
    
for i in range(Q):    
    count=0
    for item in l:    
        if A[i]<=item and (item+1)<=B[i]:
            count+=1
    print(count)


Fixed submission:
import sys

input=sys.stdin.readline

N,Q=map(int,input().split())
S=input()
A=[]
B=[]
l=[0]

for _ in range(Q):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

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

for i in range(Q):
    print(l[B[i]-1]-l[A[i]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
A=[]
B=[]
l=[]

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

for i in range(Q):
    a,b=map(int,input().split())
    A.append(a-1)
    B.append(b-1) 
    
for i in range(Q):    
    count=0
    for item in l:    
        if A[i]<=item and (item+1)<=B[i]:
            count+=1
    print(count)


Fixed submission:
import sys

input=sys.stdin.readline

N,Q=map(int,input().split())
S=input()
A=[]
B=[]
l=[0]

for _ in range(Q):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

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

for i in range(Q):
    print(l[B[i]-1]-l[A[i]-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

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

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

    


Fixed submission:
import sys

input=sys.stdin.readline

N,Q=map(int,input().split())
S=input()
A=[]
B=[]
l=[0]

for _ in range(Q):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

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

for i in range(Q):
    print(l[B[i]-1]-l[A[i]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=(input())

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

    


Fixed submission:
import sys

input=sys.stdin.readline

N,Q=map(int,input().split())
S=input()
A=[]
B=[]
l=[0]

for _ in range(Q):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

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

for i in range(Q):
    print(l[B[i]-1]-l[A[i]-1])