Buggy python submission (verdict: Runtime Error):
N, Q = list(map(int, input().split()))
S = input()
T = [list(map(int, input().split())) for _ in range(Q)]

total_list = []
total = 0
for i in range(N):
  if S[i] == 'A' and S[i+1] == 'C':
    total += 1
  total_list.append(total)

for i in range(Q):
  l, r = T[i][0], T[i][1]
  if l != 1:
    print(total_list[r-2]-total_list[l-2])
  else:
    print(total_list[r-2])

Fixed submission:
N, Q = list(map(int, input().split()))
S = input()
T = [list(map(int, input().split())) for _ in range(Q)]

total_list = []
total = 0
try:
  for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
      total += 1
    total_list.append(total)

  for i in range(Q):
    l, r = T[i][0], T[i][1]
    if l != 1:
      print(total_list[r-2]-total_list[l-2])
    else:
      print(total_list[r-2])
except IndexError:
  print(0)

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

index = {i for i in range(N-1) if (S[i] == 'A') and (S[i+1] == 'C')}

for i in range(Q):
  l, r = T[i][0], T[i][1]
  print(len(index & set(range(l-1, r-1))))

Fixed submission:
N, Q = list(map(int, input().split()))
S = input()
T = [list(map(int, input().split())) for _ in range(Q)]

total_list = []
total = 0
try:
  for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
      total += 1
    total_list.append(total)

  for i in range(Q):
    l, r = T[i][0], T[i][1]
    if l != 1:
      print(total_list[r-2]-total_list[l-2])
    else:
      print(total_list[r-2])
except IndexError:
  print(0)

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

index = {i for i, X in enumerate(S) if X == 'A'}

for i in range(Q):
  l, r = T[i][0], T[i][1]
  count = 0
  index1 = index & set(range(l-1, r-1))
  for j in index1:
    if S[j+1] =='C':
      count += 1
  print(count)

Fixed submission:
N, Q = list(map(int, input().split()))
S = input()
T = [list(map(int, input().split())) for _ in range(Q)]

total_list = []
total = 0
try:
  for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
      total += 1
    total_list.append(total)

  for i in range(Q):
    l, r = T[i][0], T[i][1]
    if l != 1:
      print(total_list[r-2]-total_list[l-2])
    else:
      print(total_list[r-2])
except IndexError:
  print(0)

Buggy python submission (verdict: Runtime Error):
import re

N, Q = list(map(int, input().split()))
S = input()
T = [list(map(int, input().split())) for _ in range(Q)]

S = re.sub('[^AC]+', 'X', S)
print(S)

for i in range(Q):
  l, r = T[i][0], T[i][1]
  s = S[l-1:r]
  count = 0
  if r-l == 0:
    count = 0
  else:
    for j in range(r-l):
      if s[j] == 'A' and s[j+1] == 'C':
        count += 1
  print(count)

Fixed submission:
N, Q = list(map(int, input().split()))
S = input()
T = [list(map(int, input().split())) for _ in range(Q)]

total_list = []
total = 0
try:
  for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
      total += 1
    total_list.append(total)

  for i in range(Q):
    l, r = T[i][0], T[i][1]
    if l != 1:
      print(total_list[r-2]-total_list[l-2])
    else:
      print(total_list[r-2])
except IndexError:
  print(0)

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

for i in range(Q):
  l, r = T[i][0], T[i][1]
  s = S[l-1:r]
  count = 0
  if r-l == 0:
    count = 0
  else:
    for j in range(r-l):
      if s[j] == 'A' and s[j+1] == 'C':
        count += 1
  print(count)

Fixed submission:
N, Q = list(map(int, input().split()))
S = input()
T = [list(map(int, input().split())) for _ in range(Q)]

total_list = []
total = 0
try:
  for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
      total += 1
    total_list.append(total)

  for i in range(Q):
    l, r = T[i][0], T[i][1]
    if l != 1:
      print(total_list[r-2]-total_list[l-2])
    else:
      print(total_list[r-2])
except IndexError:
  print(0)