Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
# lr = [list(map(int, input().split())) for i in range(q)]

idx = [s[i:i+2] == "AC" for i in range(n-1)]
idx2 = [sum(idx[:i]) for i in range(n)]

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



Fixed submission:
n,q = map(int, input().split())
s = input()
# lr = [list(map(int, input().split())) for i in range(q)]

idx = [0] * n

# idx = [idx[i-1]+int(s[i-1:i+1] == "AC") for i in range(1, n)]
for i in range(1,n):
    idx[i] = idx[i-1] + (s[i-1:i+1] == "AC")


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

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
# lr = [list(map(int, input().split())) for i in range(q)]

idx = [s[i:i+2] == "AC" for i in range(n-1)]
idx2 = [sum(idx[:i]) for i in range(n)]

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



Fixed submission:
n,q = map(int, input().split())
s = input()
# lr = [list(map(int, input().split())) for i in range(q)]

idx = [0] * n

# idx = [idx[i-1]+int(s[i-1:i+1] == "AC") for i in range(1, n)]
for i in range(1,n):
    idx[i] = idx[i-1] + (s[i-1:i+1] == "AC")


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

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for i in range(q)]

idx = [s[i:i+2] == "AC" for i in range(n-1)]
idx2 = [sum(idx[:i]) for i in range(n)]

for i in range(q):
    print(idx2[lr[i][1]-1]-idx2[lr[i][0]-1])



Fixed submission:
n,q = map(int, input().split())
s = input()
# lr = [list(map(int, input().split())) for i in range(q)]

idx = [0] * n

# idx = [idx[i-1]+int(s[i-1:i+1] == "AC") for i in range(1, n)]
for i in range(1,n):
    idx[i] = idx[i-1] + (s[i-1:i+1] == "AC")


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

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for i in range(q)]

idx = [s[i:i+2] == "AC" for i in range(n-1)]

for i in range(q):
    print(sum(idx[lr[i][0]-1:lr[i][1]-1]))


Fixed submission:
n,q = map(int, input().split())
s = input()
# lr = [list(map(int, input().split())) for i in range(q)]

idx = [0] * n

# idx = [idx[i-1]+int(s[i-1:i+1] == "AC") for i in range(1, n)]
for i in range(1,n):
    idx[i] = idx[i-1] + (s[i-1:i+1] == "AC")


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

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for i in range(q)]

idx = [0] * (n-1)

for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        idx[i] = 1

for i in range(q):
    print(sum(idx[lr[i][0]-1:lr[i][1]-1]))



Fixed submission:
n,q = map(int, input().split())
s = input()
# lr = [list(map(int, input().split())) for i in range(q)]

idx = [0] * n

# idx = [idx[i-1]+int(s[i-1:i+1] == "AC") for i in range(1, n)]
for i in range(1,n):
    idx[i] = idx[i-1] + (s[i-1:i+1] == "AC")


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

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for i in range(q)]

idx = [0] * (n-1)

for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        idx[i] = 1

for i in range(q):
    print(sum(idx[lr[i][0]-1:lr[i][1]-1]))



Fixed submission:
n,q = map(int, input().split())
s = input()
# lr = [list(map(int, input().split())) for i in range(q)]

idx = [0] * n

# idx = [idx[i-1]+int(s[i-1:i+1] == "AC") for i in range(1, n)]
for i in range(1,n):
    idx[i] = idx[i-1] + (s[i-1:i+1] == "AC")


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