Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int, input().split())
S = input()
count = S.count("AC")
index = []
for i in range(count):
    if i == 0:
        index.append(S.find("AC"))
    else:
        index.append(S.find("AC", i + 1))

for i in range(Q):
    num = 0
    l, r = map(int, input().split())
    for j in index:
        if l-1 <= j <= r - 2:#indexnumberに揃えて, かつACの1番目のindex番号で判定
            num += 1
    print(num)

Fixed submission:
import time
N,Q = map(int, input().split())
S = input()
AC = [0]*(N+1)

for i in range(N):
    if S[i:i+2] == "AC":
        AC[i+1] = AC[i] + 1
    else:
        AC[i+1] = AC[i]

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

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int, input().split())
S = input()
def judge_letter(letter, r, l):
    j_letter = letter[r-1 : l]
    return j_letter.count("AC")
num = []
for i in range(Q):
    l, r = map(int, input().split())
    num.append(judge_letter(S, l,r))
for j in num:
    print(j)

Fixed submission:
import time
N,Q = map(int, input().split())
S = input()
AC = [0]*(N+1)

for i in range(N):
    if S[i:i+2] == "AC":
        AC[i+1] = AC[i] + 1
    else:
        AC[i+1] = AC[i]

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

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int, input().split())
S = input()
def judge_letter(letter, r, l):
    j_letter = letter[r-1 : l]
    return j_letter.count("AC")


for i in range(Q):
    l, r = map(int, input().split())
    print(judge_letter(S, l,r))

Fixed submission:
import time
N,Q = map(int, input().split())
S = input()
AC = [0]*(N+1)

for i in range(N):
    if S[i:i+2] == "AC":
        AC[i+1] = AC[i] + 1
    else:
        AC[i+1] = AC[i]

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

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
qa = []
for i in range(Q):
    lr = [int(i) for i in input().split()]
    qa.append(lr)

for j in range(Q):
    count = 0
    start = qa[j][0]-1
    end = qa[j][1]
    string = S[start:end]
    for i in range(len(string)-1):
        if string[i:i+2] == "AC":
            count += 1
    print(count)

Fixed submission:
import time
N,Q = map(int, input().split())
S = input()
AC = [0]*(N+1)

for i in range(N):
    if S[i:i+2] == "AC":
        AC[i+1] = AC[i] + 1
    else:
        AC[i+1] = AC[i]

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

Buggy python submission (verdict: Time Limit Exceeded):
import re
N,Q = map(int,input().split())
S = input()
qa = []
for i in range(Q):
    lr = [int(i) for i in input().split()]
    qa.append(lr)

for j in range(Q):
    count = 0
    start = qa[j][0]-1
    end = qa[j][1]
    string = S[start:end]
    Re = re.findall("AC", string)
    count += len(Re)
    print(count)

Fixed submission:
import time
N,Q = map(int, input().split())
S = input()
AC = [0]*(N+1)

for i in range(N):
    if S[i:i+2] == "AC":
        AC[i+1] = AC[i] + 1
    else:
        AC[i+1] = AC[i]

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