Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
S = input()
lr = [[int(i) for i in input().split()] for i in range(Q)]
C = []
#"AC"が何文字目か判断
terget = "AC"
index = -1
while True:
    index = S.find(terget,index+1)
    if index == -1:
        break
    C.append(index)
    
for l,r in lr:
    AC = 0
    for j in C:
        if j >= l-1:
            if j < r-1:
                AC += 1
            else:
                break
    print(AC)

Fixed submission:
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
S = input()
lr = [[int(i) for i in input().split()] for i in range(Q)]
C = [0]*(N+1)
terget = "AC"
index = -1
for i in range(N):
    C[i+1] = C[i] + (S[i:i+2] == "AC")
for l,r in lr:
    print(C[r-1] - C[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
S = input()
lr = [[int(i) for i in input().split()] for i in range(Q)]
C = []
for i in range(N-1):
    if S[i] == "A":
        if S[i+1] == "C":
            C.append(i)
for l,r in lr:
    AC = 0
    for j in C:
        if j >= l-1:
            if j < r-1:
                AC += 1
            else:
                break
    print(AC)

Fixed submission:
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
S = input()
lr = [[int(i) for i in input().split()] for i in range(Q)]
C = [0]*(N+1)
terget = "AC"
index = -1
for i in range(N):
    C[i+1] = C[i] + (S[i:i+2] == "AC")
for l,r in lr:
    print(C[r-1] - C[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N,Q = map(int,input().split())
S = input()
input = sys.stdin.readline
lr = [[int(i) for i in input().split()] for i in range(Q)]
C = []
for i in range(N-1):
    if S[i] == "A":
        if S[i+1] == "C":
            C.append(i)
for i in lr:
    AC = 0
    for j in C:
        if j >= i[0]-1:
            if j < i[1]-1:
                AC += 1
            else:
                break
    print(AC)

Fixed submission:
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
S = input()
lr = [[int(i) for i in input().split()] for i in range(Q)]
C = [0]*(N+1)
terget = "AC"
index = -1
for i in range(N):
    C[i+1] = C[i] + (S[i:i+2] == "AC")
for l,r in lr:
    print(C[r-1] - C[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
lr = [[int(i) for i in input().split()] for i in range(Q)]
C = []
for i in range(N-1):
    if S[i] == "A":
        if S[i+1] == "C":
            C.append(i)
for i in lr:
    AC = 0
    for j in C:
        if j >= i[0]-1:
            if j < i[1]-1:
                AC += 1
            else:
                break
    print(AC)

Fixed submission:
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
S = input()
lr = [[int(i) for i in input().split()] for i in range(Q)]
C = [0]*(N+1)
terget = "AC"
index = -1
for i in range(N):
    C[i+1] = C[i] + (S[i:i+2] == "AC")
for l,r in lr:
    print(C[r-1] - C[l-1])

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

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


Fixed submission:
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
S = input()
lr = [[int(i) for i in input().split()] for i in range(Q)]
C = [0]*(N+1)
terget = "AC"
index = -1
for i in range(N):
    C[i+1] = C[i] + (S[i:i+2] == "AC")
for l,r in lr:
    print(C[r-1] - C[l-1])