Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=list(str(input()))
lr=[]
for i in range(q):
    lr.append(list(map(int,input().split())))

l_list=[]
r_list=[0]
ctr1=0
ctr2=0
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        ctr1+=1
        l_list.append(ctr1)
        ctr2+=1
        r_list.append(ctr2)
    else:
        l_list.append(ctr1)
        r_list.append(ctr2)

for i in range(q):
    left=lr[i][0]
    right=lr[i][1]
    print(r_list[right-1]-l_list[left]+1)


Fixed submission:
n,q=map(int,input().split())
s=list(str(input()))
lr=[]
for i in range(q):
    lr.append(list(map(int,input().split())))
ctr1=0
t_list=[0]
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        ctr1+=1
        t_list.append(ctr1)
    else:
        t_list.append(ctr1)

for i in range(q):
    left=lr[i][0]
    right=lr[i][1]
    print(t_list[right-1]-t_list[left-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=list(str(input()))
lr=[]
for i in range(q):
    lr.append(list(map(int,input().split())))
sl=[]
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        sl.append([i+1,i+2])
    else:
        pass

for i in range(q):
    ctr1=1
    ctr2=0
    for k in range(len(sl)):
        if lr[i][0] > sl[k][0]:
            ctr1+=1
        if lr[i][1] >= sl[k][1]:
            ctr2+=1
        else:
            break
    print(ctr2-ctr1+1)

Fixed submission:
n,q=map(int,input().split())
s=list(str(input()))
lr=[]
for i in range(q):
    lr.append(list(map(int,input().split())))
ctr1=0
t_list=[0]
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        ctr1+=1
        t_list.append(ctr1)
    else:
        t_list.append(ctr1)

for i in range(q):
    left=lr[i][0]
    right=lr[i][1]
    print(t_list[right-1]-t_list[left-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=list(str(input()))
lr=[]
for i in range(q):
    lr.append(list(map(int,input().split())))
sl=[]
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        sl.append([i+1,i+2])
    else:
        pass

for i in range(q):
    ctr1=1
    ctr2=0
    for k in range(len(sl)):
        if lr[i][0] > sl[k][0]:
            ctr1+=1
        else:
            break
    for m in range(len(sl)):
        if lr[i][1] >= sl[m][1]:
            ctr2+=1
        else:
            break
    print(ctr2-ctr1+1)


Fixed submission:
n,q=map(int,input().split())
s=list(str(input()))
lr=[]
for i in range(q):
    lr.append(list(map(int,input().split())))
ctr1=0
t_list=[0]
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        ctr1+=1
        t_list.append(ctr1)
    else:
        t_list.append(ctr1)

for i in range(q):
    left=lr[i][0]
    right=lr[i][1]
    print(t_list[right-1]-t_list[left-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=list(str(input()))
lr=[]
for i in range(q):
    lr.append(list(map(int,input().split())))

for i in range(q):
    tl=s[lr[i][0]-1:lr[i][1]]
    ctr=0
    for k in range(len(tl)-1):
        if tl[k]=="A" and tl[k+1]=="C":
            ctr+=1
        else:
            pass
    print(ctr)


Fixed submission:
n,q=map(int,input().split())
s=list(str(input()))
lr=[]
for i in range(q):
    lr.append(list(map(int,input().split())))
ctr1=0
t_list=[0]
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        ctr1+=1
        t_list.append(ctr1)
    else:
        t_list.append(ctr1)

for i in range(q):
    left=lr[i][0]
    right=lr[i][1]
    print(t_list[right-1]-t_list[left-1])