Buggy python submission (verdict: Time Limit Exceeded):
import os, sys, re, math

(N, Q) = [int(n) for n in input().split()]
S = input()

oc = []
for i in range(len(S) - 1):
    if S[i:i+2] == 'AC':
        oc.append(i)

for i in range(Q):
    (l, r) = [int(n) for n in input().split()]
    print(len(list(filter(lambda x:x >= l - 1 and x < r - 1, oc))))


Fixed submission:
import os, sys, re, math

(N, Q) = [int(n) for n in input().split()]
S = input()

oc = [0]
n = 0
for i in range(len(S) - 1):
    if S[i:i+2] == 'AC':
        n += 1
    oc.append(n)
oc.append(n)

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

Buggy python submission (verdict: Time Limit Exceeded):
import os, sys, re, math

(N, Q) = [int(n) for n in input().split()]
S = input()

oc = []
for i in range(len(S) - 1):
    if S[i:i+2] == 'AC':
        oc.append(i)

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

for i in range(Q):
    print(len(list(filter(lambda x:x >= L[i] and x < R[i], oc))))


Fixed submission:
import os, sys, re, math

(N, Q) = [int(n) for n in input().split()]
S = input()

oc = [0]
n = 0
for i in range(len(S) - 1):
    if S[i:i+2] == 'AC':
        n += 1
    oc.append(n)
oc.append(n)

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

Buggy python submission (verdict: Time Limit Exceeded):
import os, sys, re, math

(N, Q) = [int(n) for n in input().split()]
S = input()

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

for i in range(Q):
    count = 0
    for j in range(L[i], R[i]):
        if S[j] == 'A' and S[j + 1] == 'C':
            count += 1
    print(count)


Fixed submission:
import os, sys, re, math

(N, Q) = [int(n) for n in input().split()]
S = input()

oc = [0]
n = 0
for i in range(len(S) - 1):
    if S[i:i+2] == 'AC':
        n += 1
    oc.append(n)
oc.append(n)

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

Buggy python submission (verdict: Time Limit Exceeded):
import os, sys, re, math

(N, Q) = [int(n) for n in input().split()]
S = input()

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

memo = {}
for i in range(Q):
    if (L[i], R[i]) in memo:
        print(memo[(L[i], R[i])])
        continue
    substr = S[L[i]:R[i]]
    replaced = substr.replace('AC', '')
    oc = (len(substr) - len(replaced)) >> 1
    print(oc)
    memo[(L[i], R[i])] = oc


Fixed submission:
import os, sys, re, math

(N, Q) = [int(n) for n in input().split()]
S = input()

oc = [0]
n = 0
for i in range(len(S) - 1):
    if S[i:i+2] == 'AC':
        n += 1
    oc.append(n)
oc.append(n)

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

Buggy python submission (verdict: Time Limit Exceeded):
import os, sys, re, math

(N, Q) = [int(n) for n in input().split()]
S = input()

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

for i in range(Q):
    substr = S[L[i]:R[i]]
    replaced = re.sub('AC', '', substr)
    print((len(substr) - len(replaced)) >> 1)


Fixed submission:
import os, sys, re, math

(N, Q) = [int(n) for n in input().split()]
S = input()

oc = [0]
n = 0
for i in range(len(S) - 1):
    if S[i:i+2] == 'AC':
        n += 1
    oc.append(n)
oc.append(n)

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

Buggy python submission (verdict: Time Limit Exceeded):
import os, sys, re, math

(N, Q) = [int(n) for n in input().split()]
S = input()

for i in range(Q):
    (l, r) = [int(n) for n in input().split()]
    substr = S[l - 1:r]
    replaced = re.sub('AC', '', substr)
    print((len(substr) - len(replaced)) // 2)


Fixed submission:
import os, sys, re, math

(N, Q) = [int(n) for n in input().split()]
S = input()

oc = [0]
n = 0
for i in range(len(S) - 1):
    if S[i:i+2] == 'AC':
        n += 1
    oc.append(n)
oc.append(n)

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