Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()
L = set()
for i in range(n-1):
    if s[i:i+2] == "AC":
        L.add(i+1)

for i in range(q):
    l,r = map(int,input().split())
    print(len([i for i in L if l <= i and i < r]))


Fixed submission:
n,q = map(int,input().split())
s = input().replace("AC","aC")
L = [0]*n
cnt = 0
for i in range(1,n):
    if s[i-1] == "a":
        cnt += 1
    L[i]=cnt
        
for i in range(q):
    l,r = map(int,input().split())
    print(L[r-1] - L[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()
L = [0]*n
for i in range(n-1):
    if s[i:i+2] == "AC":
        L[i] = 1

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


Fixed submission:
n,q = map(int,input().split())
s = input().replace("AC","aC")
L = [0]*n
cnt = 0
for i in range(1,n):
    if s[i-1] == "a":
        cnt += 1
    L[i]=cnt
        
for i in range(q):
    l,r = map(int,input().split())
    print(L[r-1] - L[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input().replace("AC","aC")
L = [0]*n
for i in range(n):
    if s[i] == "a":
        L[i] = 1

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


Fixed submission:
n,q = map(int,input().split())
s = input().replace("AC","aC")
L = [0]*n
cnt = 0
for i in range(1,n):
    if s[i-1] == "a":
        cnt += 1
    L[i]=cnt
        
for i in range(q):
    l,r = map(int,input().split())
    print(L[r-1] - L[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input().replace("AC","aC")

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

Fixed submission:
n,q = map(int,input().split())
s = input().replace("AC","aC")
L = [0]*n
cnt = 0
for i in range(1,n):
    if s[i-1] == "a":
        cnt += 1
    L[i]=cnt
        
for i in range(q):
    l,r = map(int,input().split())
    print(L[r-1] - L[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n,q = map(int,input().split())
s = input()
lr = [list(map(int,input().split())) for _ in range(q)]
ac_l = []
for i in range(n-1):
    if s[i:i+2] == "AC":ac_l.append(i+1)
ac = np.array(ac_l)

for i in range(q):
    print(np.sum(lr[i][0] <= ac) - np.sum(lr[i][1] <= ac))

Fixed submission:
n,q = map(int,input().split())
s = input().replace("AC","aC")
L = [0]*n
cnt = 0
for i in range(1,n):
    if s[i-1] == "a":
        cnt += 1
    L[i]=cnt
        
for i in range(q):
    l,r = map(int,input().split())
    print(L[r-1] - L[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()
lr = [list(map(int,input().split())) for _ in range(q)]
for i in range(q):
    print(s[lr[i][0]-1:lr[i][1]].count("AC"))

Fixed submission:
n,q = map(int,input().split())
s = input().replace("AC","aC")
L = [0]*n
cnt = 0
for i in range(1,n):
    if s[i-1] == "a":
        cnt += 1
    L[i]=cnt
        
for i in range(q):
    l,r = map(int,input().split())
    print(L[r-1] - L[l-1])

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

Fixed submission:
n,q = map(int,input().split())
s = input().replace("AC","aC")
L = [0]*n
cnt = 0
for i in range(1,n):
    if s[i-1] == "a":
        cnt += 1
    L[i]=cnt
        
for i in range(q):
    l,r = map(int,input().split())
    print(L[r-1] - L[l-1])

Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())
s = input()
for i in range(n):
    l,r = map(int,input().split())
    print(s[l-1:r].count("AC"))

Fixed submission:
n,q = map(int,input().split())
s = input().replace("AC","aC")
L = [0]*n
cnt = 0
for i in range(1,n):
    if s[i-1] == "a":
        cnt += 1
    L[i]=cnt
        
for i in range(q):
    l,r = map(int,input().split())
    print(L[r-1] - L[l-1])