Buggy python submission (verdict: Runtime Error):
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
i, c = 0, 0
while i < n:
    if s[i] == "A":
        ac[i] = c
        i += 1
        if s[i] == "C":
            c += 1
            ac[i] = c
        else: ac[i] = c
    else:
        ac[i] = c
        i += 1
print(ac)
for p in lr:
    l, r = p[0] - 1, p[1] - 1
    print(int(ac[r] - ac[l]))

Fixed submission:
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
i, c = 0, 0
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        ac[i+1] = ac[i] + 1
    else:
        ac[i+1] = ac[i]
for p in lr:
    l, r = p[0] - 1, p[1] - 1
    print(int(ac[r] - ac[l]))

Buggy python submission (verdict: Time Limit Exceeded):
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
i = 0
while i < n:
    if s[i] == "A":
        i += 1
        if s[i] == "C":
            ac[i-1] = 1
            ac[i] = 1
            i += 1
        else: i += 1
    else: i += 1
for p in lr:
    l, r = p[0] - 1, p[1] - 1
    a = sum(ac[l:r]) + ac[r]
    if s[l] == "C" and ac[l] == 1: a -= 1
    if s[r] == "A" and ac[r] == 1: a -= 1
    print(int(a/2))

Fixed submission:
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
i, c = 0, 0
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        ac[i+1] = ac[i] + 1
    else:
        ac[i+1] = ac[i]
for p in lr:
    l, r = p[0] - 1, p[1] - 1
    print(int(ac[r] - ac[l]))

Buggy python submission (verdict: Time Limit Exceeded):
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
i = 0
while i < n:
    if s[i] == "A":
        i += 1
        if s[i] == "C":
            ac[i-1] = 1
            ac[i] = 1
        else: i += 1
    else: i += 1
for p in lr:
    l, r = p[0] - 1, p[1] - 1
    a = sum(ac[l:r]) + ac[r]
    if s[l] == "C" and ac[l] == 1: a -= 1
    if s[r] == "A" and ac[r] == 1: a -= 1
    print(int(a/2))

Fixed submission:
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
i, c = 0, 0
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        ac[i+1] = ac[i] + 1
    else:
        ac[i+1] = ac[i]
for p in lr:
    l, r = p[0] - 1, p[1] - 1
    print(int(ac[r] - ac[l]))

Buggy python submission (verdict: Runtime Error):
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
for i in range(n):
    if s[i] != "A": continue
    elif s[i+1] != "C": continue
    else:
        ac[i] = 1
        ac[i+1] = 1
for p in lr:
    l, r = p[0] - 1, p[1]
    a = sum(ac[l:r])
    if s[l] == "C": a -= 1
    if s[r-1] == "A": a -= 1
    print(int(a/2))

Fixed submission:
n, q = (int(x) for x in input().split())
s = input()
s = [s[i] for i in range(n)]
lr = []
for i in range(q):
    lr.append([int(x) for x in input().split()])
ac = [0 for _ in range(n)]
i, c = 0, 0
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        ac[i+1] = ac[i] + 1
    else:
        ac[i+1] = ac[i]
for p in lr:
    l, r = p[0] - 1, p[1] - 1
    print(int(ac[r] - ac[l]))