Buggy python submission (verdict: Runtime Error):

[N,Q] = list(map(int,input().split()))
locate= [-1]*N

str=input()
s = list(str)

k=1
locate=[-1]*N

for i in range (N):
    if s[i]=='A' and s[i+1]=='C':
        locate[k]=i
        k+=1

locate[k]=100000000

numL=1
numR=k-1

for i in range(Q):
    a = list(map(int, input().split()))
    L=a[0]-1
    R=a[1]-1

    for j in range(1,k):
        if L>locate[j-1] and L<=locate[j]:
            numL=j
            break
 


    for j in range(1,k):
        if R>locate[j] and R<=locate[j+1]:
            numR=j
            break
    
    
    print(numR-numL+1)


Fixed submission:

[N,Q] = list(map(int,input().split()))
locate= [-1]*N

str=input()
s = list(str)

num_a=[0]*N
tmp=0

for i in range(1,N):
    if s[i-1]=='A' and s[i]=='C':
        tmp+=1
    num_a[i]=tmp
        

for i in range(Q):
    a = list(map(int, input().split()))
    L=a[0]-1
    R=a[1]-1
    print(num_a[R]-num_a[L])

Buggy python submission (verdict: Runtime Error):

[N,Q] = list(map(int,input().split()))
locate= [-1]*N

str=input()
s = list(str)

k=1
locate=[-1]*N

for i in range (N):
    if s[i]=='A' and s[i+1]=='C':
        locate[k]=i
        k+=1

locate[k]=100000000

numL=1
numR=k-1

for i in range(Q):
    a = list(map(int, input().split()))
    L=a[0]-1
    R=a[1]-1

    for j in range(1,k):
        if L>locate[j-1] and L<=locate[j]:
            numL=j
            break
 


    for j in range(1,k):
        if R>locate[j] and R<=locate[j+1]:
            numR=j
            break
    
    
    print(numL,numR,numR-numL+1)


Fixed submission:

[N,Q] = list(map(int,input().split()))
locate= [-1]*N

str=input()
s = list(str)

num_a=[0]*N
tmp=0

for i in range(1,N):
    if s[i-1]=='A' and s[i]=='C':
        tmp+=1
    num_a[i]=tmp
        

for i in range(Q):
    a = list(map(int, input().split()))
    L=a[0]-1
    R=a[1]-1
    print(num_a[R]-num_a[L])

Buggy python submission (verdict: Runtime Error):

[N,Q] = list(map(int,input().split()))
locate= [-1]*N

str=input()
s = list(str)

k=0
for i in range (N):
    if s[i]=='A' and s[i+1]=='C':
        locate[k]=i
        k+=1

k-=1

for j in range(Q):
    i = list(map(int, input().split()))
    L=i[0]-1
    R=i[1]-1

    low = 0
    high = k
    # t は中央番目の数
    t = int((low + high) / 2) 
    
    while (low<=high):
        if (L>locate[t-1] and L<=locate[t]):
            break
        elif (L > locate[t]):
            low = t+1
        elif (L < locate[t]):
            high = t-1
        t = int((low + high) / 2)
    
 
    numL=t
    
    
    low = 0
    high = k
    # t は中央番目の数
    t = int((low + high) / 2) 
    
    while (low<=high):
        if (R>=locate[t-1]+1 and R<locate[t]+1):
            break
        elif (R > locate[t-1]+1):
            low = t+1
        elif (R < locate[t-1]+1):
            high = t-1
        t = int((low + high) / 2)
    
    numR=t
    
    
    print(numR-numL+1)


Fixed submission:

[N,Q] = list(map(int,input().split()))
locate= [-1]*N

str=input()
s = list(str)

num_a=[0]*N
tmp=0

for i in range(1,N):
    if s[i-1]=='A' and s[i]=='C':
        tmp+=1
    num_a[i]=tmp
        

for i in range(Q):
    a = list(map(int, input().split()))
    L=a[0]-1
    R=a[1]-1
    print(num_a[R]-num_a[L])