Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())
l=[0]*q
r=[0]*q
for i in range(q):
        l[i],r[i]=map(int,input().split())

t=s.replace('A'+'C','*_')
a=[0]
for i in range(n):
        if t[i]=='*':
                a.append(i+1)
a.append(len(s))
for i in range(q):
        count=0
        for j in range(len(a)):
                if l[i]<=a[j]<=r[i]-1:
                        count+=1
                elif a[j]<l[i]:
                        continue
                else:
                        break
        print(count)




Fixed submission:
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())

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

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())
l=[0]*q
r=[0]*q
for i in range(q):
        l[i],r[i]=map(int,input().split())

t=s.replace('A'+'C','*_')
a=[0]
for i in range(n):
        if t[i]=='*':
                a.append(i+1)
a.append(len(s))
for i in range(q):
        count=0
        for j in range(len(a)):
                if l[i]<=a[j]<=r[i]-1:
                        count+=1
        print(count)




Fixed submission:
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())

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

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=str(input())
l=[0]*q
r=[0]*q
for i in range(q):
        l[i],r[i]=map(int,input().split())

t=s.replace('A'+'C','*_')
a=[0]
for i in range(n):
        if t[i]=='*':
                a.append(i+1)
a.append(len(s))
for i in range(q):
        count=0
        for j in range(len(a)):
                if l[i]<=a[j]<=r[i]-1:
                        count+=1
        print(count)




Fixed submission:
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())

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

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())
t=s
l=[0]*q
r=[0]*q
for i in range(q):
        l[i],r[i]=map(int,input().split())
for j in range(q):
        s=t
        print(s[l[j]-1:r[j]].count('A'+'C'))




Fixed submission:
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())

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

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())
t=s
l=[0]*q
r=[0]*q
for i in range(q):
        l[i],r[i]=map(int,input().split())
for j in range(q):
        s=t
        print(s[l[j]-1:r[j]].count('A'+'C'))




Fixed submission:
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())

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

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())
t=s
l=[0]*q
r=[0]*q
for i in range(q):
        l[i],r[i]=map(int,input().split())
for j in range(q):
        s=t
        c=s[l[j]-1:r[j]].replace('A'+'C','__')
        print(c.count('__'))




Fixed submission:
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())

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

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=str(input())
t=s
l=[0]*q
r=[0]*q
for i in range(q):
        l[i],r[i]=map(int,input().split())
for j in range(q):
        s=t
        c=s[l[j]-1:r[j]].replace('A'+'C','__')
        print(c.count('__'))




Fixed submission:
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=str(input())

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