Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
S = 'Z'+input()
L = []
res = 0
for i in range(0,N+1):
    if S[i] == 'C' and S[i-1] == 'A':
        res += 1
    L.append(res)
for i in range(Q):
    l,r = map(int,input().split())
    print(max(L[l:r+1])-min(L[l:r+1]))

Fixed submission:
import bisect

N,Q = map(int,input().split())
S = input()
L = []
for i in range(N):
    if S[i:i+2] == 'AC':
        L.append(i)
for i in range(Q):
    l,r = map(int,input().split())
    a = bisect.bisect_left(L,l-1)
    b = bisect.bisect_right(L,r-2)
    print(b-a)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = 'Z'+input()
L = []
res = 0
for i in range(0,N+1):
    if S[i] == 'C' and S[i-1] == 'A':
        res += 1
    L.append(res)
for i in range(Q):
    l,r = map(int,input().split())
    print(max(L[l:r+1])-min(L[l:r+1]))

Fixed submission:
import bisect

N,Q = map(int,input().split())
S = input()
L = []
for i in range(N):
    if S[i:i+2] == 'AC':
        L.append(i)
for i in range(Q):
    l,r = map(int,input().split())
    a = bisect.bisect_left(L,l-1)
    b = bisect.bisect_right(L,r-2)
    print(b-a)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
for i in range(Q):
    l,r = map(int,input().split())
    T = S[l-1:r]
    ans = 0
    for j in range(len(T)-1):
        if T[j] == 'A' and T[j+1] == 'C':
            ans += 1
    print(ans)

Fixed submission:
import bisect

N,Q = map(int,input().split())
S = input()
L = []
for i in range(N):
    if S[i:i+2] == 'AC':
        L.append(i)
for i in range(Q):
    l,r = map(int,input().split())
    a = bisect.bisect_left(L,l-1)
    b = bisect.bisect_right(L,r-2)
    print(b-a)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
LR = [list(map(int,input().split())) for i in range(Q)]
for l,r in LR:
    print(S[l-1:r].count('AC'))

Fixed submission:
import bisect

N,Q = map(int,input().split())
S = input()
L = []
for i in range(N):
    if S[i:i+2] == 'AC':
        L.append(i)
for i in range(Q):
    l,r = map(int,input().split())
    a = bisect.bisect_left(L,l-1)
    b = bisect.bisect_right(L,r-2)
    print(b-a)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
lr = [list(map(int,input().split())) for _ in range(Q)]
L = []
for i in range(N-2):
    if S[i:i+2] == 'AC':
        L.append(i)
for l,r in lr:
    ans = 0
    for a in L:
        if l-1<=a<r-1:
            ans += 1
    print(ans)

Fixed submission:
import bisect

N,Q = map(int,input().split())
S = input()
L = []
for i in range(N):
    if S[i:i+2] == 'AC':
        L.append(i)
for i in range(Q):
    l,r = map(int,input().split())
    a = bisect.bisect_left(L,l-1)
    b = bisect.bisect_right(L,r-2)
    print(b-a)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
lr = [list(map(int,input().split())) for _ in range(Q)]
for l,r in lr:
    print(S[l-1:r].count('AC'))

Fixed submission:
import bisect

N,Q = map(int,input().split())
S = input()
L = []
for i in range(N):
    if S[i:i+2] == 'AC':
        L.append(i)
for i in range(Q):
    l,r = map(int,input().split())
    a = bisect.bisect_left(L,l-1)
    b = bisect.bisect_right(L,r-2)
    print(b-a)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
LR = [input().split() for _ in range(Q)]
for lr in LR:
    l = int(lr[0])
    r = int(lr[1])
    print(S[l-1:r].count('AC'))

Fixed submission:
import bisect

N,Q = map(int,input().split())
S = input()
L = []
for i in range(N):
    if S[i:i+2] == 'AC':
        L.append(i)
for i in range(Q):
    l,r = map(int,input().split())
    a = bisect.bisect_left(L,l-1)
    b = bisect.bisect_right(L,r-2)
    print(b-a)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
for i in range(Q):
    l,r = map(int,input().split())
    print(S[l-1:r].count('AC'))

Fixed submission:
import bisect

N,Q = map(int,input().split())
S = input()
L = []
for i in range(N):
    if S[i:i+2] == 'AC':
        L.append(i)
for i in range(Q):
    l,r = map(int,input().split())
    a = bisect.bisect_left(L,l-1)
    b = bisect.bisect_right(L,r-2)
    print(b-a)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
for i in range(Q):
    l,r = map(int,input().split())
    new_S = S[l-1:r]
    print(new_S.count('AC'))

Fixed submission:
import bisect

N,Q = map(int,input().split())
S = input()
L = []
for i in range(N):
    if S[i:i+2] == 'AC':
        L.append(i)
for i in range(Q):
    l,r = map(int,input().split())
    a = bisect.bisect_left(L,l-1)
    b = bisect.bisect_right(L,r-2)
    print(b-a)