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

# ACがある場所の添字（エンド）
# pos_ = []
# last = "x"
# for i, si in enumerate(S):
#     if last == "A" and si == "C":
#         pos_.append(i)
#     last = si
# print(pos_)

import re
pos = [m.start() for m in re.finditer('AC', S)]
# print(pos)

for _ in range(Q):
    l, r = map(int, input().split())
    start = l - 1
    end = r - 1
    # print(start, end)
    count = 0
    for p in pos:
        if start <= p and end >= p + 1:
            count += 1
    print(count)


Fixed submission:
N, Q = map(int, input().split())
S = input()
QS = []

l = [0, 0]
last = S[0]
for i in range(1, len(S)):
    if last == 'A' and S[i] == 'C':
        l.append(l[-1] + 1)
    else:
        l.append(l[-1])
    last = S[i]

for _ in range(Q):
    left, right = map(int, input().split())
    QS.append((left, right))

# print(l)
for left, right in QS:
    ans = l[right] - l[left]
    print(ans)

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

for _ in range(Q):
    l, r = map(int, input().split())
    print(S.count("AC", l - 1, r))
    # QS.append((l, r))
#
# for l, r in QS:
#     # print(S[l - 1:r])
#     print(S.count("AC", l - 1, r))


Fixed submission:
N, Q = map(int, input().split())
S = input()
QS = []

l = [0, 0]
last = S[0]
for i in range(1, len(S)):
    if last == 'A' and S[i] == 'C':
        l.append(l[-1] + 1)
    else:
        l.append(l[-1])
    last = S[i]

for _ in range(Q):
    left, right = map(int, input().split())
    QS.append((left, right))

# print(l)
for left, right in QS:
    ans = l[right] - l[left]
    print(ans)

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

# ACがある場所の添字（エンド）
pos = []
last = "x"
for i, si in enumerate(S):
    if last == "A" and si == "C":
        pos.append(i)
    last = si
# print(pos)

for _ in range(Q):
    l, r = map(int, input().split())
    QS.append((l, r))

for l, r in QS:
    start = l - 1
    end = r - 1
    # print(start, end)
    count = 0
    for p in pos:
        if start <= (p - 1) and end >= p:
            count += 1
    print(count)


Fixed submission:
N, Q = map(int, input().split())
S = input()
QS = []

l = [0, 0]
last = S[0]
for i in range(1, len(S)):
    if last == 'A' and S[i] == 'C':
        l.append(l[-1] + 1)
    else:
        l.append(l[-1])
    last = S[i]

for _ in range(Q):
    left, right = map(int, input().split())
    QS.append((left, right))

# print(l)
for left, right in QS:
    ans = l[right] - l[left]
    print(ans)

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

for _ in range(Q):
    l, r = map(int, input().split())
    s = S[l - 1: r]
    print(s.count("AC"))



Fixed submission:
N, Q = map(int, input().split())
S = input()
QS = []

l = [0, 0]
last = S[0]
for i in range(1, len(S)):
    if last == 'A' and S[i] == 'C':
        l.append(l[-1] + 1)
    else:
        l.append(l[-1])
    last = S[i]

for _ in range(Q):
    left, right = map(int, input().split())
    QS.append((left, right))

# print(l)
for left, right in QS:
    ans = l[right] - l[left]
    print(ans)

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

for _ in range(Q):
    l, r = map(int, input().split())
    QS.append((l, r))

ans = []
for l, r in QS:
    s = S[l - 1: r]
    print(s.count("AC"))


Fixed submission:
N, Q = map(int, input().split())
S = input()
QS = []

l = [0, 0]
last = S[0]
for i in range(1, len(S)):
    if last == 'A' and S[i] == 'C':
        l.append(l[-1] + 1)
    else:
        l.append(l[-1])
    last = S[i]

for _ in range(Q):
    left, right = map(int, input().split())
    QS.append((left, right))

# print(l)
for left, right in QS:
    ans = l[right] - l[left]
    print(ans)