Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
list = [[0 for i in range(2)] for j in range(Q)]
#print(list)

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

for i in range(Q):
    sub_S = S[list[i][0]-1:list[i][1]]
    count = 0
    for j in range(len(sub_S)-1):
        if sub_S[j] == 'A':
            if sub_S[j:j+2] == 'AC':
                count += 1
                j += 1
    print(count)

Fixed submission:
N, Q = map(int, input().split())
S = input()
list = [[0 for i in range(2)] for j in range(Q)]

b = [0] * (N+1)
for i in range(N):
    if S[i:i+2] == 'AC':
        b[i+1] = b[i] + 1
    else:
        b[i+1] = b[i]
for i in range(Q):
    l,r = map(int, input().split())
    print(b[r-1]-b[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
list = [[0 for i in range(2)] for j in range(Q)]
#print(list)

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

for i in range(Q):
    sub_S = S[list[i][0]-1:list[i][1]]
    count = 0
    for j in range(len(sub_S)-1):
        if sub_S[j] == 'A':
            if sub_S[j:j+2] == 'AC':
                count += 1
    print(count)

Fixed submission:
N, Q = map(int, input().split())
S = input()
list = [[0 for i in range(2)] for j in range(Q)]

b = [0] * (N+1)
for i in range(N):
    if S[i:i+2] == 'AC':
        b[i+1] = b[i] + 1
    else:
        b[i+1] = b[i]
for i in range(Q):
    l,r = map(int, input().split())
    print(b[r-1]-b[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
list = []
for i in range(Q):
    l,r = map(int, input().split())
    list.append([l,r])

for i in range(Q):
    sub_S = S[list[i][0]-1:list[i][1]]
    count = 0
    for j in range(len(sub_S)-1):
        if sub_S[j] == 'A':
            if sub_S[j:j+2] == 'AC':
                count += 1
    print(count)

Fixed submission:
N, Q = map(int, input().split())
S = input()
list = [[0 for i in range(2)] for j in range(Q)]

b = [0] * (N+1)
for i in range(N):
    if S[i:i+2] == 'AC':
        b[i+1] = b[i] + 1
    else:
        b[i+1] = b[i]
for i in range(Q):
    l,r = map(int, input().split())
    print(b[r-1]-b[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
list = []
for i in range(Q):
    l,r = map(int, input().split())
    list.append([l,r])

#print(list)

target_s = 'AC'
for i in range(Q):
    sub_S = S[list[i][0]-1:list[i][1]]

    '''
    #print(i,sub_S)
    count = 0
    for j in range(len(sub_S)+1-len(target_s)):
        sub_sub_S = sub_S[j:j+len(target_s)]
        #print(sub_sub_S)
        if sub_sub_S == target_s:
            count += 1
    '''

    print(sub_S.count(target_s))

Fixed submission:
N, Q = map(int, input().split())
S = input()
list = [[0 for i in range(2)] for j in range(Q)]

b = [0] * (N+1)
for i in range(N):
    if S[i:i+2] == 'AC':
        b[i+1] = b[i] + 1
    else:
        b[i+1] = b[i]
for i in range(Q):
    l,r = map(int, input().split())
    print(b[r-1]-b[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
list = []
for i in range(Q):
    l,r = map(int, input().split())
    list.append([l,r])

#print(list)

target_s = 'AC'
for i in range(Q):
    sub_S = S[list[i][0]-1:list[i][1]]
    #print(i,sub_S)
    count = 0
    for j in range(len(sub_S)+1-len(target_s)):
        sub_sub_S = sub_S[j:j+len(target_s)]
        #print(sub_sub_S)
        if sub_sub_S == target_s:
            count += 1
    print(count)

Fixed submission:
N, Q = map(int, input().split())
S = input()
list = [[0 for i in range(2)] for j in range(Q)]

b = [0] * (N+1)
for i in range(N):
    if S[i:i+2] == 'AC':
        b[i+1] = b[i] + 1
    else:
        b[i+1] = b[i]
for i in range(Q):
    l,r = map(int, input().split())
    print(b[r-1]-b[l-1])