Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
# cnt = [S[:i].count('AC') for i in range(1, len(S) + 1)]
# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = S[:r].count('AC') - S[:l].count('AC')
    print(ans)


Fixed submission:
N, Q = map(int, input().split())
S = input()
cnt = [0]
for i in range(2, len(S) + 1):
    if S[i - 2:i] == 'AC':
        v = cnt[-1] + 1
    else:
        v = cnt[-1]
    cnt.append(v)

# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
# cnt = [S[:i].count('AC') for i in range(1, len(S) + 1)]
# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = S[:r].count('AC') - S[:l].count('AC')
    print(ans)


Fixed submission:
N, Q = map(int, input().split())
S = input()
cnt = [0]
for i in range(2, len(S) + 1):
    if S[i - 2:i] == 'AC':
        v = cnt[-1] + 1
    else:
        v = cnt[-1]
    cnt.append(v)

# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
cnt = [S[:i].count('AC') for i in range(1, len(S) + 1)]
# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)


Fixed submission:
N, Q = map(int, input().split())
S = input()
cnt = [0]
for i in range(2, len(S) + 1):
    if S[i - 2:i] == 'AC':
        v = cnt[-1] + 1
    else:
        v = cnt[-1]
    cnt.append(v)

# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
cnt = [S[:i].count('AC') for i in range(1, len(S) + 1)]
# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)


Fixed submission:
N, Q = map(int, input().split())
S = input()
cnt = [0]
for i in range(2, len(S) + 1):
    if S[i - 2:i] == 'AC':
        v = cnt[-1] + 1
    else:
        v = cnt[-1]
    cnt.append(v)

# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc122/tasks/abc122_c
import numpy as np

N, Q = map(int, input().split())
N = int(N)
S = input()
lr = []
for i in range(Q):
    l, r = map(int, input().split())
    lr.append((l - 1, r - 1))

locations = []
for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        locations.append(i)
locations = np.array(locations)
# print('locations', locations)

t = []
for i in range(len(S) + 1):
    t.append(np.count_nonzero(locations < i))
# print(t)
for l, r in lr:
    print(t[r] - t[l])


Fixed submission:
N, Q = map(int, input().split())
S = input()
cnt = [0]
for i in range(2, len(S) + 1):
    if S[i - 2:i] == 'AC':
        v = cnt[-1] + 1
    else:
        v = cnt[-1]
    cnt.append(v)

# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc122/tasks/abc122_c
import numpy as np

N, Q = map(int, input().split())
N = int(N)
S = input()
lr = []
for _ in range(Q):
    l, r = map(int, input().split())
    lr.append((l - 1, r - 1))

t = []
for i in range(1, len(S) + 1):
    subset = S[:i]
    t.append(subset.count('AC'))
for l, r in lr:
    print(t[r] - t[l])


Fixed submission:
N, Q = map(int, input().split())
S = input()
cnt = [0]
for i in range(2, len(S) + 1):
    if S[i - 2:i] == 'AC':
        v = cnt[-1] + 1
    else:
        v = cnt[-1]
    cnt.append(v)

# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc122/tasks/abc122_c
import numpy as np

N, Q = map(int, input().split())
N = int(N)
S = input()
lr = []
for _ in range(Q):
    l, r = map(int, input().split())
    lr.append((l - 1, r - 1))
locations = []
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        locations.append(i)
locations = np.array(locations)
# print(locations)

for l, r in lr:
    subset = locations[(l <= locations) & (locations < r)]
    # print(l, r, subset)
    print(len(subset))


Fixed submission:
N, Q = map(int, input().split())
S = input()
cnt = [0]
for i in range(2, len(S) + 1):
    if S[i - 2:i] == 'AC':
        v = cnt[-1] + 1
    else:
        v = cnt[-1]
    cnt.append(v)

# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc122/tasks/abc122_c
import numpy as np

N, Q = map(int, input().split())
N = int(N)
S = input()
lr = []
for _ in range(Q):
    l, r = map(int, input().split())
    lr.append((l - 1, r - 1))
locations = []
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        locations.append(i)
locations = np.array(locations)
# print(locations)

for l, r in lr:
    subset = locations[l <= locations]
    subset = subset[subset < r]
    # print(l, r, subset)
    print(len(subset))


Fixed submission:
N, Q = map(int, input().split())
S = input()
cnt = [0]
for i in range(2, len(S) + 1):
    if S[i - 2:i] == 'AC':
        v = cnt[-1] + 1
    else:
        v = cnt[-1]
    cnt.append(v)

# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc122/tasks/abc122_c
import itertools

N, Q = map(int, input().split())
N = int(N)
S = input()
lr = []
for _ in range(Q):
    l, r = map(int, input().split())
    lr.append((l - 1, r - 1))
locations = []
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        locations.append(i)
# print(locations)

for l, r in lr:
    subset = list(itertools.filterfalse(lambda x: x < l, locations))
    subset = list(itertools.filterfalse(lambda x: x > r, subset))
    # print(l, r, subset)
    num_substring = len(subset)
    # print('num_substring', num_substring)
    if num_substring == 0:
        print(0)
        continue
    if subset[-1] == r:
        print(num_substring - 1)
    else:
        print(num_substring)


Fixed submission:
N, Q = map(int, input().split())
S = input()
cnt = [0]
for i in range(2, len(S) + 1):
    if S[i - 2:i] == 'AC':
        v = cnt[-1] + 1
    else:
        v = cnt[-1]
    cnt.append(v)

# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)

Buggy python submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc122/tasks/abc122_c
import itertools

N, Q = map(int, input().split())
N = int(N)
S = input()
lr = []
for _ in range(Q):
    l, r = map(int, input().split())
    lr.append((l - 1, r - 1))
locations = []
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        locations.append(i)
# print(locations)

for l, r in lr:
    subset = list(itertools.filterfalse(lambda x: x < l, locations))
    subset = list(itertools.filterfalse(lambda x: x > r, subset))
    # print(l, r, subset)
    num_substring = len(subset)
    # print('num_substring', num_substring)
    if subset[-1] == r:
        print(num_substring - 1)
    else:
        print(num_substring)


Fixed submission:
N, Q = map(int, input().split())
S = input()
cnt = [0]
for i in range(2, len(S) + 1):
    if S[i - 2:i] == 'AC':
        v = cnt[-1] + 1
    else:
        v = cnt[-1]
    cnt.append(v)

# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)