Buggy python submission (verdict: Runtime Error):
N,Q = map(int,input().split())
S = input()

AC_list = [0]*N
for i in range(N):
    if S[i:i+2] == "AC":
        AC_list[i] = AC_list[i-1]+1
    else:
        AC_list[i] = AC_list[i-1]

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

Fixed submission:
N,Q = map(int,input().split())
S = input()

AC_list = [0]*(N+1)
for i in range(N):
    if S[i:i+2] == "AC":
        AC_list[i+1] = AC_list[i]+1
    else:
        AC_list[i+1] = AC_list[i]

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

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()

AC_list = []
for i in range(len(S)):
    if S[i:i+2] == "AC":
        AC_list.append(i)
    else:
        pass
    
for i in range(Q):
    l, r = map(int,input().split())
    ans = 0
    for j in AC_list:
        if l-1 <= j <= r-2:
            ans += 1
        elif j > r-2:
            break
    print(ans)

Fixed submission:
N,Q = map(int,input().split())
S = input()

AC_list = [0]*(N+1)
for i in range(N):
    if S[i:i+2] == "AC":
        AC_list[i+1] = AC_list[i]+1
    else:
        AC_list[i+1] = AC_list[i]

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

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()

judge = 0
AC_list = []
for i in range(len(S)):
    if S[i] == "A":
        judge = 1
    elif S[i] =="C":
        if judge == 1:
            judge = 0
            AC_list.append(i-1)
        else:
            pass
    else:
        judge = 0
        
for i in range(Q):
    l, r = map(int,input().split())
    ans = 0
    for j in AC_list:
        if l-1 <= j <= r-2:
            ans += 1
        elif j > r-2:
            break
    print(ans)

Fixed submission:
N,Q = map(int,input().split())
S = input()

AC_list = [0]*(N+1)
for i in range(N):
    if S[i:i+2] == "AC":
        AC_list[i+1] = AC_list[i]+1
    else:
        AC_list[i+1] = AC_list[i]

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

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()

judge = 0
AC_list = []
for i in range(len(S)):
    if S[i] == "A":
        judge = 1
    elif S[i] =="C":
        if judge == 1:
            judge = 0
            AC_list.append(i-1)
        else:
            pass
    else:
        judge = 0
        
for i in range(Q):
    l, r = map(int,input().split())
    ans = sum(l-1 <= j <= r-2 for j in AC_list)
    print(ans)

Fixed submission:
N,Q = map(int,input().split())
S = input()

AC_list = [0]*(N+1)
for i in range(N):
    if S[i:i+2] == "AC":
        AC_list[i+1] = AC_list[i]+1
    else:
        AC_list[i+1] = AC_list[i]

for i in range(Q):
    l, r = map(int,input().split())
    print(AC_list[r-1]-AC_list[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()

AC_list = [0]*(N+1)
for i in range(N):
    if S[i:i+2] == "AC":
        AC_list[i+1] = AC_list[i]+1
    else:
        AC_list[i+1] = AC_list[i]

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