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

# check
counts = []
c_append = counts.append
for i in range(Q):
    l, r = map(int, input().split())
    AC_cnt = S.count("AC", l - 1, r) 
    c_append(AC_cnt)

# output
for c in counts:
    print(c)

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

a = [0] * N
c = [False] * N
for i in range(1, N):
    if S[i - 1:i + 1] == "AC":
        a[i] = a[i - 1] + 1
        c[i] = True
    else:
        a[i] = a[i - 1]

for i in range(Q):
    l, r = map(int, input().split())
    if l - 1 == 0:
        print(a[r - 1])
    elif c[l - 1] is True:
        print(a[r - 1] - a[l - 1])
    else:
        print(a[r - 1] - a[l - 1])

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

# check
counts = []
c_append = counts.append
for i in range(Q):
    l, r = map(int, input().split())
    substr = S[l - 1:r]
    AC_cnt = substr.replace("AC", "*").count("*")
    c_append(AC_cnt)

# output
for c in counts:
    print(c)

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

a = [0] * N
c = [False] * N
for i in range(1, N):
    if S[i - 1:i + 1] == "AC":
        a[i] = a[i - 1] + 1
        c[i] = True
    else:
        a[i] = a[i - 1]

for i in range(Q):
    l, r = map(int, input().split())
    if l - 1 == 0:
        print(a[r - 1])
    elif c[l - 1] is True:
        print(a[r - 1] - a[l - 1])
    else:
        print(a[r - 1] - a[l - 1])

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

substrs = []
s_append = substrs.append
for i in range(Q):
    l, r = map(int, input().split())
    s_append(S[l - 1:r])

# check
for substr in substrs:
    substr_len = len(substr)
    AC_cnt = substr.replace("AC", "*").count("*")

    print(AC_cnt)

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

a = [0] * N
c = [False] * N
for i in range(1, N):
    if S[i - 1:i + 1] == "AC":
        a[i] = a[i - 1] + 1
        c[i] = True
    else:
        a[i] = a[i - 1]

for i in range(Q):
    l, r = map(int, input().split())
    if l - 1 == 0:
        print(a[r - 1])
    elif c[l - 1] is True:
        print(a[r - 1] - a[l - 1])
    else:
        print(a[r - 1] - a[l - 1])

Buggy python submission (verdict: Runtime Error):
# input
N, Q = map(int, input().split())
S = input()

substrs = []
s_append = substrs.append
for i in range(Q):
    l, r = map(int, input().split())
    s_append(S[l - 1:r])

# check
for substr in substrs:
    substr_len = len(substr)
    AC_cnt = sum(
        [
            1
            for i in range(0, substr_len - 1)
            if substr[i:i + 2] == "AC"
        ]
    )

    print(AC_cnt)

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

a = [0] * N
c = [False] * N
for i in range(1, N):
    if S[i - 1:i + 1] == "AC":
        a[i] = a[i - 1] + 1
        c[i] = True
    else:
        a[i] = a[i - 1]

for i in range(Q):
    l, r = map(int, input().split())
    if l - 1 == 0:
        print(a[r - 1])
    elif c[l - 1] is True:
        print(a[r - 1] - a[l - 1])
    else:
        print(a[r - 1] - a[l - 1])

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

index = []
i_append = index.append
for i in range(Q):
    l, r = map(int, input().split())
    i_append((l - 1, r))

# check
for l, r in index:
    check_substr = S[l:r]
    substr_len = len(check_substr)
    AC_cnt = sum(
        [
            1
            for i in range(0, substr_len - 1)
            if check_substr[i:i + 2] == "AC"
        ]
    )

    print(AC_cnt)

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

a = [0] * N
c = [False] * N
for i in range(1, N):
    if S[i - 1:i + 1] == "AC":
        a[i] = a[i - 1] + 1
        c[i] = True
    else:
        a[i] = a[i - 1]

for i in range(Q):
    l, r = map(int, input().split())
    if l - 1 == 0:
        print(a[r - 1])
    elif c[l - 1] is True:
        print(a[r - 1] - a[l - 1])
    else:
        print(a[r - 1] - a[l - 1])