Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
k = [0] * N
for i in range(1,N):
  v = 1 if S[i-1]+S[i] == 'AC' else 0
  k[i-1] = v
for _ in range(Q):
  f,l = map(int,input().split())
  print(sum(k[f-1:l-1]))

Fixed submission:
N,Q=map(int,input().split())
S=input()
k = [0] * (N+1)

for i in range(1,N):
  v = 1 if S[i-1]+S[i] == 'AC' else 0
  k[i] = k[i-1] + v
k[-1]=k[-2]
for _ in range(Q):
  f,l = map(int,input().split())
  print(k[l-1] - k[f-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
k=[S[0:2]]
for i in range(2,N):
  k.append(k[-1][-1]+S[i])
k.append(S[-1])

for _ in range(Q):
  f,l = map(int,input().split())
  print(k[f-1:l-1].count('AC'))

Fixed submission:
N,Q=map(int,input().split())
S=input()
k = [0] * (N+1)

for i in range(1,N):
  v = 1 if S[i-1]+S[i] == 'AC' else 0
  k[i] = k[i-1] + v
k[-1]=k[-2]
for _ in range(Q):
  f,l = map(int,input().split())
  print(k[l-1] - k[f-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
for lz in range(Q):
  l1,l2=map(int,input().split())
  s1=S[l1-1:l2]
  z=0
  flg=0
  for k in s1:
    if k == 'A':
      flg=1
      continue
    elif k == 'C' and flg == 1:
      z+=1
    flg=0
  print(z)

Fixed submission:
N,Q=map(int,input().split())
S=input()
k = [0] * (N+1)

for i in range(1,N):
  v = 1 if S[i-1]+S[i] == 'AC' else 0
  k[i] = k[i-1] + v
k[-1]=k[-2]
for _ in range(Q):
  f,l = map(int,input().split())
  print(k[l-1] - k[f-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
from collections import Counter
for lz in range(Q):
  l1,l2=map(int,input().split())
  s1=S[l1-1:l2]
  z=0
  flg=0
  for k in s1:
    if k == 'A':
      flg=1
      continue
    elif k == 'C' and flg == 1:
      z+=1
    flg=0
  print(z)

Fixed submission:
N,Q=map(int,input().split())
S=input()
k = [0] * (N+1)

for i in range(1,N):
  v = 1 if S[i-1]+S[i] == 'AC' else 0
  k[i] = k[i-1] + v
k[-1]=k[-2]
for _ in range(Q):
  f,l = map(int,input().split())
  print(k[l-1] - k[f-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
for lz in range(Q):
  l1,l2=map(int,input().split())
  print(S[l1-1:l2].count('AC'))

Fixed submission:
N,Q=map(int,input().split())
S=input()
k = [0] * (N+1)

for i in range(1,N):
  v = 1 if S[i-1]+S[i] == 'AC' else 0
  k[i] = k[i-1] + v
k[-1]=k[-2]
for _ in range(Q):
  f,l = map(int,input().split())
  print(k[l-1] - k[f-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
for lz in range(Q):
  l1,l2=map(int,input().split())
  print(S[l1-1:l2].count('AC'))

Fixed submission:
N,Q=map(int,input().split())
S=input()
k = [0] * (N+1)

for i in range(1,N):
  v = 1 if S[i-1]+S[i] == 'AC' else 0
  k[i] = k[i-1] + v
k[-1]=k[-2]
for _ in range(Q):
  f,l = map(int,input().split())
  print(k[l-1] - k[f-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
l=[list(map(int,input().split())) for _ in range(Q)]
for lz in l:
  print(S[lz[0]-1:lz[1]].count('AC'))

Fixed submission:
N,Q=map(int,input().split())
S=input()
k = [0] * (N+1)

for i in range(1,N):
  v = 1 if S[i-1]+S[i] == 'AC' else 0
  k[i] = k[i-1] + v
k[-1]=k[-2]
for _ in range(Q):
  f,l = map(int,input().split())
  print(k[l-1] - k[f-1])