Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()
s = s.replace('AC','aC')
ac = []
for i in range(len(s)):
  if s[i] == 'a':
    ac.append(i)

lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  cnt = 0
  for j in range(len(ac)):
    if lr[i][0]-1 <= ac[j] <= lr[i][1] - 2:
      cnt += 1
  print(cnt)

Fixed submission:
n,q = map(int,input().split())
s = input()

ac = [0] * (n - 1)
for i in range(n-1):
  if s[i] == 'A' and s[i+1] == 'C':
    ac[i] = 1

acc = [0] * n
for i in range(n-1):
  acc[i+1] = acc[i] + ac[i]

lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  l = lr[i][0] - 1
  r = lr[i][1] - 1
  print(acc[r] - acc[l])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()
s = s.replace('AC','aC')
lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  temp = list(s[lr[i][0]-1:lr[i][1]])
  cnt = temp[:-1].count('a')
  print(cnt)

Fixed submission:
n,q = map(int,input().split())
s = input()

ac = [0] * (n - 1)
for i in range(n-1):
  if s[i] == 'A' and s[i+1] == 'C':
    ac[i] = 1

acc = [0] * n
for i in range(n-1):
  acc[i+1] = acc[i] + ac[i]

lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  l = lr[i][0] - 1
  r = lr[i][1] - 1
  print(acc[r] - acc[l])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()
lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  temp = list(s[lr[i][0]-1:lr[i][1]])
  cnt = 0
  while len(temp) > 1:
    x = temp.pop()
    y = temp[-1]
    if x == 'C' and y == 'A':
      cnt += 1
  print(cnt)

Fixed submission:
n,q = map(int,input().split())
s = input()

ac = [0] * (n - 1)
for i in range(n-1):
  if s[i] == 'A' and s[i+1] == 'C':
    ac[i] = 1

acc = [0] * n
for i in range(n-1):
  acc[i+1] = acc[i] + ac[i]

lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  l = lr[i][0] - 1
  r = lr[i][1] - 1
  print(acc[r] - acc[l])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()
lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  temp = list(reversed(s[lr[i][0]-1:lr[i][1]]))
  cnt = 0
  while len(temp) > 1:
    x = temp.pop()
    y = temp[-1]
    if x == 'A' and y == 'C':
      cnt += 1
  print(cnt)

Fixed submission:
n,q = map(int,input().split())
s = input()

ac = [0] * (n - 1)
for i in range(n-1):
  if s[i] == 'A' and s[i+1] == 'C':
    ac[i] = 1

acc = [0] * n
for i in range(n-1):
  acc[i+1] = acc[i] + ac[i]

lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  l = lr[i][0] - 1
  r = lr[i][1] - 1
  print(acc[r] - acc[l])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()
lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  temp = s[lr[i][0]-1:lr[i][1]]
  cnt =0
  j = -1
  while True:
    j = temp.find('AC')
    temp = temp[j+1:]
    if j == -1:
      break
    cnt += 1
  print(cnt)

Fixed submission:
n,q = map(int,input().split())
s = input()

ac = [0] * (n - 1)
for i in range(n-1):
  if s[i] == 'A' and s[i+1] == 'C':
    ac[i] = 1

acc = [0] * n
for i in range(n-1):
  acc[i+1] = acc[i] + ac[i]

lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  l = lr[i][0] - 1
  r = lr[i][1] - 1
  print(acc[r] - acc[l])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()
lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  temp = s[lr[i][0]-1:lr[i][1]]
  cnt =0
  j = -1
  while True:
    j = temp.find('AC', j+1)
    if j == -1:
      break
    cnt += 1
  print(cnt)

Fixed submission:
n,q = map(int,input().split())
s = input()

ac = [0] * (n - 1)
for i in range(n-1):
  if s[i] == 'A' and s[i+1] == 'C':
    ac[i] = 1

acc = [0] * n
for i in range(n-1):
  acc[i+1] = acc[i] + ac[i]

lr = [tuple(map(int,input().split())) for _ in range(q)]
for i in range(q):
  l = lr[i][0] - 1
  r = lr[i][1] - 1
  print(acc[r] - acc[l])