Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())

s = input()

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

Fixed submission:
n, q = map(int, input().split())

s = input()

count = [0] * n

for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        count[i] += 1

from itertools import accumulate

accum = list(accumulate(count))

for _ in range(q):
    l, r = map(int, input().split())
    print(accum[r-1] - accum[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
_, q = input().split()
s = input()
qs = [list(map(int, input().split())) for _ in range(int(q))]

# def get_num_AC(ccond, s, count):
#     if s == []:
#         return count
#     if ccond:
#         if s.pop() == 'A':
#             return get_num_AC(False, s, count+1)
#         else:
#             if s == []:
#                 return count
#             else:
#                 return get_num_AC(s.pop() == 'C', s, count)
#     return get_num_AC(s.pop() == 'C', s, count)

def get_substr(s, smaller, larger):
    s1 = s[smaller-1:larger]
    return s1

for smaller, larger in qs:
    substr = get_substr(s, smaller, larger)
    count = substr.count('AC')
    print(count)


Fixed submission:
n, q = map(int, input().split())

s = input()

count = [0] * n

for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        count[i] += 1

from itertools import accumulate

accum = list(accumulate(count))

for _ in range(q):
    l, r = map(int, input().split())
    print(accum[r-1] - accum[l-1])

Buggy python submission (verdict: Runtime Error):
_, q = input().split()
s = list(input())
qs = [list(map(int, input().split())) for _ in range(int(q))]

def get_num_AC(ccond, s, count):
    if s == []:
        return count
    if ccond:
        if s.pop() == 'A':
            return get_num_AC(False, s, count+1)
        else:
            if s == []:
                return count
            else:
                return get_num_AC(s.pop() == 'C', s, count)
    return get_num_AC(s.pop() == 'C', s, count)

def get_substr(s, smaller, larger):
    s1 = s[smaller-1:larger]
    return s1

for smaller, larger in qs:
    substr = get_substr(s, smaller, larger)
    count = get_num_AC(False, substr, 0)
    print(count)


Fixed submission:
n, q = map(int, input().split())

s = input()

count = [0] * n

for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        count[i] += 1

from itertools import accumulate

accum = list(accumulate(count))

for _ in range(q):
    l, r = map(int, input().split())
    print(accum[r-1] - accum[l-1])

Buggy python submission (verdict: Runtime Error):
import re
_, q = input().split()
s = list(input())
qs = [list(map(int, input().split())) for _ in range(int(q))]

def get_num_AC(ccond, s, count):
    if s == []:
        return count
    if ccond:
        if s.pop() == 'A':
            return get_num_AC(False, s, count+1)
        else:
            if s == []:
                return count
            else:
                return get_num_AC(s.pop() == 'C', s, count)
    return get_num_AC(s.pop() == 'C', s, count)

def get_substr(s, smaller, larger):
    s1 = s[smaller-1:larger]
    return s1

for smaller, larger in qs:
    substr = get_substr(s, smaller, larger)
    count = get_num_AC(substr)
    print(count)


Fixed submission:
n, q = map(int, input().split())

s = input()

count = [0] * n

for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        count[i] += 1

from itertools import accumulate

accum = list(accumulate(count))

for _ in range(q):
    l, r = map(int, input().split())
    print(accum[r-1] - accum[l-1])

Buggy python submission (verdict: Runtime Error):
import re
_, q = input().split()
s = list(input())
qs = [list(map(int, input().split())) for _ in range(int(q))]

s = ['a', 'b']

def get_num_AC(ccond, s, count):
    if s == []:
        return count
    if ccond:
        if s.pop() == 'A':
            return get_num_AC(False, s, count+1)
        else:
            if s == []:
                return count
            else:
                return get_num_AC(s.pop() == 'C', s, count)
    return get_num_AC(s.pop() == 'C', s, count)

def get_substr(s, smaller, larger):
    s1 = s[smaller-1:larger]
    return s1

for smaller, larger in qs:
    substr = get_substr(s, smaller, larger)
    count = get_num_AC(substr)
    print(count)


Fixed submission:
n, q = map(int, input().split())

s = input()

count = [0] * n

for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        count[i] += 1

from itertools import accumulate

accum = list(accumulate(count))

for _ in range(q):
    l, r = map(int, input().split())
    print(accum[r-1] - accum[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import re
import numpy as np
_, q = input().split()
s = input()
qs = [list(map(int, input().split())) for _ in range(int(q))]

def get_num_AC(s):
    count = len(re.split(r'AC', s)) - 1
    return count

def get_substr(s, smaller, larger):
    s1 = s[smaller-1:larger]
    return s1

for smaller, larger in qs:
    substr = get_substr(s, smaller, larger)
    count = get_num_AC(substr)
    print(count)


Fixed submission:
n, q = map(int, input().split())

s = input()

count = [0] * n

for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        count[i] += 1

from itertools import accumulate

accum = list(accumulate(count))

for _ in range(q):
    l, r = map(int, input().split())
    print(accum[r-1] - accum[l-1])

Buggy python submission (verdict: Runtime Error):
import re
import numpy as np
_, q = input()
s = input()
qs = [input().split() for _ in range(q)]

def get_num_AC(s):
    count = len(re.split(r'AC', s)) - 1
    return count

def get_substr(s, smaller, larger)
    s1 = s[smaller-1:larger]
    return s1

for smaller, larger in qs:
    substr = get_substr(s, smaller, larger)
    count = get_num_AC(substr)
    print(count)

Fixed submission:
n, q = map(int, input().split())

s = input()

count = [0] * n

for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        count[i] += 1

from itertools import accumulate

accum = list(accumulate(count))

for _ in range(q):
    l, r = map(int, input().split())
    print(accum[r-1] - accum[l-1])