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

l_list = []
r_list = []

s_count = [0]
for i in range(len(S) - 1):
    if S[i:i+2] == 'AC':
        s_count.append(1)
    else:
        s_count.append(0)
     

for x in range(Q):
    l, r = map(int, input().split())
    sub_count = s_count[l:r]
    print(sum(sub_count))
    
    




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

l_list = []
r_list = []

s_count = [0]
for i in range(len(S) - 1):
    if S[i:i+2] == 'AC':
        s_count.append(1)
    else:
        s_count.append(0)
#print(s_count)

n_count = []
n_sum = 0
for n in s_count:
    n_sum = n_sum + n
    n_count.append(n_sum)

#print(n_count)


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

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

l_list = []
r_list = []

ans = []
for x in range(Q):
    l, r = map(int, input().split())
    sub_str = S[l-1:r]
    ans = sub_str.count('AC')
    print(ans)

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

l_list = []
r_list = []

s_count = [0]
for i in range(len(S) - 1):
    if S[i:i+2] == 'AC':
        s_count.append(1)
    else:
        s_count.append(0)
#print(s_count)

n_count = []
n_sum = 0
for n in s_count:
    n_sum = n_sum + n
    n_count.append(n_sum)

#print(n_count)


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

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

l_list = []
r_list = []

ans = []
for x in range(Q):
    l, r = map(int, input().split())
    sub_str = S[l-1:r]
    ac_count = 0
    
    for i in range(len(sub_str) - 1):
        if sub_str[i:i+2] == 'AC':
            ac_count += 1
    
    ans.append(ac_count)
    
for a in ans:
    print(a)
    
    




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

l_list = []
r_list = []

s_count = [0]
for i in range(len(S) - 1):
    if S[i:i+2] == 'AC':
        s_count.append(1)
    else:
        s_count.append(0)
#print(s_count)

n_count = []
n_sum = 0
for n in s_count:
    n_sum = n_sum + n
    n_count.append(n_sum)

#print(n_count)


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

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

l_list = []
r_list = []

for x in range(Q):
    l, r = map(int, input().split())
    sub_str = S[l-1:r]
    ac_count = 0
    
    for i in range(len(sub_str) - 1):
        if sub_str[i:i+2] == 'AC':
            ac_count += 1
    
    print(ac_count)
    
    




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

l_list = []
r_list = []

s_count = [0]
for i in range(len(S) - 1):
    if S[i:i+2] == 'AC':
        s_count.append(1)
    else:
        s_count.append(0)
#print(s_count)

n_count = []
n_sum = 0
for n in s_count:
    n_sum = n_sum + n
    n_count.append(n_sum)

#print(n_count)


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