Buggy python submission (verdict: Runtime Error):
n,q = map(int, input().split())
s = input()

counts = [1 if s[i]=="A" and s[i+1]=="C" else 0 for i in range(n)]
cum_counts = [sum(counts[:i]) for i in range(n)]

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

Fixed submission:
n,q = map(int, input().split())
s = input()

counts = [1 if s[i:i+2]=="AC" else 0 for i in range(n)]

cum_counts=[0]*n
for i in range(1,n):
  cum_counts[i]=cum_counts[i-1]+counts[i-1]

#print(counts)
#print(cum_counts)

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

Buggy python submission (verdict: Time Limit Exceeded):
import re
n,q = map(int, input().split())
s = input()
l = [0]*q
r = [0]*q
for i in range(q):
  l[i],r[i] = map(int, input().split())

counts = [0]*n

pattern = "AC"
result = re.finditer(pattern, s)
for res in result:
  counts[res.start()] = 1

cum_counts = [sum(counts[:i]) for i in range(n)]

#print(s)
#print(cum_counts)

for i in range(q):
  ret = cum_counts[r[i]-1] - cum_counts[l[i]-1]
  print(ret)

Fixed submission:
n,q = map(int, input().split())
s = input()

counts = [1 if s[i:i+2]=="AC" else 0 for i in range(n)]

cum_counts=[0]*n
for i in range(1,n):
  cum_counts[i]=cum_counts[i-1]+counts[i-1]

#print(counts)
#print(cum_counts)

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

Buggy python submission (verdict: Time Limit Exceeded):

n,q = map(int, input().split())
s = input()

counts = [1 if s[i]=="A" and s[i+1]=="C" else 0 for i in range(n-1)]

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

Fixed submission:
n,q = map(int, input().split())
s = input()

counts = [1 if s[i:i+2]=="AC" else 0 for i in range(n)]

cum_counts=[0]*n
for i in range(1,n):
  cum_counts[i]=cum_counts[i-1]+counts[i-1]

#print(counts)
#print(cum_counts)

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

Buggy python submission (verdict: Time Limit Exceeded):
import re
n,q = map(int, input().split())
s = input()
l = [0]*q
r = [0]*q
counts = [0]*n

pattern = "AC"
result = re.finditer(pattern, s)
for res in result:
  counts[res.start()] = 1

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

Fixed submission:
n,q = map(int, input().split())
s = input()

counts = [1 if s[i:i+2]=="AC" else 0 for i in range(n)]

cum_counts=[0]*n
for i in range(1,n):
  cum_counts[i]=cum_counts[i-1]+counts[i-1]

#print(counts)
#print(cum_counts)

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

Buggy python submission (verdict: Time Limit Exceeded):
import re
n,q = map(int, input().split())
s = input()
l = [0]*q
r = [0]*q
for i in range(q):
  l[i],r[i] = map(int, input().split())

counts = [0]*n

pattern = "AC"
result = re.finditer(pattern, s)
for res in result:
  counts[res.start()] = 1

for i in range(q):
  print(sum(counts[l[i]-1:r[i]-1]))

Fixed submission:
n,q = map(int, input().split())
s = input()

counts = [1 if s[i:i+2]=="AC" else 0 for i in range(n)]

cum_counts=[0]*n
for i in range(1,n):
  cum_counts[i]=cum_counts[i-1]+counts[i-1]

#print(counts)
#print(cum_counts)

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

Buggy python submission (verdict: Time Limit Exceeded):
import re
n,q = map(int, input().split())
s = input()
l = [0]*q
r = [0]*q
for i in range(q):
  l[i],r[i] = map(int, input().split())

counts = [0]*n

pattern = "AC"
result = re.finditer(pattern, s)
for res in result:
  counts[res.start()] = 1

for i in range(q):
  tmp = counts[l[i]-1:r[i]]
  if tmp[-1]==1:
    tmp[-1]=0
  ret=sum(tmp)
  print(ret)

Fixed submission:
n,q = map(int, input().split())
s = input()

counts = [1 if s[i:i+2]=="AC" else 0 for i in range(n)]

cum_counts=[0]*n
for i in range(1,n):
  cum_counts[i]=cum_counts[i-1]+counts[i-1]

#print(counts)
#print(cum_counts)

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

Buggy python submission (verdict: Time Limit Exceeded):
import re
n,q = map(int, input().split())
s = input()

l = [0]*q
r = [0]*q
for i in range(q):
  l[i],r[i] = map(int, input().split())
  
where_a=[0]*n
where_c=[0]*n
pattern = "AC"
result = re.finditer(pattern, s)
i=0
for res in result:
  i+=1
  tmp=res.span()
  where_a[tmp[0]]=i
  where_c[tmp[1]-1]=i

  
for i in range(q):
  tmp1 = where_a[l[i]-1:r[i]]
  tmp2 = where_c[l[i]-1:r[i]]
  tmp3 = set(tmp1) & set(tmp2) -{0}
  #print(tmp3)
  print(len(tmp3))
  

Fixed submission:
n,q = map(int, input().split())
s = input()

counts = [1 if s[i:i+2]=="AC" else 0 for i in range(n)]

cum_counts=[0]*n
for i in range(1,n):
  cum_counts[i]=cum_counts[i-1]+counts[i-1]

#print(counts)
#print(cum_counts)

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