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

AC_appearance = []
for i in range(len(S)-1):
    if S[i] == 'A' and S[i + 1] == 'C':
        AC_appearance.append(i)

for i in range(Q):
    l, r = map(int, input().split())
    l = l - 1
    r = r - 1
    print(str(len([x for x in AC_appearance if l <= x and x+1 <= r])))

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

AC_appearance = [0] * len(S)
counter = 0
for i in range(1, len(S)):
    if S[i-1] == 'A' and S[i] == 'C':
        counter += 1
    AC_appearance[i] = counter 

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

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = input().split()
S = input()
for i in range(int(Q)):
    str_l, str_r = input().split()
    l = int(str_l)
    r = int(str_r)
    count = 0
    for j in range(0, r - l, 1):
        if 'A' == S[j+l-1]:
            if 'C' == S[j+l]:
                count += 1
    print(count)

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

AC_appearance = [0] * len(S)
counter = 0
for i in range(1, len(S)):
    if S[i-1] == 'A' and S[i] == 'C':
        counter += 1
    AC_appearance[i] = counter 

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

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = input().split()
S = input()
for i in range(int(Q)):
    str_l, str_r = input().split()
    l = int(str_l)
    r = int(str_r)
    count = 0
    for j in range(0, r - l + 1, 2):
        if 'A' == S[j+l-1]:
            if 'C' == S[j+l]:
                count += 1
        elif 'C' == S[j+l-1]:
            if j == 0:
                continue
            if 'A' == S[j+l-2]:
                count += 1
    print(count)

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

AC_appearance = [0] * len(S)
counter = 0
for i in range(1, len(S)):
    if S[i-1] == 'A' and S[i] == 'C':
        counter += 1
    AC_appearance[i] = counter 

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

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = input().split()
S = input()
for i in range(int(Q)):
    str_l, str_r = input().split()
    l =	int(str_l)
    r =	int(str_r)
    count = 0
    for j in range(r - l):
        if 'AC' == S[j+l-1:j+l+1]:
            count += 1
    print(count)

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

AC_appearance = [0] * len(S)
counter = 0
for i in range(1, len(S)):
    if S[i-1] == 'A' and S[i] == 'C':
        counter += 1
    AC_appearance[i] = counter 

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

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = input().split()
S = input()
for i in range(int(Q)):
    l, r = (int(x) for x in input().split())
    count = 0
    for j in range(r - l):
        if 'AC' == S[j+l-1:j+l+1]:
            count += 1
    print(count)

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

AC_appearance = [0] * len(S)
counter = 0
for i in range(1, len(S)):
    if S[i-1] == 'A' and S[i] == 'C':
        counter += 1
    AC_appearance[i] = counter 

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

Buggy python submission (verdict: Runtime Error):
N, Q = input().split()
S = input()
for i in range(int(Q)):
    l, r = (int(x) for x in input().split())
    sub_S = S[l-1:r]
    count = 0
	print('test')

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

AC_appearance = [0] * len(S)
counter = 0
for i in range(1, len(S)):
    if S[i-1] == 'A' and S[i] == 'C':
        counter += 1
    AC_appearance[i] = counter 

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

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = input().split()
S = input()
for i in range(int(Q)):
    l, r = (int(x) for x in input().split())
    sub_S = S[l-1:r]
    count = 0
    for j in range(len(sub_S)-1):
        if 'AC' == sub_S[j:j+2]:
            count += 1
    print(count)

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

AC_appearance = [0] * len(S)
counter = 0
for i in range(1, len(S)):
    if S[i-1] == 'A' and S[i] == 'C':
        counter += 1
    AC_appearance[i] = counter 

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