Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
tmp=[0]*n
for i in range(n):
  if 'AC' == s[i:i+2]:
    tmp[i+1]=1
for i in range(q):
  l,r = map(int,input().split())
  print(sum(tmp[l:r]))

Fixed submission:
n,q = map(int, input().split())
s = input()
tmp=[0]
l,cnt=0,0
r=2
while r<=n:
  if 'AC' == s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    l+=1
    r+=1
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
tmp=[]
l,cnt=0,0
r=1
while r<=n:
  if 'AC' in s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    r+=1

for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

Fixed submission:
n,q = map(int, input().split())
s = input()
tmp=[0]
l,cnt=0,0
r=2
while r<=n:
  if 'AC' == s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    l+=1
    r+=1
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys,re
n,q = map(int, input().split())
s = input()
tmp=[]
l,cnt=0,0
s=s.replace('AC','01')
s=list(map(int,list(re.sub('[a-zA-Z]','0',s))))
for i in range(q):
  l,r = map(int,input().split())
  print(sum(s[l:r]))

Fixed submission:
n,q = map(int, input().split())
s = input()
tmp=[0]
l,cnt=0,0
r=2
while r<=n:
  if 'AC' == s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    l+=1
    r+=1
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
tmp=[]
l,cnt=0,0
for r in range(1,n+1):
  if 'AC' in s[l:r]:
    cnt+=1
    l=r
  tmp.append(cnt)

for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

Fixed submission:
n,q = map(int, input().split())
s = input()
tmp=[0]
l,cnt=0,0
r=2
while r<=n:
  if 'AC' == s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    l+=1
    r+=1
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
tmp=[]
l,cnt=0,0
for r in range(1,n+1):
  if 'AC' in s[l:r]:
    cnt+=1
    l=r
  tmp.append(cnt)

for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

Fixed submission:
n,q = map(int, input().split())
s = input()
tmp=[0]
l,cnt=0,0
r=2
while r<=n:
  if 'AC' == s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    l+=1
    r+=1
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
tmp = []
for i in range(1,n+1):
  tmp.append(s[:i].count('AC'))
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

Fixed submission:
n,q = map(int, input().split())
s = input()
tmp=[0]
l,cnt=0,0
r=2
while r<=n:
  if 'AC' == s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    l+=1
    r+=1
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
tmp = []
for i in range(1,n+1):
  tmp.append(s[:i].count('AC'))
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

Fixed submission:
n,q = map(int, input().split())
s = input()
tmp=[0]
l,cnt=0,0
r=2
while r<=n:
  if 'AC' == s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    l+=1
    r+=1
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
lr = [list(map(int,input().split())) for i in range(q)]
tmp = []
for i in range(1,n+1):
  tmp.append(s[:i].count('AC'))

for i in range(q):
  print(tmp[lr[i][1]-1]-tmp[lr[i][0]-1])

Fixed submission:
n,q = map(int, input().split())
s = input()
tmp=[0]
l,cnt=0,0
r=2
while r<=n:
  if 'AC' == s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    l+=1
    r+=1
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
lr = [list(map(int,input().split())) for i in range(q)]
for i in range(q):
  print(len(s[lr[i][0]-1:lr[i][1]].replace('AC',':').split(':'))-1)

Fixed submission:
n,q = map(int, input().split())
s = input()
tmp=[0]
l,cnt=0,0
r=2
while r<=n:
  if 'AC' == s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    l+=1
    r+=1
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
lr = [list(map(int,input().split())) for i in range(q)]
for i in range(q):
  print(len(s[lr[i][0]-1:lr[i][1]].replace('AC',':').split(':'))-1)

Fixed submission:
n,q = map(int, input().split())
s = input()
tmp=[0]
l,cnt=0,0
r=2
while r<=n:
  if 'AC' == s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    l+=1
    r+=1
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

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

Fixed submission:
n,q = map(int, input().split())
s = input()
tmp=[0]
l,cnt=0,0
r=2
while r<=n:
  if 'AC' == s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    l+=1
    r+=1
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

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

Fixed submission:
n,q = map(int, input().split())
s = input()
tmp=[0]
l,cnt=0,0
r=2
while r<=n:
  if 'AC' == s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    l+=1
    r+=1
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])