Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
lr_list = [list(map(int, input().split())) for i in range(Q)]

ac_list  = [0]*N
for i in range(N-1):
    if S[i:i+2] == "AC":
        ac_list[i] = 1
        
for lr in lr_list:
    print(ac_list[lr[0] - 1:lr[1] - 1].count(1))

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

ac_list  = [0]*N
cnt = 0
for i in range(N-1):
    if i < len(S) and S[i:i+2] == "AC":
        cnt += 1
    ac_list[i+1] = cnt
        
for lr in lr_list:
    print(ac_list[lr[1]-1] - ac_list[lr[0]-1])

Buggy python submission (verdict: Runtime Error):
N,Q = map(int,input().split())
S = input()
lr_list = [list(map(int, input().split())) for i in range(Q)]

target = "AC"
ac_list =[]

index = -1
while True:
    index = S.find(target,index+ 1)
    if index == -1 :
        break
    ac_list.append(index)
    
for lr in lr_list:
    st = 0
    last = 0
    for i,ac in enumerate(ac_list):
#         print(ac+1,lr[0])
        if ac + 1 >= lr[0]:
            st = i
            break
    for i,ac in enumerate(ac_list[::-1]):
#         print(ac+1,lr[1]-1)
        if ac + 1 <= lr[1] - 1:
            end = len(ac_list) - i
            break
    
#     print(ac_list)
#     print(st,end)
    print(len(ac_list[st:end]))

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

ac_list  = [0]*N
cnt = 0
for i in range(N-1):
    if i < len(S) and S[i:i+2] == "AC":
        cnt += 1
    ac_list[i+1] = cnt
        
for lr in lr_list:
    print(ac_list[lr[1]-1] - ac_list[lr[0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
lr_list = [list(map(int, input().split())) for i in range(Q)]

for lr in lr_list:
    len_bfr = len(S[lr[0] - 1:lr[1]])
    len_aft = len((S[lr[0] - 1:lr[1]]).replace("AC",""))
    print((len_bfr - len_aft) // 2 )

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

ac_list  = [0]*N
cnt = 0
for i in range(N-1):
    if i < len(S) and S[i:i+2] == "AC":
        cnt += 1
    ac_list[i+1] = cnt
        
for lr in lr_list:
    print(ac_list[lr[1]-1] - ac_list[lr[0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
lr_list = [list(map(int, input().split())) for i in range(Q)]

for lr in lr_list:
    tmp = (S[lr[0] - 1:lr[1]]).replace("G","").replace("T","")
    print(tmp.count("AC")) 

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

ac_list  = [0]*N
cnt = 0
for i in range(N-1):
    if i < len(S) and S[i:i+2] == "AC":
        cnt += 1
    ac_list[i+1] = cnt
        
for lr in lr_list:
    print(ac_list[lr[1]-1] - ac_list[lr[0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
lr_list = [list(map(int, input().split())) for i in range(Q)]

for lr in lr_list:
    print(S[lr[0] - 1:lr[1]].count("AC")) 


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

ac_list  = [0]*N
cnt = 0
for i in range(N-1):
    if i < len(S) and S[i:i+2] == "AC":
        cnt += 1
    ac_list[i+1] = cnt
        
for lr in lr_list:
    print(ac_list[lr[1]-1] - ac_list[lr[0]-1])