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

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

l = [None]*Q
r = [None]*Q
for i in range(Q):
    l[i], r[i] = list(map(int, input().split()))

s = list(S)
ac = [0] * N

for i in range(N-1):
    if s[i] == 'A':
        if s[i+1] == 'C':
            s[i] = "AC"
            ac[i] += 1

#ans = list(accumulate(ac))
#ans = [0] + ans


#for i in range(Q):
#    print(ans[r[i]-1]- ans[l[i]-1])
ac = [0] + ac
for i in range(Q):
    print(sum(ac[l[i]:r[i]]))

Fixed submission:
import sys  
from itertools import accumulate
input = sys.stdin.readline  

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

l = [None]*Q
r = [None]*Q
for i in range(Q):
    l[i], r[i] = list(map(int, input().split()))

s = list(S)
ac = [0] * N

for i in range(N-1):
    if s[i] == 'A':
        if s[i+1] == 'C':
            s[i] = "AC"
            ac[i] += 1

ans = list(accumulate(ac))
ans = [0] + ans


for i in range(Q):
    print(ans[r[i]-1]- ans[l[i]-1])

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

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

S.split("AC")

s = list(S)

for k in range(Q):
    z = "".join(s[l[k]-1:r[k]])
    print(len(z.split("AC"))-1)


Fixed submission:
import sys  
from itertools import accumulate
input = sys.stdin.readline  

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

l = [None]*Q
r = [None]*Q
for i in range(Q):
    l[i], r[i] = list(map(int, input().split()))

s = list(S)
ac = [0] * N

for i in range(N-1):
    if s[i] == 'A':
        if s[i+1] == 'C':
            s[i] = "AC"
            ac[i] += 1

ans = list(accumulate(ac))
ans = [0] + ans


for i in range(Q):
    print(ans[r[i]-1]- ans[l[i]-1])

Buggy python submission (verdict: Time Limit Exceeded):

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

s = list(S)

for k in range(Q):
    z = "".join(s[l[k]-1:r[k]])
    print(len(z.split("AC"))-1)





Fixed submission:
import sys  
from itertools import accumulate
input = sys.stdin.readline  

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

l = [None]*Q
r = [None]*Q
for i in range(Q):
    l[i], r[i] = list(map(int, input().split()))

s = list(S)
ac = [0] * N

for i in range(N-1):
    if s[i] == 'A':
        if s[i+1] == 'C':
            s[i] = "AC"
            ac[i] += 1

ans = list(accumulate(ac))
ans = [0] + ans


for i in range(Q):
    print(ans[r[i]-1]- ans[l[i]-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
l = [0]*Q
r = [0]*Q
for i in range(Q):
    l[i], r[i] = list(map(int, input().split()))

s = list(S)
ac = []

for i in range(N-1):
    if s[i] == 'A':
        if s[i+1] == 'C':
            s[i] = "AC"
            ac.append(i)



for i in range(Q):
    cnt = 0
    for k in ac:
        if k< r[i]-1 and k >= l[i]-1:
            cnt += 1
    print(cnt)



Fixed submission:
import sys  
from itertools import accumulate
input = sys.stdin.readline  

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

l = [None]*Q
r = [None]*Q
for i in range(Q):
    l[i], r[i] = list(map(int, input().split()))

s = list(S)
ac = [0] * N

for i in range(N-1):
    if s[i] == 'A':
        if s[i+1] == 'C':
            s[i] = "AC"
            ac[i] += 1

ans = list(accumulate(ac))
ans = [0] + ans


for i in range(Q):
    print(ans[r[i]-1]- ans[l[i]-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, Q = list(map(int, input().split()))
S = input()
l = [0]*Q
r = [0]*Q
for i in range(Q):
    l[i], r[i] = list(map(int, input().split()))

s = list(S)

for i in range(N-1):
    if s[i] == 'A':
        if s[i+1] == 'C':
            s[i] = "AC"

d = np.array(s)
tf = np.where(d=="AC", True, False)


for i in range(Q):
    print(np.sum(tf[l[i]-1:r[i]-1]))

Fixed submission:
import sys  
from itertools import accumulate
input = sys.stdin.readline  

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

l = [None]*Q
r = [None]*Q
for i in range(Q):
    l[i], r[i] = list(map(int, input().split()))

s = list(S)
ac = [0] * N

for i in range(N-1):
    if s[i] == 'A':
        if s[i+1] == 'C':
            s[i] = "AC"
            ac[i] += 1

ans = list(accumulate(ac))
ans = [0] + ans


for i in range(Q):
    print(ans[r[i]-1]- ans[l[i]-1])