Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(i) for i in input().split()]
string = input()

collection = []

for i in range(1, n + 1):
    collection.append(string[0:i].count('AC'))

for i in range(q):
    start, end = [int(i) for i in input().split()]
    print(collection[end-1] - collection[start-1])

Fixed submission:
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):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(i) for i in input().split()]
string = list(input())

for i in range(q):
    res = 0
    start, end = [int(i) for i in input().split()]
    start -= 1
    temp = string[start:end]
    for j in range(len(temp) - 1):
        if temp[j] == 'A' and temp[j+1] == 'C':
            res += 1
    print(res)

Fixed submission:
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):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
length, questions = [int(a) for a in input().split()]
strings = str(input())
for j in range(questions):
    start, end = [int(a) for a in input().split()]
    moji = strings[start - 1: end]
    counts = 0
    place = 0
    temp = 0
    while True:
        temp = moji.find('AC', place)
        if temp != -1:
            counts += 1
            place = temp + 2
        else:
            break
    print(counts)

Fixed submission:
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):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
length, questions = [int(a) for a in input().split()]
strings = str(input())
for j in range(questions):
    start, end = [int(a) for a in input().split()]
    moji = strings[start - 1: end]
    counts = 0
    for k in range(len(moji) - 1):
        if moji[k] == 'A':
            if moji[k + 1] == 'C':
                counts += 1
    print(counts)

Fixed submission:
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):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
length, questions = [int(a) for a in input().split()]

strings = str(input())
for j in range(questions):
    start, end = [int(a) for a in input().split()]
    moji = strings[start - 1: end]
    counts = 0
    for k in range(len(moji) - 1):
        if moji[k] == 'A' and moji[k + 1] == 'C':
            counts += 1
    print(counts)

Fixed submission:
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):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Buggy python submission (verdict: Runtime Error):
times, questions = [int(a) for a in input().split()]

strings = str(input())

for i in range(questions):
    for j in range(times):
        start, end = [int(a) for a in input().split()]
        moji = strings[start - 1: end]
        counts = 0
        for k in range(len(moji) - 1):
            if moji[k] == 'A' and moji[k + 1] == 'C':
                counts += 1
        print(counts)

Fixed submission:
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):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])