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

Fixed submission:
n,q = map(int, input().split())
s = input()
c = []
pre = ""
count = 0
for i in range(n):
  if pre == "A" and s[i] == "C":
    count += 1
  pre = s[i]
  c.append(count)
  
for i in range(q):
  l,r = map(int,input().split())
  print(c[r-1]-c[l-1])

Buggy python submission (verdict: Runtime Error):
n,q = map(int, input().split())
s = input()
c = []
for i in range(n+1):
  c.add(s[:i].count("AC"))
  
for i in range(q):
  l,r = map(int,input().split())
  print(c[r]-c[l-1])

Fixed submission:
n,q = map(int, input().split())
s = input()
c = []
pre = ""
count = 0
for i in range(n):
  if pre == "A" and s[i] == "C":
    count += 1
  pre = s[i]
  c.append(count)
  
for i in range(q):
  l,r = map(int,input().split())
  print(c[r-1]-c[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
for i in range(q):
  l,r = map(int,input().split())
  count = 0
  pre = s[l-1]
  skip = False
  for j in range(l, r):
    if skip:
      skip = False
      pre = s[j]
      continue
    if pre == 'A' and s[j] == 'C':
      count += 1
    elif s[j] != 'A':
      skip = True
    pre = s[j]
  print(count)

Fixed submission:
n,q = map(int, input().split())
s = input()
c = []
pre = ""
count = 0
for i in range(n):
  if pre == "A" and s[i] == "C":
    count += 1
  pre = s[i]
  c.append(count)
  
for i in range(q):
  l,r = map(int,input().split())
  print(c[r-1]-c[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = input()
for i in range(q):
  l,r = map(int,input().split())
  count = 0
  pre = s[l-1]
  for j in range(l, r):
    if pre == 'A' and s[j] == 'C':
      count += 1
    pre = s[j]
  print(count)

Fixed submission:
n,q = map(int, input().split())
s = input()
c = []
pre = ""
count = 0
for i in range(n):
  if pre == "A" and s[i] == "C":
    count += 1
  pre = s[i]
  c.append(count)
  
for i in range(q):
  l,r = map(int,input().split())
  print(c[r-1]-c[l-1])

Buggy python submission (verdict: Runtime Error):
n,q = map(int, input().split())
s = input()
for i in range(q):
  l,r = map(int,input().split())
  count = 0
  pre = s[l-1]
  for j in range(l, r):
    if pre == 'A' and s[j] == 'C':
      count += 1
    pre = s[j]
  print(cound)

Fixed submission:
n,q = map(int, input().split())
s = input()
c = []
pre = ""
count = 0
for i in range(n):
  if pre == "A" and s[i] == "C":
    count += 1
  pre = s[i]
  c.append(count)
  
for i in range(q):
  l,r = map(int,input().split())
  print(c[r-1]-c[l-1])

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

Fixed submission:
n,q = map(int, input().split())
s = input()
c = []
pre = ""
count = 0
for i in range(n):
  if pre == "A" and s[i] == "C":
    count += 1
  pre = s[i]
  c.append(count)
  
for i in range(q):
  l,r = map(int,input().split())
  print(c[r-1]-c[l-1])

Buggy python submission (verdict: Runtime Error):
n,q = map(int, input().split())
s = input()
for i in range(q):
  l,r = map(int,input().split())
  print(s[l-1:r]).cound("AC")

Fixed submission:
n,q = map(int, input().split())
s = input()
c = []
pre = ""
count = 0
for i in range(n):
  if pre == "A" and s[i] == "C":
    count += 1
  pre = s[i]
  c.append(count)
  
for i in range(q):
  l,r = map(int,input().split())
  print(c[r-1]-c[l-1])