Buggy python submission (verdict: Time Limit Exceeded):
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = [list(map(int, input().split())) for _ in range(q)]

count_ac_list = [s[:i+1].count('AC') for i in range(n)]
count_list = [str(count_ac_list[r-1] - count_ac_list[l-1]) for l, r in lr_list]

print('\n'.join(count_list))


Fixed submission:
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = [list(map(int, input().split())) for _ in range(q)]

count_ac_list = [0] * n
for i in range(n-1):
    # print('{}: {}'.format(i, s[i:i+2]))
    if s[i:i+2] == 'AC':
        count_ac_list[i+1] = count_ac_list[i] + 1
    else:
        count_ac_list[i+1] = count_ac_list[i]

count_list = [str(count_ac_list[r-1] - count_ac_list[l-1]) for l, r in lr_list]

print('\n'.join(count_list))

Buggy python submission (verdict: Time Limit Exceeded):
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = []
lr_list = [list(map(int, input().split())) for _ in range(q)]

count_ac_list = [s[:i+1].count('AC') for i in range(n)]

count_list = [str(count_ac_list[r-1] - count_ac_list[l-1])
    if l > 1 else str(count_ac_list[r-1])
    for l, r in lr_list]

print('\n'.join(count_list))


Fixed submission:
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = [list(map(int, input().split())) for _ in range(q)]

count_ac_list = [0] * n
for i in range(n-1):
    # print('{}: {}'.format(i, s[i:i+2]))
    if s[i:i+2] == 'AC':
        count_ac_list[i+1] = count_ac_list[i] + 1
    else:
        count_ac_list[i+1] = count_ac_list[i]

count_list = [str(count_ac_list[r-1] - count_ac_list[l-1]) for l, r in lr_list]

print('\n'.join(count_list))

Buggy python submission (verdict: Time Limit Exceeded):
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = []
lr_list = [list(map(int, input().split())) for _ in range(q)]

count_ac_list = []
for i in range(n):
    count_ac_list.append(s[:i+1].count('AC'))

# print(count_ac_list)
count_list = [str(count_ac_list[r-1] - count_ac_list[l-1])
    if l > 1 else str(count_ac_list[r-1])
    for l, r in lr_list]

print('\n'.join(count_list))


Fixed submission:
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = [list(map(int, input().split())) for _ in range(q)]

count_ac_list = [0] * n
for i in range(n-1):
    # print('{}: {}'.format(i, s[i:i+2]))
    if s[i:i+2] == 'AC':
        count_ac_list[i+1] = count_ac_list[i] + 1
    else:
        count_ac_list[i+1] = count_ac_list[i]

count_list = [str(count_ac_list[r-1] - count_ac_list[l-1]) for l, r in lr_list]

print('\n'.join(count_list))

Buggy python submission (verdict: Time Limit Exceeded):
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = []

for _ in range(q):
    l, r = list(map(int, input().split()))
    lr_list.append((l, r))

count_ac_list = []
for i in range(n):
    count_ac_list.append(s[:i+1].count('AC'))

# print(count_ac_list)
count_list = [str(count_ac_list[r-1] - count_ac_list[l-1])
    if l > 1 else str(count_ac_list[r-1])
    for l, r in lr_list]

print('\n'.join(count_list))


Fixed submission:
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = [list(map(int, input().split())) for _ in range(q)]

count_ac_list = [0] * n
for i in range(n-1):
    # print('{}: {}'.format(i, s[i:i+2]))
    if s[i:i+2] == 'AC':
        count_ac_list[i+1] = count_ac_list[i] + 1
    else:
        count_ac_list[i+1] = count_ac_list[i]

count_list = [str(count_ac_list[r-1] - count_ac_list[l-1]) for l, r in lr_list]

print('\n'.join(count_list))

Buggy python submission (verdict: Time Limit Exceeded):
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = []

for _ in range(q):
    l, r = list(map(int, input().split()))
    lr_list.append((l, r))

count_ac_list = []
for i in range(n):
    count_ac_list.append(s[:i+1].count('AC'))

# print(count_ac_list)
count_list = [str(count_ac_list[r-1] - count_ac_list[l-1])
    if l > 1 else str(count_ac_list[r-1])
    for l, r in lr_list]

print('\n'.join(count_list))


Fixed submission:
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = [list(map(int, input().split())) for _ in range(q)]

count_ac_list = [0] * n
for i in range(n-1):
    # print('{}: {}'.format(i, s[i:i+2]))
    if s[i:i+2] == 'AC':
        count_ac_list[i+1] = count_ac_list[i] + 1
    else:
        count_ac_list[i+1] = count_ac_list[i]

count_list = [str(count_ac_list[r-1] - count_ac_list[l-1]) for l, r in lr_list]

print('\n'.join(count_list))

Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc122/tasks/abc122_c
# C - GeT AC

n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = []

for _ in range(q):
    l, r = list(map(int, input().split()))
    lr_list.append((l, r))

