Buggy python submission (verdict: Runtime Error):
N,Q=map(int,input().split())
S=input()

lis = [0] * len(S)
for i in range(len(S)):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S)-1 and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])


Fixed submission:
N,Q=map(int,input().split())
S=input()

lis = [0] * len(S)
for i in range(len(S)):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S)-1 and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

Buggy python submission (verdict: Runtime Error):
N,Q=map(int,input().split())
S=input()

lis = [0] * (len(S)+1)
for i in range(len(S)+1):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S) and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1

    
for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

Fixed submission:
N,Q=map(int,input().split())
S=input()

lis = [0] * len(S)
for i in range(len(S)):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S)-1 and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()

lis = []
for i in range(len(S)-1):
  if S[i] == 'A' and S[i+1] == 'C':
    lis += [i]

for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  for l in lis:
    if L[0] - 1 <= l < L[1] - 1:
      c+=1
      
  
  print(c)


Fixed submission:
N,Q=map(int,input().split())
S=input()

lis = [0] * len(S)
for i in range(len(S)):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S)-1 and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()

lis = []
for i in range(len(S)-1):
  if S[i:i+2] == 'AC':
    lis += [i]

for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  for l in lis:
    if L[0] - 1 <= l < L[1] - 1:
      c+=1
      
  
  print(c)


Fixed submission:
N,Q=map(int,input().split())
S=input()

lis = [0] * len(S)
for i in range(len(S)):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S)-1 and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()

lis = []
p=0
while True:
  p = S.find("AC", p)

  if p < 0:
    break

  lis += [p]

  p+=2

for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  for l in lis:
    if L[0] - 1 <= l < L[1] - 1:
      c+=1
      
  
  print(c)


Fixed submission:
N,Q=map(int,input().split())
S=input()

lis = [0] * len(S)
for i in range(len(S)):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S)-1 and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

Buggy python submission (verdict: Runtime Error):
_=input()
A=map(lambda x:("A", int(x)), input())
B=map(lambda x:("B", int(x)), input())
C=map(lambda x:("C", int(x)), input())
S = sorted(A, cmp=lambda x, y:-x[1] + y[1])

A=None
B=None
C=None
for i in len(S):
  if A==None and x[0]=="A":
    A=i
  elif B==None and x[0]=="B":
    B=i
  elif C==None and x[0]=="C":
  	C=i

for i in [A, B, C].sort()[::-1]:
  del S[i]

print(S)


Fixed submission:
N,Q=map(int,input().split())
S=input()

lis = [0] * len(S)
for i in range(len(S)):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S)-1 and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()

lis = []
p=0
while True:
  p = S.find("AC", p)

  if p < 0:
    break

  lis += [p]

  p+=2

for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  for l in lis:
    if L[0] - 1 <= l < L[1] - 1:
      c+=1
      
  
  print(c)


Fixed submission:
N,Q=map(int,input().split())
S=input()

lis = [0] * len(S)
for i in range(len(S)):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S)-1 and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
for _ in range(Q):
  L = tuple(map(int, input().split()))

  p = L[0] - 1
  c = 0
  while True:
    p = S.find("AC", p)

    if p < 0 or p >= L[1]-1:
      break

    c+=1
    p+=2
  print(c)


Fixed submission:
N,Q=map(int,input().split())
S=input()

lis = [0] * len(S)
for i in range(len(S)):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S)-1 and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
L=[tuple(map(int, input().split())) for _ in range(Q)]
print("\n".join([str(len(S[nS-1:nE])-len(S[nS-1:nE].replace("AC", "|"))) for nS, nE in L]))


Fixed submission:
N,Q=map(int,input().split())
S=input()

lis = [0] * len(S)
for i in range(len(S)):

  if i>0:
    lis[i] += lis[i-1]
  if i < len(S)-1 and S[i] == 'A' and S[i+1] == 'C':
    lis[i+1] += 1


for _ in range(Q):
  L = tuple(map(int, input().split()))

  c = 0
  print(lis[L[1]-1]-lis[L[0]-1])