Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N, Q = map(int, input().split())
S = input()
c = 0
lst = [0] * N
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
        lst[i + 1] = c
for _ in range(Q):
    a, b = map(int, input().split())
    c = max(lst[a - 1:b])
    d = max(lst[:a])
    print(max(c - d, 0))

Fixed submission:
# coding: utf-8
N, Q = map(int, input().split())
S = input()
c = 0
lst = [0] * N
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
    lst[i + 1] = c
for _ in range(Q):
    a, b = map(int, input().split())
    print(lst[b - 1] - lst[a - 1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N, Q = map(int, input().split())
S = input()
c = 0
lst = [0] * N
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
        lst[i + 1] = c
for _ in range(Q):
    a, b = map(int, input().split())
    c = max(lst[a - 1:b])
    d = max(lst[:a])
    print(max(c - d, 0))

Fixed submission:
# coding: utf-8
N, Q = map(int, input().split())
S = input()
c = 0
lst = [0] * N
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
    lst[i + 1] = c
for _ in range(Q):
    a, b = map(int, input().split())
    print(lst[b - 1] - lst[a - 1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N, Q = map(int, input().split())
S = input()
l = [0] * N
c = 0
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
        l[i + 1] = c
for _ in range(Q):
    a, b = map(int, input().split())
    c = d = 0
    while a != 0:
        if l[a - 1] != 0:
            c = l[a - 1]
            break
        a -= 1
    while b > a:
        if l[b - 1] != 0:
            d = l[b - 1]
            break
        b -= 1
    print(max(d - c, 0))

Fixed submission:
# coding: utf-8
N, Q = map(int, input().split())
S = input()
c = 0
lst = [0] * N
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
    lst[i + 1] = c
for _ in range(Q):
    a, b = map(int, input().split())
    print(lst[b - 1] - lst[a - 1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N, Q = map(int, input().split())
S = input()
l = [0] * N
c = 0
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
        l[i + 1] = c
for _ in range(Q):
    a, b = map(int, input().split())
    print(max(l[a - 1: b]) - max(l[:a]))

Fixed submission:
# coding: utf-8
N, Q = map(int, input().split())
S = input()
c = 0
lst = [0] * N
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
    lst[i + 1] = c
for _ in range(Q):
    a, b = map(int, input().split())
    print(lst[b - 1] - lst[a - 1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N, Q = map(int, input().split())
S = input()
l = [0] * N
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        l[i + 1] = 1
for _ in range(Q):
    ans = 0
    a, b = map(int, input().split())
    ans = sum(l[a - 1: b])
    if l[a - 1] == 1:
        ans -= 1
    print(ans)

Fixed submission:
# coding: utf-8
N, Q = map(int, input().split())
S = input()
c = 0
lst = [0] * N
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
    lst[i + 1] = c
for _ in range(Q):
    a, b = map(int, input().split())
    print(lst[b - 1] - lst[a - 1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
N, Q = map(int, input().split())
S = input()
l = [0] * N
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        l[i] = 1
        l[i + 1] = -1
for _ in range(Q):
    ans = 0
    a, b = map(int, input().split())
    for i in range(a - 1, b - 1):
        if l[i] == 1 and l[i + 1] == -1:
            ans += 1
    print(ans)

Fixed submission:
# coding: utf-8
N, Q = map(int, input().split())
S = input()
c = 0
lst = [0] * N
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
    lst[i + 1] = c
for _ in range(Q):
    a, b = map(int, input().split())
    print(lst[b - 1] - lst[a - 1])