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())
    str = S[l-1:r]
    print(str.count("AC"))

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

count_list = [0]*(N+1)

for i in range(N):
    if S[i:i+2] == 'AC':
        count_list[i+1] = count_list[i] + 1
    else:
        count_list[i+1] = count_list[i]

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

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

count_list = [0]*(N+1)

for i in range(N):
    if S[i:i+2] == 'AC':
        count_list[i+1] = count_list[i] + 1
    else:
        count_list[i+1] = count_list[i]

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

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

for i in range(Q):
    str = S[lr_lists[i][0] -1:lr_lists[i][1] ]
    print(str.count("AC"))

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

count_list = [0]*(N+1)

for i in range(N):
    if S[i:i+2] == 'AC':
        count_list[i+1] = count_list[i] + 1
    else:
        count_list[i+1] = count_list[i]

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

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

for i in range(Q):
    start = lr_lists[i][0] -1
    end = lr_lists[i][1] 
    str = S[start:end]
    

    count = 0
    """
    for j in range(0,len(str)-1):
        if str[j] == "A" and str[j+1] == "C":
            count += 1
    """
    count = str.count("AC")

    print(count)

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

count_list = [0]*(N+1)

for i in range(N):
    if S[i:i+2] == 'AC':
        count_list[i+1] = count_list[i] + 1
    else:
        count_list[i+1] = count_list[i]

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

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

for i in range(Q):
    start = lr_lists[i][0] -1
    end = lr_lists[i][1] 
    str_list = S[start:end]

    count = 0
    for j in range(0,len(str_list)-1):
        if str_list[j] == "A" and str_list[j+1] == "C":
            count += 1
    print(count)

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

count_list = [0]*(N+1)

for i in range(N):
    if S[i:i+2] == 'AC':
        count_list[i+1] = count_list[i] + 1
    else:
        count_list[i+1] = count_list[i]

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