Buggy python submission (verdict: Time Limit Exceeded):
n,q = [int(i) for i in input().split()]
s = input()
l = []
r = []
for i in range(q):
  l_tmp, r_tmp = [int(j) for j in input().split()]
  l.append(l_tmp-1)
  r.append(r_tmp-1)
  
ac_loc = []
flag = False
for i in range(n-1):
  if flag:
    flag = False
    continue
  if s[i:i+2] == 'AC':
    ac_loc.append(i)
    flag = True
ac_cnt = len(ac_loc)

up_cnt = []
down_cnt = []
for i in range(n):
  up_cnt.append(sum(i<=j for j in ac_loc))
  down_cnt.append(sum(j+1<=i for j in ac_loc))
  
for i in range(q):
  ans = up_cnt[l[i]] + down_cnt[r[i]] - ac_cnt
  print(ans)

Fixed submission:
n,q = [int(i) for i in input().split()]
s = input()
l = []
r = []
for i in range(q):
  l_tmp, r_tmp = [int(j) for j in input().split()]
  l.append(l_tmp-1)
  r.append(r_tmp-1)
  
ac_cnt = s.count('AC')
r_cnt = [ac_cnt]
l_cnt = [0]
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    r_cnt.append(r_cnt[i-1]-1)
    l_cnt.append(l_cnt[i-1]+1)
  else:
    r_cnt.append(r_cnt[i-1])
    l_cnt.append(l_cnt[i-1])
    
for i in range(q):
  ans = r_cnt[l[i]] + l_cnt[r[i]] - ac_cnt
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,q = [int(i) for i in input().split()]
s = input()
ac_loc = []
flag = False
for i in range(n-1):
  if flag:
    flag = False
    continue
  if s[i:i+2] == 'AC':
    ac_loc.append(i)
    flag = True

l = []
r = []
for i in range(q):
  l_tmp, r_tmp = [int(j) for j in input().split()]
  l.append(l_tmp-1)
  r.append(r_tmp-1)
  
for i in range(q):
  ans = sum((l[i]<=j and j+1<=r[i]) for j in ac_loc)
  print(ans)

Fixed submission:
n,q = [int(i) for i in input().split()]
s = input()
l = []
r = []
for i in range(q):
  l_tmp, r_tmp = [int(j) for j in input().split()]
  l.append(l_tmp-1)
  r.append(r_tmp-1)
  
ac_cnt = s.count('AC')
r_cnt = [ac_cnt]
l_cnt = [0]
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    r_cnt.append(r_cnt[i-1]-1)
    l_cnt.append(l_cnt[i-1]+1)
  else:
    r_cnt.append(r_cnt[i-1])
    l_cnt.append(l_cnt[i-1])
    
for i in range(q):
  ans = r_cnt[l[i]] + l_cnt[r[i]] - ac_cnt
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,q = [int(i) for i in input().split()]
s = input()
ac_loc = []
flag = False
for i in range(n-1):
  if flag:
    flag = False
    continue
  if s[i:i+2] == 'AC':
    ac_loc.append(i)
    flag = True

for i in range(q):
  l, r = [int(j) for j in input().split()]
  l -= 1
  r -= 1
  ans = sum((l<=j and j+1<=r) for j in ac_loc)
  print(ans)

Fixed submission:
n,q = [int(i) for i in input().split()]
s = input()
l = []
r = []
for i in range(q):
  l_tmp, r_tmp = [int(j) for j in input().split()]
  l.append(l_tmp-1)
  r.append(r_tmp-1)
  
ac_cnt = s.count('AC')
r_cnt = [ac_cnt]
l_cnt = [0]
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    r_cnt.append(r_cnt[i-1]-1)
    l_cnt.append(l_cnt[i-1]+1)
  else:
    r_cnt.append(r_cnt[i-1])
    l_cnt.append(l_cnt[i-1])
    
for i in range(q):
  ans = r_cnt[l[i]] + l_cnt[r[i]] - ac_cnt
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,q = [int(i) for i in input().split()]
s = input()
ac_loc = []
for i in range(n-1):
  if s[i] =='A':
    if s[i+1] == 'C':
      ac_loc.append(i)
      i+=1 

for i in range(q):
  l, r = [int(j) for j in input().split()]
  l -= 1
  r -= 1
  ans = sum((l<=j and j+1<=r) for j in ac_loc)
  print(ans)

Fixed submission:
n,q = [int(i) for i in input().split()]
s = input()
l = []
r = []
for i in range(q):
  l_tmp, r_tmp = [int(j) for j in input().split()]
  l.append(l_tmp-1)
  r.append(r_tmp-1)
  
ac_cnt = s.count('AC')
r_cnt = [ac_cnt]
l_cnt = [0]
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    r_cnt.append(r_cnt[i-1]-1)
    l_cnt.append(l_cnt[i-1]+1)
  else:
    r_cnt.append(r_cnt[i-1])
    l_cnt.append(l_cnt[i-1])
    
for i in range(q):
  ans = r_cnt[l[i]] + l_cnt[r[i]] - ac_cnt
  print(ans)

Buggy python submission (verdict: Runtime Error):
n,q = [int(i) for i in input().split()]
s = input()
ac_loc = []
for i in range(n):
  if s[i] =='A':
    if s[i+1] == 'C':
      ac_loc.append(i)
      i+=1 

for i in range(q):
  l, r = [int(j) for j in input().split()]
  l -= 1
  r -= 1
  ans = sum((l<=j and j+1<=r) for j in ac_loc)
  print(ans)

Fixed submission:
n,q = [int(i) for i in input().split()]
s = input()
l = []
r = []
for i in range(q):
  l_tmp, r_tmp = [int(j) for j in input().split()]
  l.append(l_tmp-1)
  r.append(r_tmp-1)
  
ac_cnt = s.count('AC')
r_cnt = [ac_cnt]
l_cnt = [0]
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    r_cnt.append(r_cnt[i-1]-1)
    l_cnt.append(l_cnt[i-1]+1)
  else:
    r_cnt.append(r_cnt[i-1])
    l_cnt.append(l_cnt[i-1])
    
for i in range(q):
  ans = r_cnt[l[i]] + l_cnt[r[i]] - ac_cnt
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,q = [int(i) for i in input().split()]
s = input()

for i in range(q):
  l, r = [int(j) for j in input().split()]
  l -= 1
  r -= 1
  s_tmp = s[l:r+1]
  print(s_tmp.count('AC'))

Fixed submission:
n,q = [int(i) for i in input().split()]
s = input()
l = []
r = []
for i in range(q):
  l_tmp, r_tmp = [int(j) for j in input().split()]
  l.append(l_tmp-1)
  r.append(r_tmp-1)
  
ac_cnt = s.count('AC')
r_cnt = [ac_cnt]
l_cnt = [0]
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    r_cnt.append(r_cnt[i-1]-1)
    l_cnt.append(l_cnt[i-1]+1)
  else:
    r_cnt.append(r_cnt[i-1])
    l_cnt.append(l_cnt[i-1])
    
for i in range(q):
  ans = r_cnt[l[i]] + l_cnt[r[i]] - ac_cnt
  print(ans)