Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
for i in range(q):
    l,r=map(int,input().split())
    ans=0
    for i in range(l-1,r-1):
        if s[i]=="A" and s[i+1]=='C':
            ans+=1
    print(ans)

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

ac_count=[]
ac=0

for i in range(n-1):
    if s[i:i+2]=='AC':
        ac+=1
    ac_count.append(ac)
    
for i in range(q):
    l,r=map(int,input().split())
    if l==1:
        print(ac_count[r-2])
    else:
        print(ac_count[r-2]-ac_count[l-2])

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
for i in range(q):
    l,r=map(int,input().split())
    ss=s[l-1:r]
    n=len(ss)
    ans=0
    for i in range(n-1):
        if ss[i]=="A" and ss[i+1]=='C':
            ans+=1
    print(ans)

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

ac_count=[]
ac=0

for i in range(n-1):
    if s[i:i+2]=='AC':
        ac+=1
    ac_count.append(ac)
    
for i in range(q):
    l,r=map(int,input().split())
    if l==1:
        print(ac_count[r-2])
    else:
        print(ac_count[r-2]-ac_count[l-2])

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

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

ac_count=[]
ac=0

for i in range(n-1):
    if s[i:i+2]=='AC':
        ac+=1
    ac_count.append(ac)
    
for i in range(q):
    l,r=map(int,input().split())
    if l==1:
        print(ac_count[r-2])
    else:
        print(ac_count[r-2]-ac_count[l-2])

Buggy python submission (verdict: Time Limit Exceeded):
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'))

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

ac_count=[]
ac=0

for i in range(n-1):
    if s[i:i+2]=='AC':
        ac+=1
    ac_count.append(ac)
    
for i in range(q):
    l,r=map(int,input().split())
    if l==1:
        print(ac_count[r-2])
    else:
        print(ac_count[r-2]-ac_count[l-2])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
anss = list()
for i in range(q):
    ans = 0
    ss = list()
    l,r = map(int, input().split())
    ss = s[l-1:r]
    for j in range(r-l):
        if ''.join(ss[j]+ss[j+1]) == 'AC':
            ans += 1
    anss.append(ans)
for i in range(q):
    print(anss[i])

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

ac_count=[]
ac=0

for i in range(n-1):
    if s[i:i+2]=='AC':
        ac+=1
    ac_count.append(ac)
    
for i in range(q):
    l,r=map(int,input().split())
    if l==1:
        print(ac_count[r-2])
    else:
        print(ac_count[r-2]-ac_count[l-2])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
anss = list()
for i in range(q):
    ans = 0
    ss = list()
    l,r = map(int, input().split())
    ss = s[l-1:r]
    for j in range(r-l):
        if ''.join(ss[j]+ss[j+1]) == 'AC':
            ans += 1
    anss.append(ans)
for i in range(q):
    print(anss[i])

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

ac_count=[]
ac=0

for i in range(n-1):
    if s[i:i+2]=='AC':
        ac+=1
    ac_count.append(ac)
    
for i in range(q):
    l,r=map(int,input().split())
    if l==1:
        print(ac_count[r-2])
    else:
        print(ac_count[r-2]-ac_count[l-2])