count_ac_list = []
for i in range(n):
    count_ac_list.append(s[:i+1].count('AC'))

# print(count_ac_list)
count_list = []

for l, r in lr_list:
    if l > 1:
        count = count_ac_list[r-1] - count_ac_list[l-1]
    else:
        count = count_ac_list[r-1]
    count_list.append(str(count))

print('\n'.join(count_list))


Fixed submission:
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = [list(map(int, input().split())) for _ in range(q)]

count_ac_list = [0] * n
for i in range(n-1):
    # print('{}: {}'.format(i, s[i:i+2]))
    if s[i:i+2] == 'AC':
        count_ac_list[i+1] = count_ac_list[i] + 1
    else:
        count_ac_list[i+1] = count_ac_list[i]

count_list = [str(count_ac_list[r-1] - count_ac_list[l-1]) for l, r in lr_list]

print('\n'.join(count_list))

Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc122/tasks/abc122_c
# C - GeT AC

n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = []

for _ in range(q):
    l, r = list(map(int, input().split()))
    lr_list.append((l, r))

count_ac_list = []
for i in range(n):
    count_ac_list.append(s[:i+1].count('AC'))

# print(count_ac_list)

for l, r in lr_list:
    if l > 1:
        count = count_ac_list[r-1] - count_ac_list[l-1]
    else:
        count = count_ac_list[r-1]
    print(count)


Fixed submission:
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = [list(map(int, input().split())) for _ in range(q)]

count_ac_list = [0] * n
for i in range(n-1):
    # print('{}: {}'.format(i, s[i:i+2]))
    if s[i:i+2] == 'AC':
        count_ac_list[i+1] = count_ac_list[i] + 1
    else:
        count_ac_list[i+1] = count_ac_list[i]

count_list = [str(count_ac_list[r-1] - count_ac_list[l-1]) for l, r in lr_list]

print('\n'.join(count_list))

Buggy python submission (verdict: Time Limit Exceeded):
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = []

for _ in range(q):
    l, r = list(map(int, input().split()))
    lr_list.append((l, r))

# あらかじめACがある位置を検索した方が良いのかもしれない
work_s = s.replace('AC', '*_')
matched_index_list = [i for i, x in enumerate(work_s) if x == '*']

for l, r in lr_list:
    # count = len([x for x in matched_index_list if l-1 <= x < r-1])
    count = 0
    for x in matched_index_list:
        if l-1 <= x < r-1:
            count += 1
        elif x >= r-1:
            break
    print(count)


Fixed submission:
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = [list(map(int, input().split())) for _ in range(q)]

count_ac_list = [0] * n
for i in range(n-1):
    # print('{}: {}'.format(i, s[i:i+2]))
    if s[i:i+2] == 'AC':
        count_ac_list[i+1] = count_ac_list[i] + 1
    else:
        count_ac_list[i+1] = count_ac_list[i]

count_list = [str(count_ac_list[r-1] - count_ac_list[l-1]) for l, r in lr_list]

print('\n'.join(count_list))

Buggy python submission (verdict: Time Limit Exceeded):
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = []

for _ in range(q):
    l, r = list(map(int, input().split()))
    lr_list.append((l, r))

# あらかじめACがある位置を検索した方が良いのかもしれない
work_s = s.replace('AC', '*_')
matched_index_list = [i for i, x in enumerate(work_s) if x == '*']

for l, r in lr_list:
    count = len([x for x in matched_index_list if l-1 <= x < r-1])
    print(count)


Fixed submission:
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = [list(map(int, input().split())) for _ in range(q)]

count_ac_list = [0] * n
for i in range(n-1):
    # print('{}: {}'.format(i, s[i:i+2]))
    if s[i:i+2] == 'AC':
        count_ac_list[i+1] = count_ac_list[i] + 1
    else:
        count_ac_list[i+1] = count_ac_list[i]

count_list = [str(count_ac_list[r-1] - count_ac_list[l-1]) for l, r in lr_list]

print('\n'.join(count_list))

Buggy python submission (verdict: Time Limit Exceeded):
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = []

for _ in range(q):
    l, r = list(map(int, input().split()))
    lr_list.append((l, r))

for l, r in lr_list:
    sub_s = s[l-1:r]
    count = sub_s.count('AC')
    print(count)


Fixed submission:
n, q = list(map(int, input().split()))
s = input().split()[0]
lr_list = [list(map(int, input().split())) for _ in range(q)]

count_ac_list = [0] * n
for i in range(n-1):
    # print('{}: {}'.format(i, s[i:i+2]))
    if s[i:i+2] == 'AC':
        count_ac_list[i+1] = count_ac_list[i] + 1
    else:
        count_ac_list[i+1] = count_ac_list[i]

count_list = [str(count_ac_list[r-1] - count_ac_list[l-1]) for l, r in lr_list]

print('\n'.join(count_list))