Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
S = S[0:len(S)-1]
ac = [1 if S[_:_+2] == 'AC' else 0 for _ in range(N-1)] + [0]
for q in range(Q):
    r,l = map(int,input().split())
    print(sum(ac[r-1:l-1]))

Fixed submission:
N,Q = map(int,input().split())
S = input()
ansers = [0] * (N+1)
for i in range(N):
    ansers[i+1] = ansers[i] + (1 if S[i:i+2] == 'AC' else 0)
for q in range(Q):
    l,r = map(int,input().split())
    print(ansers[r-1] - ansers[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
S = S[0:len(S)-1]
ac = []
for _ in range(N-1):
    if S[_:_+2] == 'AC':
        ac.append(1)
    else:
        ac.append(0)
ac.append(0)
for q in range(Q):
    r,l = map(int,input().split())
    print(sum(ac[r-1:l-1]))

Fixed submission:
N,Q = map(int,input().split())
S = input()
ansers = [0] * (N+1)
for i in range(N):
    ansers[i+1] = ansers[i] + (1 if S[i:i+2] == 'AC' else 0)
for q in range(Q):
    l,r = map(int,input().split())
    print(ansers[r-1] - ansers[l-1])

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 q in range(Q):
    ans = 0
    flag = False
    for a in S[lr[q][0]:lr[q][1]]:
        if a == 'A':
            flag = True
        elif a == 'C':
            ans += 1
            flag = False
        else:
            flag = False
    print(ans)

Fixed submission:
N,Q = map(int,input().split())
S = input()
ansers = [0] * (N+1)
for i in range(N):
    ansers[i+1] = ansers[i] + (1 if S[i:i+2] == 'AC' else 0)
for q in range(Q):
    l,r = map(int,input().split())
    print(ansers[r-1] - ansers[l-1])

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 q in range(Q):
    q_lis = S[lr[q][0] -1:lr[q][1]]
    print(q_lis.count('AC'))


Fixed submission:
N,Q = map(int,input().split())
S = input()
ansers = [0] * (N+1)
for i in range(N):
    ansers[i+1] = ansers[i] + (1 if S[i:i+2] == 'AC' else 0)
for q in range(Q):
    l,r = map(int,input().split())
    print(ansers[r-1] - ansers[l-1])

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)]
q_lis = [S[lr[x][0]-1:lr[x][1]:] for x in range(Q)]
for q in range(Q):
    print(q_lis[q].count('AC'))

Fixed submission:
N,Q = map(int,input().split())
S = input()
ansers = [0] * (N+1)
for i in range(N):
    ansers[i+1] = ansers[i] + (1 if S[i:i+2] == 'AC' else 0)
for q in range(Q):
    l,r = map(int,input().split())
    print(ansers[r-1] - ansers[l-1])

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 q in lr:
    q_lis = S[q[0]-1:q[1]:]
    print(q_lis.count('AC'))

Fixed submission:
N,Q = map(int,input().split())
S = input()
ansers = [0] * (N+1)
for i in range(N):
    ansers[i+1] = ansers[i] + (1 if S[i:i+2] == 'AC' else 0)
for q in range(Q):
    l,r = map(int,input().split())
    print(ansers[r-1] - ansers[l-1])