Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int,input().split())
S= input()
lr_list = [list(map(int,input().split())) for _ in range(Q)]
ac_tf_list = [1 if S[i:i+2]=='AC' else 0 for i in range(N-1)]

for i in range(Q):
    ans = sum(ac_tf_list[lr_list[i][0]-1:lr_list[i][1]-1])
    print(ans)

Fixed submission:
N, Q = map(int,input().split())
S= input()
lr_list = [list(map(int,input().split())) for _ in range(Q)]

# ac_tf_list = [1 if S[i:i+2]=='AC' else 0 for i in range(N-1)]
t = [0]*N
for i in range(N-1):
    if S[i:i+2]=='AC':
        t[i+1] = t[i]+1
    else:
        t[i+1] = t[i]

for i in range(Q):
    l = lr_list[i][0]-1
    r = lr_list[i][1]-1
    print(t[r]-t[l])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int,input().split())
S= input()
lr_list = [list(map(int,input().split())) for _ in range(Q)]
ac_tf_list = [1 if S[i:i+2]=='AC' else 0 for i in range(N-1)]

for i in range(Q):
    l,r = lr_list[i][0]-1, lr_list[i][1]-1
    ans = sum(ac_tf_list[l:r])
    print(ans)


Fixed submission:
N, Q = map(int,input().split())
S= input()
lr_list = [list(map(int,input().split())) for _ in range(Q)]

# ac_tf_list = [1 if S[i:i+2]=='AC' else 0 for i in range(N-1)]
t = [0]*N
for i in range(N-1):
    if S[i:i+2]=='AC':
        t[i+1] = t[i]+1
    else:
        t[i+1] = t[i]

for i in range(Q):
    l = lr_list[i][0]-1
    r = lr_list[i][1]-1
    print(t[r]-t[l])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int,input().split())
S= input()
ac_pos_list = []
start = 0
ret = 0
ac_tf_list = [1 if S[i:i+2]=='AC' else 0 for i in range(len(S)-1)]

for i in range(Q):
    l,r = map(int,input().split())
    l = l-1
    r = r-1
    ans = sum(ac_tf_list[l:r])
    print(ans)

Fixed submission:
N, Q = map(int,input().split())
S= input()
lr_list = [list(map(int,input().split())) for _ in range(Q)]

# ac_tf_list = [1 if S[i:i+2]=='AC' else 0 for i in range(N-1)]
t = [0]*N
for i in range(N-1):
    if S[i:i+2]=='AC':
        t[i+1] = t[i]+1
    else:
        t[i+1] = t[i]

for i in range(Q):
    l = lr_list[i][0]-1
    r = lr_list[i][1]-1
    print(t[r]-t[l])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, Q = map(int,input().split())
S= input()
ac_pos_list = []
start = 0
ret = 0
while ret != -1:
    ret = S.find('AC',start)
    if ret != -1:
        ac_pos_list.append(ret)
        start = ret + 2        
ac_pos_list = np.array(ac_pos_list)

for i in range(Q):
    l,r = map(int,input().split())
    l = l-1
    r = r-1
    ans = np.sum((ac_pos_list>=l) & (ac_pos_list<=r-1))
    print(ans)


Fixed submission:
N, Q = map(int,input().split())
S= input()
lr_list = [list(map(int,input().split())) for _ in range(Q)]

# ac_tf_list = [1 if S[i:i+2]=='AC' else 0 for i in range(N-1)]
t = [0]*N
for i in range(N-1):
    if S[i:i+2]=='AC':
        t[i+1] = t[i]+1
    else:
        t[i+1] = t[i]

for i in range(Q):
    l = lr_list[i][0]-1
    r = lr_list[i][1]-1
    print(t[r]-t[l])

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


Fixed submission:
N, Q = map(int,input().split())
S= input()
lr_list = [list(map(int,input().split())) for _ in range(Q)]

# ac_tf_list = [1 if S[i:i+2]=='AC' else 0 for i in range(N-1)]
t = [0]*N
for i in range(N-1):
    if S[i:i+2]=='AC':
        t[i+1] = t[i]+1
    else:
        t[i+1] = t[i]

for i in range(Q):
    l = lr_list[i][0]-1
    r = lr_list[i][1]-1
    print(t[r]-t[l])