Buggy python submission (verdict: Time Limit Exceeded):
def solve(N, Q, S, L_R):
    answers = [0] * Q
    for i in range(len(S) - 1):
        if S[i] == "A" and S[i + 1] == "C":
            for j in range(len(L_R)):
                l, r = L_R[j]
                if l <= i + 1 < r:
                    answers[j] += 1
    return answers


N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
for ans in solve(N, Q, S, L_R):
    print(ans)

Fixed submission:
def solve(N, Q, S, L_R):
    memo = [None] * N
    cumsum = 0
    for i in range(len(S) - 1):
        memo[i] = cumsum
        if S[i] == "A" and S[i + 1] == "C":
            cumsum += 1
    memo[N - 1] = cumsum
    for l, r in L_R:
        print(memo[r - 1] - memo[l - 1])


N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
solve(N, Q, S, L_R)

Buggy python submission (verdict: Time Limit Exceeded):
def solve(N, Q, S, L_R):
    answers = [0] * Q
    ac_index = list()
    for i in range(len(S) - 1):
        s = S[i:i + 2]
        if s == "AC":
            for j in range(len(L_R)):
                l, r = L_R[j]
                if l <= i + 1 < r:
                    answers[j] += 1
    return answers


N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
for ans in solve(N, Q, S, L_R):
    print(ans)

Fixed submission:
def solve(N, Q, S, L_R):
    memo = [None] * N
    cumsum = 0
    for i in range(len(S) - 1):
        memo[i] = cumsum
        if S[i] == "A" and S[i + 1] == "C":
            cumsum += 1
    memo[N - 1] = cumsum
    for l, r in L_R:
        print(memo[r - 1] - memo[l - 1])


N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
solve(N, Q, S, L_R)

Buggy python submission (verdict: Time Limit Exceeded):
def solve(N, Q, S, L_R):
    answers = [None] * Q
    ac_index = list()
    for i in range(len(S) - 1):
        s = S[i:i + 2]
        if s == "AC":
            ac_index.append(i)
    q = 0
    for l, r in L_R:
        ans = 0
        for ac in ac_index:
            if l - 1 <= ac < r - 1:
                ans += 1
        answers[q] = ans
        q += 1
    return answers


N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
for ans in solve(N, Q, S, L_R):
    print(ans)

Fixed submission:
def solve(N, Q, S, L_R):
    memo = [None] * N
    cumsum = 0
    for i in range(len(S) - 1):
        memo[i] = cumsum
        if S[i] == "A" and S[i + 1] == "C":
            cumsum += 1
    memo[N - 1] = cumsum
    for l, r in L_R:
        print(memo[r - 1] - memo[l - 1])


N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
solve(N, Q, S, L_R)

Buggy python submission (verdict: Time Limit Exceeded):
def solve(N, Q, S, L_R):
    answers = [None] * Q
    ac_index = [0] * len(S)
    for i in range(len(S) - 1):
        s = S[i:i + 2]
        if s == "AC":
            ac_index[i] = 1
    q = 0
    for l, r in L_R:
        arr = ac_index[l - 1:r]
        ans = sum(arr)
        if arr[-1] == 1:
            ans -= 1
        answers[q] = ans
        q += 1
    return answers


N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
for ans in solve(N, Q, S, L_R):
    print(ans)

Fixed submission:
def solve(N, Q, S, L_R):
    memo = [None] * N
    cumsum = 0
    for i in range(len(S) - 1):
        memo[i] = cumsum
        if S[i] == "A" and S[i + 1] == "C":
            cumsum += 1
    memo[N - 1] = cumsum
    for l, r in L_R:
        print(memo[r - 1] - memo[l - 1])


N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
solve(N, Q, S, L_R)

Buggy python submission (verdict: Runtime Error):
def solve(N, Q, S, L_R):
    answers = [None] * Q
    ac_index = [0] * len(S)
    for i in range(len(S)):
        s = S[i]
        if s == "A":
            a_flag = True
            continue
        elif s == "C":
            if a_flag:
                ac_index[i - 1] = 1
            a_flag = False
        else:
            a_flag = False
    q = 0
    for l, r in L_R:
        arr = ac_index[l - 1:r]
        ans = sum(arr)
        if arr[-1] == 1:
            ans -= 1
        answers[q] = ans
        q += 1
    return answers

def count_ac(pstr):
    count = 0
    a_flag = False
    for i in range(len(pstr)):
        s = pstr[i]
        if s == "A":
            a_flag = True
            continue
        elif s == "C":
            if a_flag:
                count += 1
            a_flag = False
        else:
            a_flag = False
    return count

N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
for ans in solve(N, Q, S, L_R):
    print(ans)

Fixed submission:
def solve(N, Q, S, L_R):
    memo = [None] * N
    cumsum = 0
    for i in range(len(S) - 1):
        memo[i] = cumsum
        if S[i] == "A" and S[i + 1] == "C":
            cumsum += 1
    memo[N - 1] = cumsum
    for l, r in L_R:
        print(memo[r - 1] - memo[l - 1])


N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
solve(N, Q, S, L_R)

Buggy python submission (verdict: Time Limit Exceeded):
def solve(N, Q, S, L_R):
    answers = [None] * Q
    q = 0
    for l, r in L_R:
        pstr = S[l - 1:r]
        count = count_ac(pstr)
        answers[q] = count
        q += 1
    return answers


def count_ac(pstr):
    count = 0
    a_flag = False
    for i in range(len(pstr)):
        s = pstr[i]
        if s == "A":
            a_flag = True
            continue
        elif s == "C":
            if a_flag:
                count += 1
            a_flag = False
        else:
            a_flag = False
    return count

N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
for ans in solve(N, Q, S, L_R):
    print(ans)

Fixed submission:
def solve(N, Q, S, L_R):
    memo = [None] * N
    cumsum = 0
    for i in range(len(S) - 1):
        memo[i] = cumsum
        if S[i] == "A" and S[i + 1] == "C":
            cumsum += 1
    memo[N - 1] = cumsum
    for l, r in L_R:
        print(memo[r - 1] - memo[l - 1])


N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
solve(N, Q, S, L_R)

Buggy python submission (verdict: Time Limit Exceeded):
def solve(N, Q, S, L_R):
    answers = [None] * Q
    q = 0
    for l, r in L_R:
        pstr = S[l - 1:r]
        count = 0
        for i in range(len(pstr) - 1):
            if pstr[i:i + 2] == "AC":
                count += 1
        answers[q] = count
        q += 1
    return answers


N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
for ans in solve(N, Q, S, L_R):
    print(ans)

Fixed submission:
def solve(N, Q, S, L_R):
    memo = [None] * N
    cumsum = 0
    for i in range(len(S) - 1):
        memo[i] = cumsum
        if S[i] == "A" and S[i + 1] == "C":
            cumsum += 1
    memo[N - 1] = cumsum
    for l, r in L_R:
        print(memo[r - 1] - memo[l - 1])


N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
solve(N, Q, S, L_R)