Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Fri Apr  5 17:16:14 2019

@author: adachi-lab
"""

input_1 = input()
S = input()
l = []
r = []


N = input_1.split()[0]
Q = input_1.split()[1]

for i in range(int(Q)):
    input_3 = input()
    l.append(int(input_3.split()[0]))
    r.append(int(input_3.split()[1]))

W = [(S[x-1:y]).count('AC') for (x, y) in zip(l, r)]

for i in range(len(W)):
    print(W[i])



Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Mon Apr  8 10:49:27 2019

@author: adachi-lab
"""


input_1 = input()
S = input()
l = []
r = []

N = input_1.split()[0]
Q = input_1.split()[1]

for i in range(int(Q)):
    input_3 = input()
    l.append(int(input_3.split()[0]))
    r.append(int(input_3.split()[1]))
    
s_1 = []
x = 0
for w in range(len(S)-1):
    if S[w] == 'A' and S[w+1] == 'C':
        x += 1
        s_1.append(x)
    else:
        s_1.append(x)
        
s_1.insert(0,0)
w = []

for j in range(len(l)):
    p = s_1[r[j]-1]-s_1[l[j]-1]
    w.append(p)
    
for t in range(len(w)):
    print(w[t])

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Fri Apr  5 17:16:14 2019

@author: adachi-lab
"""

input_1 = input()
S = input()
l = []
r = []


N = input_1.split()[0]
Q = input_1.split()[1]

for i in range(int(Q)):
    input_3 = input()
    l.append(int(input_3.split()[0]))
    r.append(int(input_3.split()[1]))

W = [S[x-1:y] for (x, y) in zip(l, r)]
for i in range(len(W)):
    print(W[i].count('AC'))



Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Mon Apr  8 10:49:27 2019

@author: adachi-lab
"""


input_1 = input()
S = input()
l = []
r = []

N = input_1.split()[0]
Q = input_1.split()[1]

for i in range(int(Q)):
    input_3 = input()
    l.append(int(input_3.split()[0]))
    r.append(int(input_3.split()[1]))
    
s_1 = []
x = 0
for w in range(len(S)-1):
    if S[w] == 'A' and S[w+1] == 'C':
        x += 1
        s_1.append(x)
    else:
        s_1.append(x)
        
s_1.insert(0,0)
w = []

for j in range(len(l)):
    p = s_1[r[j]-1]-s_1[l[j]-1]
    w.append(p)
    
for t in range(len(w)):
    print(w[t])

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Fri Apr  5 17:16:14 2019

@author: adachi-lab
"""

input_1 = input()
input_2 = input()
l = []
r = []

N = input_1.split()[0]
Q = input_1.split()[1]


for i in range(int(Q)):
    input_3 = input()
    l.append(int(input_3.split()[0]))
    r.append(int(input_3.split()[1]))



list_3 = []
list_4 = []

for w in range(int(Q)):
    word = input_2[(l[w]-1):(r[w])]
    word1 = ''.join(word)
    

    print(word.count('AC'))
    

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Mon Apr  8 10:49:27 2019

@author: adachi-lab
"""


input_1 = input()
S = input()
l = []
r = []

N = input_1.split()[0]
Q = input_1.split()[1]

for i in range(int(Q)):
    input_3 = input()
    l.append(int(input_3.split()[0]))
    r.append(int(input_3.split()[1]))
    
s_1 = []
x = 0
for w in range(len(S)-1):
    if S[w] == 'A' and S[w+1] == 'C':
        x += 1
        s_1.append(x)
    else:
        s_1.append(x)
        
s_1.insert(0,0)
w = []

for j in range(len(l)):
    p = s_1[r[j]-1]-s_1[l[j]-1]
    w.append(p)
    
for t in range(len(w)):
    print(w[t])