Buggy python submission (verdict: Runtime Error):
N, Q  = map(int, input().split())
S = list(input())
Lsub = [0] * N
Rsub = [0] * N
L = 0
R = 0


for k in range(1,N):
  if SS[k-1] == "A" and SS[k] == "C":
    L += 1
  Lsub[k] = L

for j in (0,N-1)[::-1]:
  if SS[j] == "A" and SS[j+1] == "C":
    R += 1
  Rsub[j] = R


for i in range(Q):
  L, R = map(int, input().split())
  print(Rsub[0] - Lsub[L-1] - Rsub[R-1])

Fixed submission:
N, Q  = map(int, input().split())
S = list(input())
Lsub = [0]
Rsub = [0]
L = 0
R = 0


for k in range(1,N):
  if S[k-1] == "A" and S[k] == "C":
    L += 1
  Lsub.append(L)

for j in range(0,N-1)[::-1]:
  if S[j] == "A" and S[j+1] == "C":
    R += 1
  Rsub.append(R)


for i in range(Q):
  L, R = map(int, input().split())
  print(Rsub[N-1] - Lsub[L-1] - Rsub[N-R])

Buggy python submission (verdict: Runtime Error):
N, Q  = map(int, input().split())
S = list(input())
Lsub = [0] * N
Rsub = [0] * N
L = 0
R = 0


for k in range(1,N):
  if SS[k-1] == "A" and SS[k] == "C":
    L += 1
  Lsub[k] = L

for j in reversed(range(0,N-1)):
  if SS[j] == "A" and SS[j+1] == "C":
    R += 1
  Rsub[j] = R
  

for i in range(Q):
  L, R = map(int, input().split())
  print(Rsub[0] - Lsub[L-1] - Rsub[R-1])

Fixed submission:
N, Q  = map(int, input().split())
S = list(input())
Lsub = [0]
Rsub = [0]
L = 0
R = 0


for k in range(1,N):
  if S[k-1] == "A" and S[k] == "C":
    L += 1
  Lsub.append(L)

for j in range(0,N-1)[::-1]:
  if S[j] == "A" and S[j+1] == "C":
    R += 1
  Rsub.append(R)


for i in range(Q):
  L, R = map(int, input().split())
  print(Rsub[N-1] - Lsub[L-1] - Rsub[N-R])

Buggy python submission (verdict: Runtime Error):
N, Q  = map(int, input().split())
S = list(input())
Lsub = [0]*N
Rsub = [0]*N
L = 0
R = 0


for j in range(1,N):
  if SS[j-1] == "A" and SS[j] == "C":
    L += 1
  Lsub[j] = L

for j in reversed(range(0,N-1)):
  if SS[j] == "A" and SS[j+1] == "C":
    R += 1
  Rsub[j] = R



ans = [0] * Q

for i in range(Q):
  L, R = map(int, input().split())
  ans[i] = Rsub[0] - Lsub[L-1] - Rsub[R-1]


for i in range(Q):
  print(ans[i])

Fixed submission:
N, Q  = map(int, input().split())
S = list(input())
Lsub = [0]
Rsub = [0]
L = 0
R = 0


for k in range(1,N):
  if S[k-1] == "A" and S[k] == "C":
    L += 1
  Lsub.append(L)

for j in range(0,N-1)[::-1]:
  if S[j] == "A" and S[j+1] == "C":
    R += 1
  Rsub.append(R)


for i in range(Q):
  L, R = map(int, input().split())
  print(Rsub[N-1] - Lsub[L-1] - Rsub[N-R])

Buggy python submission (verdict: Runtime Error):
N, Q  = map(int, input().split())
S = list(input())
Lsub = [0]*N
Rsub = [0]*N
L = 0
R = 0


for j in range(1,N):
  if SS[j-1] == "A" and SS[j] == "C":
    L += 1
  Lsub[j] = L

for j in reversed(range(0,N-1)):
  if SS[j] == "A" and SS[j+1] == "C":
    R += 1
  Rsub[j] = R



ans = [0] * Q

for i in range(Q):
  L, R = map(int, input().split())
  ans[i] = Rsub[0] - Lsub[L-1] - Rsub[R-1]


for i in range(Q):
  print(ans[i])

Fixed submission:
N, Q  = map(int, input().split())
S = list(input())
Lsub = [0]
Rsub = [0]
L = 0
R = 0


for k in range(1,N):
  if S[k-1] == "A" and S[k] == "C":
    L += 1
  Lsub.append(L)

for j in range(0,N-1)[::-1]:
  if S[j] == "A" and S[j+1] == "C":
    R += 1
  Rsub.append(R)


for i in range(Q):
  L, R = map(int, input().split())
  print(Rsub[N-1] - Lsub[L-1] - Rsub[N-R])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q  = map(int, input().split())
S = list(input())
ans = [0] * Q
A = 0

for i in range(Q):
  L, R = map(int, input().split())
  A = 0
  SS = S[L-1:R]
  for j in range(len(SS)-1):
    if SS[j] == "A" and SS[j+1] == "C":
      A += 1
  ans[i] = A

for i in range(Q):
  print(ans[i])

Fixed submission:
N, Q  = map(int, input().split())
S = list(input())
Lsub = [0]
Rsub = [0]
L = 0
R = 0


for k in range(1,N):
  if S[k-1] == "A" and S[k] == "C":
    L += 1
  Lsub.append(L)

for j in range(0,N-1)[::-1]:
  if S[j] == "A" and S[j+1] == "C":
    R += 1
  Rsub.append(R)


for i in range(Q):
  L, R = map(int, input().split())
  print(Rsub[N-1] - Lsub[L-1] - Rsub[N-R])