Buggy python submission (verdict: Time Limit Exceeded):
N, Q = list(map(int, input().split()))
S = input()
l = [0] * Q
r = [0] * Q
for x in range(Q):
    l[x], r[x] = list(map(int, input().split()))

isAC = [0] * len(S)
for x in range(len(S) - 1):
    if S[x] == "A" and S[x + 1] == "C":
        isAC[x] = 1

for x in range(Q):
    ans = 0
    for y in range(l[x] - 1, r[x] - 1):
        ans += isAC[y]
    print(ans)


Fixed submission:
N, Q = list(map(int, input().split()))
S = input()
l = [0] * Q
r = [0] * Q
for x in range(Q):
    l[x], r[x] = list(map(int, input().split()))

countAC = [0] * len(S)
for x in range(len(S) - 1):
    countAC[x + 1] = countAC[x]
    if S[x] == "A" and S[x + 1] == "C":
        countAC[x + 1] += 1
for x in range(Q):
    print(countAC[r[x] - 1] - countAC[l[x] - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = list(map(int, input().split()))
S = input()
l = [0] * Q
r = [0] * Q
for x in range(Q):
    l[x], r[x] = list(map(int, input().split()))

isAC = [0] * len(S)
for x in range(len(S) - 1):
    if S[x] == "A" and S[x + 1] == "C":
        isAC[x] = 1

for x in range(Q):
    ans = 0
    cut_isAC = isAC[l[x] - 1:r[x] - 1]
    for y in range(len(cut_isAC)):
        ans += cut_isAC[y]
    print(ans)


Fixed submission:
N, Q = list(map(int, input().split()))
S = input()
l = [0] * Q
r = [0] * Q
for x in range(Q):
    l[x], r[x] = list(map(int, input().split()))

countAC = [0] * len(S)
for x in range(len(S) - 1):
    countAC[x + 1] = countAC[x]
    if S[x] == "A" and S[x + 1] == "C":
        countAC[x + 1] += 1
for x in range(Q):
    print(countAC[r[x] - 1] - countAC[l[x] - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = list(map(int, input().split()))
S = input()
l = [0] * Q
r = [0] * Q
for x in range(Q):
    l[x], r[x] = list(map(int, input().split()))

isAC = [False] * len(S)
for x in range(len(S) - 1):
    if S[x] == "A" and S[x + 1] == "C":
        isAC[x] = True

for x in range(Q):
    ans = 0
    cut_isAC = isAC[l[x] - 1:r[x] - 1]
    for y in range(len(cut_isAC)):
        if cut_isAC[y]:
            ans += 1
    print(ans)


Fixed submission:
N, Q = list(map(int, input().split()))
S = input()
l = [0] * Q
r = [0] * Q
for x in range(Q):
    l[x], r[x] = list(map(int, input().split()))

countAC = [0] * len(S)
for x in range(len(S) - 1):
    countAC[x + 1] = countAC[x]
    if S[x] == "A" and S[x + 1] == "C":
        countAC[x + 1] += 1
for x in range(Q):
    print(countAC[r[x] - 1] - countAC[l[x] - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = list(map(int, input().split()))
S = input()
l = [0] * Q
r = [0] * Q
for x in range(Q):
    l[x], r[x] = list(map(int, input().split()))
for x in range(Q):
    s_tmp = S[l[x] - 1:r[x]]
    countAC = 0
    flag_A = False
    for y in range(len(s_tmp)):
        if flag_A and s_tmp[y] == 'C':
            countAC += 1
        if s_tmp[y] == 'A':
            flag_A = True
        else:
            flag_A = False
    print(countAC)


Fixed submission:
N, Q = list(map(int, input().split()))
S = input()
l = [0] * Q
r = [0] * Q
for x in range(Q):
    l[x], r[x] = list(map(int, input().split()))

countAC = [0] * len(S)
for x in range(len(S) - 1):
    countAC[x + 1] = countAC[x]
    if S[x] == "A" and S[x + 1] == "C":
        countAC[x + 1] += 1
for x in range(Q):
    print(countAC[r[x] - 1] - countAC[l[x] - 1])