Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int, input().split())
S = str(input())
L = [0] * len(S) #0はACのAでない
i = 0
while i < len(S)-1:
    if S[i] == "A":
        if S[i+1] == "C":
            L[i] = 1
            i += 1
        elif S[i+1] == "A":
            i += 1
        else:
            i += 2
    else:
        i += 1
for _ in range(Q):
    l, r = map(int, input().split())
    print(sum(L[l-1:r-1]))


Fixed submission:
N,Q = map(int, input().split())
S = str(input())
# N,Q=8,3
# S = "ACACTACG"
L = [0] * len(S) #ACのAの個数を保持
i = 0
sum_i = 0
while i < len(S)-1:
    if S[i] == "A":
        if S[i+1] == "C":
            L[i] = sum_i
            sum_i += 1
            L[i+1] = sum_i
            i += 2
        elif S[i+1] == "A":
            L[i] = sum_i
            i += 1
        else:
            L[i] = sum_i
            L[i+1] = sum_i
            i += 2
    else:
        L[i] = sum_i
        i += 1
L[len(S)-1] = sum_i
for _ in range(Q):
    l, r = map(int, input().split())
    print(L[r-1] - L[l-1])

Buggy python submission (verdict: Runtime Error):
# N,Q = map(int, input().split())
# S = str(input())
N,Q = 8,3
S = "ACACTACG"
L = [0] * len(S) #0はACのAでない
i = 0
while i < len(S)-1:
    if S[i] == "A":
        if S[i+1] == "C":
            L[i] = 1
            i += 1
        elif S[i+1] == "A":
            i += 1
        else:
            i += 2
    else:
        i += 1
for _ in range(Q):
    l, r = map(int, input().split())
    print(sum(L[l-1:r-1]))


Fixed submission:
N,Q = map(int, input().split())
S = str(input())
# N,Q=8,3
# S = "ACACTACG"
L = [0] * len(S) #ACのAの個数を保持
i = 0
sum_i = 0
while i < len(S)-1:
    if S[i] == "A":
        if S[i+1] == "C":
            L[i] = sum_i
            sum_i += 1
            L[i+1] = sum_i
            i += 2
        elif S[i+1] == "A":
            L[i] = sum_i
            i += 1
        else:
            L[i] = sum_i
            L[i+1] = sum_i
            i += 2
    else:
        L[i] = sum_i
        i += 1
L[len(S)-1] = sum_i
for _ in range(Q):
    l, r = map(int, input().split())
    print(L[r-1] - L[l-1])

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 = str(input())
# N,Q=8,3
# S = "ACACTACG"
L = [0] * len(S) #ACのAの個数を保持
i = 0
sum_i = 0
while i < len(S)-1:
    if S[i] == "A":
        if S[i+1] == "C":
            L[i] = sum_i
            sum_i += 1
            L[i+1] = sum_i
            i += 2
        elif S[i+1] == "A":
            L[i] = sum_i
            i += 1
        else:
            L[i] = sum_i
            L[i+1] = sum_i
            i += 2
    else:
        L[i] = sum_i
        i += 1
L[len(S)-1] = sum_i
for _ in range(Q):
    l, r = map(int, input().split())
    print(L[r-1] - L[l-1])

Buggy python submission (verdict: Runtime Error):
N,Q = map(int, input().split())
S = str(input())
# L = []
# R = []
for _ in range(N):
    l, r = map(int, input().split())
    print(S[l-1:r].count("AC"))
#     L.append(l)
#     R.append(r)

Fixed submission:
N,Q = map(int, input().split())
S = str(input())
# N,Q=8,3
# S = "ACACTACG"
L = [0] * len(S) #ACのAの個数を保持
i = 0
sum_i = 0
while i < len(S)-1:
    if S[i] == "A":
        if S[i+1] == "C":
            L[i] = sum_i
            sum_i += 1
            L[i+1] = sum_i
            i += 2
        elif S[i+1] == "A":
            L[i] = sum_i
            i += 1
        else:
            L[i] = sum_i
            L[i+1] = sum_i
            i += 2
    else:
        L[i] = sum_i
        i += 1
L[len(S)-1] = sum_i
for _ in range(Q):
    l, r = map(int, input().split())
    print(L[r-1] - L[l-1])