Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
moji = str(input())
ans = [0]
for i in range(N-1):
    if moji[i] == "A" and moji[i+1] == "C":
        ans.append(ans[i]+1)
    else:
        ans.append(ans[i])

        
for i in range(K):
    st,sp = map(int,input().split())
    print(ans[sp]-ans[st])
    

Fixed submission:
N,K = map(int,input().split())
moji = str(input())
ans = [0]
for i in range(N-1):
    if moji[i] == "A" and moji[i+1] == "C":
        ans.append(ans[i]+1)
    else:
        ans.append(ans[i])

        
for i in range(K):
    st,sp = map(int,input().split())
    print(ans[sp-1]-ans[st-1])

Buggy python submission (verdict: Runtime Error):
cho,N = map(int,input().split())
moji = str(input())
moji_dict = []
flg = 0
##計算量は10**5
for i in range(cho):
    if flg == 1:
        flg = 0
    elif i != cho and moji[i] == "A" and moji[i+1] =="C":
        moji_dict.append(i + 1)
        flg = 1
##計算量は10**3　* 10 ** 5
for j in range(N):
    s,g = map(int,input().split())
    print(len([k for k in moji_dict if k >= s and k < g]))

Fixed submission:
N,K = map(int,input().split())
moji = str(input())
ans = [0]
for i in range(N-1):
    if moji[i] == "A" and moji[i+1] == "C":
        ans.append(ans[i]+1)
    else:
        ans.append(ans[i])

        
for i in range(K):
    st,sp = map(int,input().split())
    print(ans[sp-1]-ans[st-1])

Buggy python submission (verdict: Runtime Error):
cho,N = map(int,input().split())
moji = str(input())
moji_dict = []
flg = 0
##計算量は10**5
for i in range(cho):
    if flg == 1:
        flg = 0
    elif i != cho and moji[i] == "A" and moji[i+1] =="C":
        moji_dict.append(i + 1)
        flg = 1
##計算量は10**3　* 10 ** 5
for j in range(N):
    s,g = map(int,input().split())
    print(len([k for k in moji_dict if k >= s and k < g]))

Fixed submission:
N,K = map(int,input().split())
moji = str(input())
ans = [0]
for i in range(N-1):
    if moji[i] == "A" and moji[i+1] == "C":
        ans.append(ans[i]+1)
    else:
        ans.append(ans[i])

        
for i in range(K):
    st,sp = map(int,input().split())
    print(ans[sp-1]-ans[st-1])

Buggy python submission (verdict: Runtime Error):
cho,N = map(int,input().split())
moji = str(input())
moji_dict = []
flg = 0
##計算量は10**5
for i in range(cho):
    if flg == 1:
        flg = 0
    elif i != cho and moji[i] == "A" and moji[i+1] =="C":
        moji_dict.append(i + 1)
        flg = 1
##計算量は10**3　* 10 ** 5
for j in range(N):
    s,g = map(int,input().split())
    print(len([k for k in moji_dict if k >= s and k < g]))

Fixed submission:
N,K = map(int,input().split())
moji = str(input())
ans = [0]
for i in range(N-1):
    if moji[i] == "A" and moji[i+1] == "C":
        ans.append(ans[i]+1)
    else:
        ans.append(ans[i])

        
for i in range(K):
    st,sp = map(int,input().split())
    print(ans[sp-1]-ans[st-1])

Buggy python submission (verdict: Time Limit Exceeded):
cho,N = map(int,input().split())
moji = str(input())
for i in range(int(N)):
    s,g = map(int,input().split())
    cmoji = moji[s-1:g]
    print(cmoji.count('AC'))


Fixed submission:
N,K = map(int,input().split())
moji = str(input())
ans = [0]
for i in range(N-1):
    if moji[i] == "A" and moji[i+1] == "C":
        ans.append(ans[i]+1)
    else:
        ans.append(ans[i])

        
for i in range(K):
    st,sp = map(int,input().split())
    print(ans[sp-1]-ans[st-1])

Buggy python submission (verdict: Time Limit Exceeded):
#https://atcoder.jp/contests/abc122/tasks/abc122_c
N,Q= map(int,input().split())
moji = str(input())
a_list = [i for i, x in enumerate(moji) if x == 'A']
Current_List =[]
for i in a_list:
    if i == N - 1:
        break
    elif moji[i+1] == "C":
        Current_List.append(i)

for i in range(Q):
    start,stop = map(int,input().split())
    print(len([j for j in Current_List if (j >=start-1) and (j < stop-1)]))


Fixed submission:
N,K = map(int,input().split())
moji = str(input())
ans = [0]
for i in range(N-1):
    if moji[i] == "A" and moji[i+1] == "C":
        ans.append(ans[i]+1)
    else:
        ans.append(ans[i])

        
for i in range(K):
    st,sp = map(int,input().split())
    print(ans[sp-1]-ans[st-1])

Buggy python submission (verdict: Time Limit Exceeded):
#https://atcoder.jp/contests/abc122/tasks/abc122_c
N,Q= map(int,input().split())
moji = str(input())
for i in range(Q):
    start,stop = map(int,input().split())
    print(moji[start-1:stop].count("AC"))

    


Fixed submission:
N,K = map(int,input().split())
moji = str(input())
ans = [0]
for i in range(N-1):
    if moji[i] == "A" and moji[i+1] == "C":
        ans.append(ans[i]+1)
    else:
        ans.append(ans[i])

        
for i in range(K):
    st,sp = map(int,input().split())
    print(ans[sp-1]-ans[st-1])