Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
s = input()
ans = []
for i in range(Q):
    l,r = map(int,input().split())
    ss = s[l-1:r]
    ans.append(ss.count("AC"))
for i in ans:
    print(i)

Fixed submission:
N,Q = map(int,input().split())
s = input()
t = [0]
ans = []
for i in range(N):
    if s[i:i+2] == "AC":
        t.append(t[i] + 1)
    else:
        t.append(t[i])
for i in range(Q):
    l,r = map(int,input().split())
    ans.append(t[r-1]-t[l-1])
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
s = str(input())

for _ 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()
t = [0]
ans = []
for i in range(N):
    if s[i:i+2] == "AC":
        t.append(t[i] + 1)
    else:
        t.append(t[i])
for i in range(Q):
    l,r = map(int,input().split())
    ans.append(t[r-1]-t[l-1])
for i in ans:
    print(i)

Buggy python submission (verdict: Runtime Error):
N,Q = map(int,input().split())
s = str(input())

index = -1
idxs = []
while True:
    index = s.find("A", index + 1)
    if index == -1:
        break
    elif s[index + 1] == "C":
        idxs.append(index)

for i in range(Q):
    l,r = map(int,input().split())
    ans = sum(l-1 <= x <= r-2 for x in idxs)
    print(ans)

Fixed submission:
N,Q = map(int,input().split())
s = input()
t = [0]
ans = []
for i in range(N):
    if s[i:i+2] == "AC":
        t.append(t[i] + 1)
    else:
        t.append(t[i])
for i in range(Q):
    l,r = map(int,input().split())
    ans.append(t[r-1]-t[l-1])
for i in ans:
    print(i)

Buggy python submission (verdict: Runtime Error):
N,Q = map(int,input().split())
S = str(input())


idx = []

for i in range(len(S)):
        if S[i] != "A" and S[i] != "C":
            flag = 0
            continue
        if S[i] == "A":
            flag = 1
            continue
        if S[i] == "C" and flag == 1:
            flag = 0
            idx.append(i-1)
            continue
        if S[i] == "C" and flag == 0:
            continue

#print(idx)
L = []
R = []
for _ in range(Q):
    l,r = map(int,input().split())
    ans = 0
    for i in idx:
        if i in range(l-1,r-1):
            ans += 1
    print(ans)
    


Fixed submission:
N,Q = map(int,input().split())
s = input()
t = [0]
ans = []
for i in range(N):
    if s[i:i+2] == "AC":
        t.append(t[i] + 1)
    else:
        t.append(t[i])
for i in range(Q):
    l,r = map(int,input().split())
    ans.append(t[r-1]-t[l-1])
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = str(input())

for _ in range(Q):
    l,r = map(int,input().split())
    flag = 0
    cnt = 0
    for i in range(l-1,r):
        if S[i] == "A":
            flag = 1
            continue
        if S[i] == "C" and flag == 1:
            cnt += 1
            flag = 0
            continue
        if S[i] == "C" and flag == 0:
            continue
    print(cnt)


Fixed submission:
N,Q = map(int,input().split())
s = input()
t = [0]
ans = []
for i in range(N):
    if s[i:i+2] == "AC":
        t.append(t[i] + 1)
    else:
        t.append(t[i])
for i in range(Q):
    l,r = map(int,input().split())
    ans.append(t[r-1]-t[l-1])
for i in ans:
    print(i)