Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()

ans = [0] * N

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

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




Fixed submission:

N, Q = map(int, input().split())
S = list(input())
lr = []
for i in range(Q):
    l, r = map(int, input().split())
    lr.append([l-1, r-1])
AC = []
pre = None
cnt = 0
for c in S:
    if c == "A":
        pre = "A"
    elif pre == "A" and c == "C":
        cnt += 1
        pre = None
    elif pre == "A":
        pre = None
    AC.append(cnt)
for l, r in lr:
    print(AC[r] - AC[l])

Buggy python submission (verdict: Runtime Error):

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


t = [0] * (N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2]=='AC' else 0)
for i in range(Q):
    print(t[R[i]] - t[L[i]])

Fixed submission:

N, Q = map(int, input().split())
S = list(input())
lr = []
for i in range(Q):
    l, r = map(int, input().split())
    lr.append([l-1, r-1])
AC = []
pre = None
cnt = 0
for c in S:
    if c == "A":
        pre = "A"
    elif pre == "A" and c == "C":
        cnt += 1
        pre = None
    elif pre == "A":
        pre = None
    AC.append(cnt)
for l, r in lr:
    print(AC[r] - AC[l])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()

Sl1 = list(S)
Sl2 = list(S)
del Sl2[-1]

idx = [i for i, a in enumerate(Sl2) if a=="A"]

AT = [0]*N

for i in idx:
    if Sl1[i+1]=="C":
        AT[i] += 1

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


Fixed submission:

N, Q = map(int, input().split())
S = list(input())
lr = []
for i in range(Q):
    l, r = map(int, input().split())
    lr.append([l-1, r-1])
AC = []
pre = None
cnt = 0
for c in S:
    if c == "A":
        pre = "A"
    elif pre == "A" and c == "C":
        cnt += 1
        pre = None
    elif pre == "A":
        pre = None
    AC.append(cnt)
for l, r in lr:
    print(AC[r] - AC[l])

Buggy python submission (verdict: Runtime Error):



N, Q = map(int, input().split())

S = input()

for i in range(Q):
    cnt = 0
    l, r = map(int, input().split())
    T = S[l-1:r]
    for t in list(T):
        if t=="A":
            flag = True
        elif t=="T" and flag:
            cnt += 1
            flag = False
        else:
            flag = False
    print(cnt)








Fixed submission:

N, Q = map(int, input().split())
S = list(input())
lr = []
for i in range(Q):
    l, r = map(int, input().split())
    lr.append([l-1, r-1])
AC = []
pre = None
cnt = 0
for c in S:
    if c == "A":
        pre = "A"
    elif pre == "A" and c == "C":
        cnt += 1
        pre = None
    elif pre == "A":
        pre = None
    AC.append(cnt)
for l, r in lr:
    print(AC[r] - AC[l])

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()

L = []
R = []

for i in range(Q):
    l, r = map(int, input().split())
    L.append(l-1)
    R.append(r-1)

a = [0]*N
pre = ''

for i, s in enumerate(S):
    if pre=='A' and s=='C':
        a[i] = 1
    pre = s

cnt = 0
for i in range(Q):
    cnt = sum(a[:R[i]]) - sum(a[:L[i]])
	print(cnt)

Fixed submission:

N, Q = map(int, input().split())
S = list(input())
lr = []
for i in range(Q):
    l, r = map(int, input().split())
    lr.append([l-1, r-1])
AC = []
pre = None
cnt = 0
for c in S:
    if c == "A":
        pre = "A"
    elif pre == "A" and c == "C":
        cnt += 1
        pre = None
    elif pre == "A":
        pre = None
    AC.append(cnt)
for l, r in lr:
    print(AC[r] - AC[l])