Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S=list(input())
list=[]
for i in range(0, N-1):
    if S[i] == "A" and S[i+1] == "C":
        list.append(i)
count=0
for i in range(Q):
    l, r = map(int, input().split())
    for j in list:
        if l-1 <= j < r-1:
            count+=1
    print(count)
    count=0

Fixed submission:
N, Q = map(int, input().split())
S = input()

ans = [0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ans[i+1] += (ans[i]+1)
    else:
        ans[i+1] = ans[i] 

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

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S=list(input())
list=[0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        list[i]+=1
count=0
for j in range(Q):
    l, r = map(int, input().split())
    print(list[l-1:r-1].count(1))

Fixed submission:
N, Q = map(int, input().split())
S = input()

ans = [0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ans[i+1] += (ans[i]+1)
    else:
        ans[i+1] = ans[i] 

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

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S=list(input())
list=[0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        list[i]+=1
count=0
for j in range(Q):
    l, r = map(int, input().split())
    print(list[l-1:r-1]).count(1))

Fixed submission:
N, Q = map(int, input().split())
S = input()

ans = [0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ans[i+1] += (ans[i]+1)
    else:
        ans[i+1] = ans[i] 

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

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S=list(input())
list=[0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        list[i]+=1
count=0
for j in range(Q):
    l, r = map(int, input().split())
    print(sum(list[l-1:r-1]))

Fixed submission:
N, Q = map(int, input().split())
S = input()

ans = [0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ans[i+1] += (ans[i]+1)
    else:
        ans[i+1] = ans[i] 

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

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S=list(input())
list=[]
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        list.append[i]
lis=[]
count=0
for j in range(Q):
    l, r = map(int, input().split())
    for h in range(l-1, r-2):
        lis.append(h)
        count+=len(set(list) & set(lis))
print(count)

Fixed submission:
N, Q = map(int, input().split())
S = input()

ans = [0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ans[i+1] += (ans[i]+1)
    else:
        ans[i+1] = ans[i] 

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

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S=list(input())
list=[]
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        list.append[i]
lis=[]
count=0
for j in range(Q):
    l, r = map(int, input().split())
    for h in range(l-1, r+1):
        lis.append(h)
        count+=len(set(list) & set(lis))
print(count)

Fixed submission:
N, Q = map(int, input().split())
S = input()

ans = [0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ans[i+1] += (ans[i]+1)
    else:
        ans[i+1] = ans[i] 

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

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S=list(input())
list=[]
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        list.append[i]
lis=[]
for j in range(Q):
    l, r = map(int, input().split())
    for h in range(l-1, r+1):
        lis.append(h)
        count+=len(set(list) & set(lis))
print(count)

Fixed submission:
N, Q = map(int, input().split())
S = input()

ans = [0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ans[i+1] += (ans[i]+1)
    else:
        ans[i+1] = ans[i] 

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