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

for i in range(Q):
  before_a = False
  ans = 0
  for j in range(LR[i][0]-1, LR[i][1]):
    if before_a and S[j] == 'C':
      ans += 1
      before_a = False
    elif S[j] == 'A':
      before_a = True
    else:
      before_a = False
  print(ans)
    


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

P = [0] * (N)
before_a = False
cnt = 0
for i in range(N):
  if before_a and S[i] == 'C':
    cnt += 1
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
  P[i] = cnt
for i in range(Q):
  print(P[LR[i][1]-1] - P[LR[i][0]-1])

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

for i in range(Q):
  before_a = False
  ans = 0
  for j in range(LR[i][0]-1, LR[i][1]):
    if before_a and S[j] == 'C':
      ans += 1
      before_a = False
    elif S[j] == 'A':
      before_a = True
    else:
      before_a = False
  print(ans)
    

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

P = [0] * (N)
before_a = False
cnt = 0
for i in range(N):
  if before_a and S[i] == 'C':
    cnt += 1
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
  P[i] = cnt
for i in range(Q):
  print(P[LR[i][1]-1] - P[LR[i][0]-1])

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

P = []
before_a = False
for i in range(N):
  if before_a and S[i] == 'C':
    P.append(i)
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
for i in range(Q):
  ans = 0
  for num in P:
    if num >= LR[i][0] and num <= LR[i][1]-1:
      ans += 1
    elif num > LR[i][1]-1:
      break
  print(ans)


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

P = [0] * (N)
before_a = False
cnt = 0
for i in range(N):
  if before_a and S[i] == 'C':
    cnt += 1
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
  P[i] = cnt
for i in range(Q):
  print(P[LR[i][1]-1] - P[LR[i][0]-1])

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

P = []
before_a = False
for i in range(N):
  if before_a and S[i] == 'C':
    P.append(i)
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
for i in range(Q):
  ans = 0
  for num in P:
    if num >= LR[i][0] and num <= LR[i][1]-1:
      ans += 1
    elif num > LR[i][1]-1:
      break
  print(ans)

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

P = [0] * (N)
before_a = False
cnt = 0
for i in range(N):
  if before_a and S[i] == 'C':
    cnt += 1
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
  P[i] = cnt
for i in range(Q):
  print(P[LR[i][1]-1] - P[LR[i][0]-1])

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

P = []
before_a = False
for i in range(N):
  if before_a and S[i] == 'C':
    P.append(i)
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
for i in range(Q):
  ans = 0
  for num in P:
    if num >= LR[i][0] and num <= LR[i][1]-1:
      ans += 1
  print(ans)

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

P = [0] * (N)
before_a = False
cnt = 0
for i in range(N):
  if before_a and S[i] == 'C':
    cnt += 1
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
  P[i] = cnt
for i in range(Q):
  print(P[LR[i][1]-1] - P[LR[i][0]-1])

Buggy python submission (verdict: Runtime Error):
from functools import reduce

N, Q = map(int, input())
S = input()
LR = [list(map(int, input())) for i in range(Q)]

P = []
before_a = False
for i in range(N):
  if before_a and S[i] == 'C':
    P.append(i)
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
for i in range(Q):
  ans = 0
  for num in P:
    if num-1 >= LR[i][0] and num <= LR[i][1]:
      ans += 1
  print(ans)
    


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

P = [0] * (N)
before_a = False
cnt = 0
for i in range(N):
  if before_a and S[i] == 'C':
    cnt += 1
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
  P[i] = cnt
for i in range(Q):
  print(P[LR[i][1]-1] - P[LR[i][0]-1])

Buggy python submission (verdict: Runtime Error):
from functools import reduce

N, Q = map(int, input())
S = input()
LR = [list(map(int, input())) for i in range(Q)]

P = []
before_a = False
for i in range(N):
  if before_a and S[i] == 'C':
    P.append(i)
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
for i in range(Q):
  ans = 0
  for num in P:
    if num-1 >= LR[i][0] and num >= LR[i][1]:
      ans += 1
  print(ans)
    


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

P = [0] * (N)
before_a = False
cnt = 0
for i in range(N):
  if before_a and S[i] == 'C':
    cnt += 1
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
  P[i] = cnt
for i in range(Q):
  print(P[LR[i][1]-1] - P[LR[i][0]-1])

Buggy python submission (verdict: Runtime Error):
from functools import reduce

N, Q = map(int, input())
S = input()
LR = [list(map(int, input())) for i in range(Q)]

P = []
before_a = False
for i in range(N):
  if before_a and S[i] == 'C':
    P.append(i)
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
for i in range(Q):
  print(reduce(lambda x: if x >= RL[i][0]-1 and x <= RL[i][1]: return 1, P))
    

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

P = [0] * (N)
before_a = False
cnt = 0
for i in range(N):
  if before_a and S[i] == 'C':
    cnt += 1
    before_a = False
  elif S[i] == 'A':
    before_a = True
  else:
    before_a = False
  P[i] = cnt
for i in range(Q):
  print(P[LR[i][1]-1] - P[LR[i][0]-1])