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:
N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[l-1])

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

for i in range(n-1):
  if s[i:i+2]=='AC':
    ac_list[i] += 1

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

Fixed submission:
N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[l-1])

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

for i in range(n-1):
  if s[i:i+2]=='AC':
    ac_list[i] += 1
  else:
    ac_list[i] += 0

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

Fixed submission:
N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[l-1])

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

for i in range(n-1):
  if s[i:i+2]=='AC':
    ac_list.append(1)
  else:
    ac_list.append(0)

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

Fixed submission:
N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[l-1])

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

for _ in range(q):
  l, r = map(int, input().split())
  s_list.append(s[l-1:r])
  
for s in s_list:
  print(s.count('AC'))

Fixed submission:
N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[l-1])

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

for _ in range(q):
  l, r = map(int, input().split())
  s_list.append(s[l-1:r])
  
for s in s_list:
  print(s.count('AC'))

Fixed submission:
N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[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())
  sub_s = s[l-1:r]
  print(sub_s.count('AC'))

Fixed submission:
N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[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())
  sub_s = s[l-1:r]
  print(sum([sub_s[i:i+2]=='AC' for i in range(r-l)]))

Fixed submission:
N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[l-1])