Buggy python submission (verdict: Time Limit Exceeded):
import re
N, Q = map(int, input().split())
S = input()
idx_list = [1 if S[i:i + 2] == 'AC' else 0 for i in range(len(S) - 1)]
for _ in range(Q):
  l, r = map(int, input().split())
  print(sum(idx_list[l - 1:r - 1]))


Fixed submission:
from itertools import accumulate
from operator import add

N, Q = map(int, input().split())
S = input()
idx_list = [1 if S[i:i + 2] == 'AC' else 0 for i in range(len(S) - 1)]
idx_list_cumsum = [0] + list(accumulate(idx_list, add))

for _ in range(Q):
  l, r = map(int, input().split())
  print(idx_list_cumsum[r - 1] - idx_list_cumsum[l - 1])

Buggy python submission (verdict: Time Limit Exceeded):
import re
N, Q = map(int, input().split())
S = input()
for _ in range(Q):
  l, r = map(int, input().split())
  print(len(re.findall('AC', S[l - 1:r])))


Fixed submission:
from itertools import accumulate
from operator import add

N, Q = map(int, input().split())
S = input()
idx_list = [1 if S[i:i + 2] == 'AC' else 0 for i in range(len(S) - 1)]
idx_list_cumsum = [0] + list(accumulate(idx_list, add))

for _ in range(Q):
  l, r = map(int, input().split())
  print(idx_list_cumsum[r - 1] - idx_list_cumsum[l - 1])

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
for _ in range(Q):
  l, r = map(int, input().split())
  print(len(re.findall('AC', S[l - 1:r])))


Fixed submission:
from itertools import accumulate
from operator import add

N, Q = map(int, input().split())
S = input()
idx_list = [1 if S[i:i + 2] == 'AC' else 0 for i in range(len(S) - 1)]
idx_list_cumsum = [0] + list(accumulate(idx_list, add))

for _ in range(Q):
  l, r = map(int, input().split())
  print(idx_list_cumsum[r - 1] - idx_list_cumsum[l - 1])

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

Fixed submission:
from itertools import accumulate
from operator import add

N, Q = map(int, input().split())
S = input()
idx_list = [1 if S[i:i + 2] == 'AC' else 0 for i in range(len(S) - 1)]
idx_list_cumsum = [0] + list(accumulate(idx_list, add))

for _ in range(Q):
  l, r = map(int, input().split())
  print(idx_list_cumsum[r - 1] - idx_list_cumsum[l - 1])

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


Fixed submission:
from itertools import accumulate
from operator import add

N, Q = map(int, input().split())
S = input()
idx_list = [1 if S[i:i + 2] == 'AC' else 0 for i in range(len(S) - 1)]
idx_list_cumsum = [0] + list(accumulate(idx_list, add))

for _ in range(Q):
  l, r = map(int, input().split())
  print(idx_list_cumsum[r - 1] - idx_list_cumsum[l - 1])

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

ans = []
for i in range(len(s) - 1):
  if s[i:i + 2] == 'AC':
      ans.append(i)
      
for _ in range(Q):
  l, r = map(int, input().split())
  print(sum([1 for i in ans 
             if l <= i + 1 < r]))


Fixed submission:
from itertools import accumulate
from operator import add

N, Q = map(int, input().split())
S = input()
idx_list = [1 if S[i:i + 2] == 'AC' else 0 for i in range(len(S) - 1)]
idx_list_cumsum = [0] + list(accumulate(idx_list, add))

for _ in range(Q):
  l, r = map(int, input().split())
  print(idx_list_cumsum[r - 1] - idx_list_cumsum[l - 1])

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

for _ in range(Q):
  l, r = map(int, input().split())
  x = s[l - 1:r]
  ans = 0
  for i in range(len(x) - 1):
    if x[i:i + 2] == 'AC':
      ans += 1
  print(ans)


Fixed submission:
from itertools import accumulate
from operator import add

N, Q = map(int, input().split())
S = input()
idx_list = [1 if S[i:i + 2] == 'AC' else 0 for i in range(len(S) - 1)]
idx_list_cumsum = [0] + list(accumulate(idx_list, add))

for _ in range(Q):
  l, r = map(int, input().split())
  print(idx_list_cumsum[r - 1] - idx_list_cumsum[l - 1])