Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N, Q = map(int,input().split())
S = list(input())[:-1]
for i in range(Q):
    count = 0
    l, r = map(int, input().split())
    tmp = S[l-1:r]
    for j in range(len(tmp)-1):
        if tmp[j] == "A" and tmp[j+1] == "C":
            count += 1
    print(count)

Fixed submission:
import sys
input = sys.stdin.readline
N, Q = map(int,input().split())
S = list(input())[:-1]
list_Sum = [0]*(N+1)
for i in range(1, N):
    list_Sum[i+1] = list_Sum[i]
    if S[i-1] == "A" and S[i] == "C":
        list_Sum[i+1] += 1
for i in range(Q):
    l, r = map(int,input().split())
    print(list_Sum[r]-list_Sum[l])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N, Q = map(int,input().split())
S = input()[:-1]
for i in range(Q):
    l, r = map(int, input().split())
    tmp = S[l-1:r]
    print(len(tmp.split("AC"))-1)

Fixed submission:
import sys
input = sys.stdin.readline
N, Q = map(int,input().split())
S = list(input())[:-1]
list_Sum = [0]*(N+1)
for i in range(1, N):
    list_Sum[i+1] = list_Sum[i]
    if S[i-1] == "A" and S[i] == "C":
        list_Sum[i+1] += 1
for i in range(Q):
    l, r = map(int,input().split())
    print(list_Sum[r]-list_Sum[l])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
for i in range(q):
    tmp = s
    list_q = list(map(int, input().split()))
    tmp = tmp[list_q[0]-1:list_q[1]]
    tmp = tmp.split("AC")
    print(len(tmp) - 1)


Fixed submission:
import sys
input = sys.stdin.readline
N, Q = map(int,input().split())
S = list(input())[:-1]
list_Sum = [0]*(N+1)
for i in range(1, N):
    list_Sum[i+1] = list_Sum[i]
    if S[i-1] == "A" and S[i] == "C":
        list_Sum[i+1] += 1
for i in range(Q):
    l, r = map(int,input().split())
    print(list_Sum[r]-list_Sum[l])

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = input()
for i in range(q):
    tmp = s
    list_q = list(map(int, input().split()))
    tmp = tmp[list_q[0] -1:list_q[1]]
    print(tmp)
    tmp = tmp.split("AC")
    print(len(tmp) - 1)


Fixed submission:
import sys
input = sys.stdin.readline
N, Q = map(int,input().split())
S = list(input())[:-1]
list_Sum = [0]*(N+1)
for i in range(1, N):
    list_Sum[i+1] = list_Sum[i]
    if S[i-1] == "A" and S[i] == "C":
        list_Sum[i+1] += 1
for i in range(Q):
    l, r = map(int,input().split())
    print(list_Sum[r]-list_Sum[l])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
for i in range(q):
    tmp = s
    list_q = list(map(int, input().split()))
    list_q[0] = list_q[0] - 1
    list_q[1] = n - list_q[1]
    min_num = min(list_q)
    for j in range(min_num):
        tmp = tmp[1:]
        tmp = tmp[:-1]
    for k in range(list_q[0] - min_num):
        tmp = tmp[1:]
    for k in range(list_q[1] - min_num):
        tmp = tmp[:-1]
    tmp = tmp.split("AC")
    print(len(tmp) - 1)


Fixed submission:
import sys
input = sys.stdin.readline
N, Q = map(int,input().split())
S = list(input())[:-1]
list_Sum = [0]*(N+1)
for i in range(1, N):
    list_Sum[i+1] = list_Sum[i]
    if S[i-1] == "A" and S[i] == "C":
        list_Sum[i+1] += 1
for i in range(Q):
    l, r = map(int,input().split())
    print(list_Sum[r]-list_Sum[l])

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = input()
for i in range(q):
    list_q = list(map(int, input().split()))
    list_q[0] = list_q[0] - 1
    list_q[1] = n - list_q[1]
    min_num = min(list_q)
    for j in range(min_num):
        s = s[1:]
        s = s[:-1]
    for k in range(list_q[0] - min_num):
        s = s[1:]
    for k in range(list_q[1] - min_num):
        s = s[:-1]
    s = s.split("AC")
    print(len(s) - 1)


Fixed submission:
import sys
input = sys.stdin.readline
N, Q = map(int,input().split())
S = list(input())[:-1]
list_Sum = [0]*(N+1)
for i in range(1, N):
    list_Sum[i+1] = list_Sum[i]
    if S[i-1] == "A" and S[i] == "C":
        list_Sum[i+1] += 1
for i in range(Q):
    l, r = map(int,input().split())
    print(list_Sum[r]-list_Sum[l])

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = input()
for i in range(q):
    list_q = list(map(int, input().split()))
    list_q[1] = n - list_q[1]
    for i in range(list_q[0] - 1):
        s = s[1:]
    for i in range(list_q[1]):
        s = s[:-1]
    s = s.split("AC")
    print(len(s) - 1)


Fixed submission:
import sys
input = sys.stdin.readline
N, Q = map(int,input().split())
S = list(input())[:-1]
list_Sum = [0]*(N+1)
for i in range(1, N):
    list_Sum[i+1] = list_Sum[i]
    if S[i-1] == "A" and S[i] == "C":
        list_Sum[i+1] += 1
for i in range(Q):
    l, r = map(int,input().split())
    print(list_Sum[r]-list_Sum[l])

Buggy python submission (verdict: Time Limit Exceeded):
def print_list(n, s, list_q):
    list_q[1] = n - list_q[1]
    for i in range(list_q[0] - 1):
        s = s[1:]
    for i in range(list_q[1]):
        s = s[:-1]
    s = s.split("AC")
    print(len(s) - 1)


n, q = map(int, input().split())
s = input()
for i in range(q):
    print_list(n, s, list(map(int, input().split())))


Fixed submission:
import sys
input = sys.stdin.readline
N, Q = map(int,input().split())
S = list(input())[:-1]
list_Sum = [0]*(N+1)
for i in range(1, N):
    list_Sum[i+1] = list_Sum[i]
    if S[i-1] == "A" and S[i] == "C":
        list_Sum[i+1] += 1
for i in range(Q):
    l, r = map(int,input().split())
    print(list_Sum[r]-list_Sum[l])

Buggy python submission (verdict: Time Limit Exceeded):
def print_list(n, s, list_q):
    tmp = 0
    count = 0
    list_q[1] = n - list_q[1]
    for i in range(list_q[0] - 1):
        s = s[1:]
    for i in range(list_q[1]):
        s = s[:-1]
    s = s.split("AC")
    print(len(s) - 1)


n, q = map(int, input().split())
s = input()
for i in range(q):
    print_list(n, s, list(map(int, input().split())))


Fixed submission:
import sys
input = sys.stdin.readline
N, Q = map(int,input().split())
S = list(input())[:-1]
list_Sum = [0]*(N+1)
for i in range(1, N):
    list_Sum[i+1] = list_Sum[i]
    if S[i-1] == "A" and S[i] == "C":
        list_Sum[i+1] += 1
for i in range(Q):
    l, r = map(int,input().split())
    print(list_Sum[r]-list_Sum[l])