Buggy python submission (verdict: Time Limit Exceeded):
import sys


input = sys.stdin.readline

N, Q = map(int, input().split())
S = input()
qlist = [(int(n)-1 for n in input().split()) for _ in range(Q)]
for l, r in qlist:
    count = 0
    while l < r:
        if S[l]+S[l+1] == "AC":
            count += 1
        if S[l+1] ==  "A":
            l += 1
        else:
            l += 2
        if S[r-1]+S[r] == "AC":
            count += 1
        if S[r-1] == "C":
            r -= 1
        else:
            r -= 2

    print(count)

Fixed submission:
import sys


input = sys.stdin.readline

N, Q = map(int, input().split())
S = list(input())
anum = [0]*N
for i in range(1, N):
    if S[i-1] == "A" and S[i] == "C":
        S[i-1] = "a"
        anum[i] += 1
    anum[i] += anum[i-1]
qnum = [map(int, input().split()) for _ in range(Q)]
for l, r in qnum:
    print(anum[r-1]-anum[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys


input = sys.stdin.readline

N, Q = map(int, input().split())
S = input()
qlist = [(int(n)-1 for n in input().split()) for _ in range(Q)]
for l, r in qlist:
    count = 0
    while l < r:
        if S[l]+S[l+1] == "AC":
            count += 1
        if S[l+1] ==  "A":
            l += 1
        else:
            l += 2
        if S[r-1]+S[r] == "AC":
            count += 1
        if S[r-1] == "C":
            r -= 1
        else:
            r -= 2

    print(count)

Fixed submission:
import sys


input = sys.stdin.readline

N, Q = map(int, input().split())
S = list(input())
anum = [0]*N
for i in range(1, N):
    if S[i-1] == "A" and S[i] == "C":
        S[i-1] = "a"
        anum[i] += 1
    anum[i] += anum[i-1]
qnum = [map(int, input().split()) for _ in range(Q)]
for l, r in qnum:
    print(anum[r-1]-anum[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys


input = sys.stdin.readline

N, Q = map(int, input().split())
S = input()
qlist = [(int(n)-1 for n in input().split()) for _ in range(Q)]
for l, r in qlist:
    count = 0
    while l < r:
        if S[l]+S[l+1] == "AC":
            count += 1
        if S[r-1]+S[r] == "AC":
            count += 1
        l += 1
        r -= 1
    print(count)

Fixed submission:
import sys


input = sys.stdin.readline

N, Q = map(int, input().split())
S = list(input())
anum = [0]*N
for i in range(1, N):
    if S[i-1] == "A" and S[i] == "C":
        S[i-1] = "a"
        anum[i] += 1
    anum[i] += anum[i-1]
qnum = [map(int, input().split()) for _ in range(Q)]
for l, r in qnum:
    print(anum[r-1]-anum[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys


input = sys.stdin.readline

N, Q = map(int, input().split())
S = input()
qlist = [(int(n)-1 for n in input().split()) for _ in range(Q)]
for l, r in qlist:
    count = 0
    while l < r:
        if S[l]+S[l+1] == "AC":
            count += 1
        if S[r-1]+S[r] == "AC":
            count += 1
        l += 1
        r -= 1
    print(count)

Fixed submission:
import sys


input = sys.stdin.readline

N, Q = map(int, input().split())
S = list(input())
anum = [0]*N
for i in range(1, N):
    if S[i-1] == "A" and S[i] == "C":
        S[i-1] = "a"
        anum[i] += 1
    anum[i] += anum[i-1]
qnum = [map(int, input().split()) for _ in range(Q)]
for l, r in qnum:
    print(anum[r-1]-anum[l-1])