Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(item) for item in input().split()]
s = input()
lr = [[int(item) for item in input().split()] for _ in range(q)]

is_ac = [0] * n
for i in range(n-2):
  if s[i] == "A":
    if s[i+1] == "C":
      is_ac[i] = 1
   
for item in lr:
  ans = sum(is_ac[item[0]-1: item[1]])
  if s[item[1]-1] == "A":
    if item[1] != n:
      if s[item[1]] == "C":
        ans -= 1
  print(ans)

Fixed submission:
n, q = [int(item) for item in input().split()]
s = input()
lr = [[int(item) for item in input().split()] for _ in range(q)]

is_ac = [0] * n
count = 0
for i in range(n-1):
  if s[i] == "A":
    if s[i+1] == "C":
      count += 1
  is_ac[i+1] = count
is_ac[-1] = count
for item in lr:
  ans = is_ac[item[1]-1] - is_ac[item[0]-1]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, q = [int(item) for item in input().split()]
s = input()
lr = [[int(item) for item in input().split()] for _ in range(q)]

is_ac = np.zeros(n)
for i in range(n-2):
  if s[i:i+2] == "AC":
    is_ac[i] = True

for item in lr:
  ans = sum(is_ac[item[0]-1: item[1]])
  if s[item[1]-1] == "A":
    if item[1] != n:
      if s[item[1]] == "C":
        ans -= 1
  print(int(ans))

Fixed submission:
n, q = [int(item) for item in input().split()]
s = input()
lr = [[int(item) for item in input().split()] for _ in range(q)]

is_ac = [0] * n
count = 0
for i in range(n-1):
  if s[i] == "A":
    if s[i+1] == "C":
      count += 1
  is_ac[i+1] = count
is_ac[-1] = count
for item in lr:
  ans = is_ac[item[1]-1] - is_ac[item[0]-1]
  print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np

n, q = [int(item) for item in input().split()]
s = input()
lr = [[int(item) for item in input().split()] for _ in range(q)]

is_ac = np.zeros(n)
for i in range(n-2):
  if s[i:i+2] == "AC":
    is_ac[i] = True

for item in lr:
  ans = sum(is_ac[item[0]-1: item[1]])
  if s[item[1]-1] == "A":
    if item[1] != n:
      if s[item[1]] == "C":
        ans -= 1
  print(int(ans))

Fixed submission:
n, q = [int(item) for item in input().split()]
s = input()
lr = [[int(item) for item in input().split()] for _ in range(q)]

is_ac = [0] * n
count = 0
for i in range(n-1):
  if s[i] == "A":
    if s[i+1] == "C":
      count += 1
  is_ac[i+1] = count
is_ac[-1] = count
for item in lr:
  ans = is_ac[item[1]-1] - is_ac[item[0]-1]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(item) for item in input().split()]
s = input()
lr = [[int(item) for item in input().split()] for _ in range(q)]

is_ac = [0] * n

for i in range(n-2):
  if s[i:i+2] == "AC":
    is_ac[i] = 1

for item in lr:
  ans = sum(is_ac[item[0]-1: item[1]])
  if s[item[1]-1] == "A" and item[1] != n:
    if s[item[1]] == "C":
      ans -= 1
  print(ans)

Fixed submission:
n, q = [int(item) for item in input().split()]
s = input()
lr = [[int(item) for item in input().split()] for _ in range(q)]

is_ac = [0] * n
count = 0
for i in range(n-1):
  if s[i] == "A":
    if s[i+1] == "C":
      count += 1
  is_ac[i+1] = count
is_ac[-1] = count
for item in lr:
  ans = is_ac[item[1]-1] - is_ac[item[0]-1]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(item) for item in input().split()]
s = input()
lr = [[int(item) for item in input().split()] for _ in range(q)]

is_ac = [0] * n
prev_char = ""

for i in range(n-2):
  if s[i:i+2] == "AC":
    is_ac[i] = 1

for i, item in enumerate(lr):
  ans = sum(is_ac[item[0]-1: item[1]])
  if s[item[1]-1] == "A" and item[1] != n:
    if s[item[1]] == "C":
      ans -= 1
  print(ans)
         
  

Fixed submission:
n, q = [int(item) for item in input().split()]
s = input()
lr = [[int(item) for item in input().split()] for _ in range(q)]

is_ac = [0] * n
count = 0
for i in range(n-1):
  if s[i] == "A":
    if s[i+1] == "C":
      count += 1
  is_ac[i+1] = count
is_ac[-1] = count
for item in lr:
  ans = is_ac[item[1]-1] - is_ac[item[0]-1]
  print(ans)