Buggy python submission (verdict: Time Limit Exceeded):
import sys
 
N, Q = map(int, input().split())
 
S = input()
 
lr = [list(map(int, i.split())) for i in sys.stdin]
  
for q in lr:
  st = q[0]-1
  en = q[1]
  left = st
  right = st
  s = S[st:en]
  ans = 0
  while right < en+1:
    dif = right - left
    if dif == 2:
      if S[left:right] == 'AC':
        ans += 1
      left += 1
    elif dif == 1:
      right += 1
    elif dif == 0:
      right += 1
      
  print(ans)

Fixed submission:
import sys
 
N, Q = map(int, input().split())
 
S = input()
 
lr = [list(map(int, i.split())) for i in sys.stdin]

Sum = [0]

sum_ = 0

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

for  q in range(Q):
  ans = Sum[lr[q][1]-1]-Sum[lr[q][0]-1]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
 
N, Q = map(int, input().split())
 
S = input()
 
lr = [list(map(int, i.split())) for i in sys.stdin]
  
for q in lr:
  st = q[0]-1
  en = q[1]
  left = st
  right = st
  s = S[st:en]
  ans = 0
  while right < en+1:
    dif = right - left
    if dif == 2:
      if S[left:right] == 'AC':
        ans += 1
      left += 1
    elif dif == 1:
      right += 1
    elif dif == 0:
      right += 1
      
  print(ans)

Fixed submission:
import sys
 
N, Q = map(int, input().split())
 
S = input()
 
lr = [list(map(int, i.split())) for i in sys.stdin]

Sum = [0]

sum_ = 0

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

for  q in range(Q):
  ans = Sum[lr[q][1]-1]-Sum[lr[q][0]-1]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

N, Q = map(int, input().split())
 
S = input()
 
lr = [list(map(int, i.split())) for i in sys.stdin]

# for q in range(Q):
#  lr.append(list(map(int, input().split())))
  
for q in lr:
  st = q[0]-1
  en = q[1]
  s = S[st:en]
  print(s.count('AC'))

Fixed submission:
import sys
 
N, Q = map(int, input().split())
 
S = input()
 
lr = [list(map(int, i.split())) for i in sys.stdin]

Sum = [0]

sum_ = 0

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

for  q in range(Q):
  ans = Sum[lr[q][1]-1]-Sum[lr[q][0]-1]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

N, Q = map(int, input().split())
 
S = input()
 
lr = [list(map(int, i.split())) for i in sys.stdin]

# for q in range(Q):
#  lr.append(list(map(int, input().split())))
  
for q in lr:
  st = q[0]-1
  en = q[1]
  s = S[st:en]
  print(s.count('AC'))

Fixed submission:
import sys
 
N, Q = map(int, input().split())
 
S = input()
 
lr = [list(map(int, i.split())) for i in sys.stdin]

Sum = [0]

sum_ = 0

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

for  q in range(Q):
  ans = Sum[lr[q][1]-1]-Sum[lr[q][0]-1]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
 
S = input()
 
lr = []
 
for q in range(Q):
  lr.append(list(map(int, input().split())))
  
for q in lr:
  st = q[0]-1
  en = q[1]
  s = S[st:en]
  print(s.count('AC'))

Fixed submission:
import sys
 
N, Q = map(int, input().split())
 
S = input()
 
lr = [list(map(int, i.split())) for i in sys.stdin]

Sum = [0]

sum_ = 0

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

for  q in range(Q):
  ans = Sum[lr[q][1]-1]-Sum[lr[q][0]-1]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
 
S = input()
 
lr = []
 
for q in range(Q):
  lr.append(list(map(int, input().split())))
  
for q in lr:
  st = q[0]-1
  en = q[1]
  s = S[st:en]
  print(s.count('AC'))

Fixed submission:
import sys
 
N, Q = map(int, input().split())
 
S = input()
 
lr = [list(map(int, i.split())) for i in sys.stdin]

Sum = [0]

sum_ = 0

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

for  q in range(Q):
  ans = Sum[lr[q][1]-1]-Sum[lr[q][0]-1]
  print(ans)

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

S = input()

lr = []

for q in range(Q):
  lr.append(input().split())
  
for q in lr:
  st = q[0]-1
  en = q[1]
  s = S[st:en]
  print(s.count('AC'))

Fixed submission:
import sys
 
N, Q = map(int, input().split())
 
S = input()
 
lr = [list(map(int, i.split())) for i in sys.stdin]

Sum = [0]

sum_ = 0

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

for  q in range(Q):
  ans = Sum[lr[q][1]-1]-Sum[lr[q][0]-1]
  print(ans)