Buggy python submission (verdict: Time Limit Exceeded):
n,q = list(map(int, input().split()))
s = input()
for _ in range(q):
    r,l=list(map(int, input().split()))
    print(s[r-1:l].count('AC'))

Fixed submission:

n,q = list(map(int, input().split()))
s = input()
ans = [0]*(n+1)
lr=[list(map(int, input().split())) for _ in range(q)]
for i in range(1,n):
    
    if s[i-1]=='A' and s[i]=='C':
        ans[i+1] = ans[i] + 1
    else:
        ans[i+1]= ans[i]
#print(ans)
for i in range(q):
    print(ans[lr[i][1]]-ans[lr[i][0]])

Buggy python submission (verdict: Runtime Error):
n,q = list(map(int, input().split()))
s = input()
s_ps=[]

a =s[0]
for i in range(n):
    b = a
    a = s[i]
    if b+a=='AC':
        s_ps.append(i)
#print(s_ps)
len_s = len(s_ps)


for _ in range(q):
    l,r=list(map(int, input().split()))
    count =0
    for i in s_ps:
        if l<=i:
            low =i
            break
    for i in s_ps[::-1]:
        if i < r:
            high=i
            break
    print(s_ps.index(high)-s_ps.index(low)+1)

Fixed submission:

n,q = list(map(int, input().split()))
s = input()
ans = [0]*(n+1)
lr=[list(map(int, input().split())) for _ in range(q)]
for i in range(1,n):
    
    if s[i-1]=='A' and s[i]=='C':
        ans[i+1] = ans[i] + 1
    else:
        ans[i+1]= ans[i]
#print(ans)
for i in range(q):
    print(ans[lr[i][1]]-ans[lr[i][0]])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = list(map(int, input().split()))
s = input()
s_ps=[]
for i in range(n-1):
    if s[i:i+2]=='AC':
        s_ps.append(i)

for _ in range(q):
    l,r=list(map(int, input().split()))
    count =0
    for i in s_ps:
        if l-1<=i and i < r-1:
            count +=1
    print(count)

Fixed submission:

n,q = list(map(int, input().split()))
s = input()
ans = [0]*(n+1)
lr=[list(map(int, input().split())) for _ in range(q)]
for i in range(1,n):
    
    if s[i-1]=='A' and s[i]=='C':
        ans[i+1] = ans[i] + 1
    else:
        ans[i+1]= ans[i]
#print(ans)
for i in range(q):
    print(ans[lr[i][1]]-ans[lr[i][0]])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = list(map(int, input().split()))
s = input()
s_lis = list(s)
for _ in range(q):
    count = 0
    l,r=list(map(int, input().split()))
    for i in range(l-1,r-1):
        #print(s_lis[i])
        if s_lis[i] =='A' and s_lis[i+1]=='C':
            count += 1
    print(count)

Fixed submission:

n,q = list(map(int, input().split()))
s = input()
ans = [0]*(n+1)
lr=[list(map(int, input().split())) for _ in range(q)]
for i in range(1,n):
    
    if s[i-1]=='A' and s[i]=='C':
        ans[i+1] = ans[i] + 1
    else:
        ans[i+1]= ans[i]
#print(ans)
for i in range(q):
    print(ans[lr[i][1]]-ans[lr[i][0]])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = list(map(int, input().split()))
s = input()
for _ in range(q):
    count = 0
    l,r=list(map(int, input().split()))
    s_part = s[l-1:r+1]
    for i in range(r-l):
        if s_part[i] =='A' and s_part[i+1]=='C':
            count += 1
    print(count)

Fixed submission:

n,q = list(map(int, input().split()))
s = input()
ans = [0]*(n+1)
lr=[list(map(int, input().split())) for _ in range(q)]
for i in range(1,n):
    
    if s[i-1]=='A' and s[i]=='C':
        ans[i+1] = ans[i] + 1
    else:
        ans[i+1]= ans[i]
#print(ans)
for i in range(q):
    print(ans[lr[i][1]]-ans[lr[i][0]])