Buggy python submission (verdict: Runtime Error):
N, Q =  map(int, (input().split(' ')))
S = ' '+str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = ''
#i = 0
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, h, x):
        while h <= self.size:
            self.tree[h] += x
            h += h & -h

bit = Bit(N)     # 要素数を与えてインスタンス化
i = 1
while i < len(S):
    if S[i] == "A":
        if S[i+1] == "C":
            bit.add(i, 1)    # a2に10を加える
        else:
            pass
    i += 1

for left, right in lr:
    print(bit.sum(right-1) - bit.sum(left-1)) # a1～a6の合計を返す => 9





Fixed submission:
N, Q =  map(int, (input().split(' ')))
S = ' '+str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = ''
#i = 0
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, h, x):
        while h <= self.size:
            self.tree[h] += x
            h += h & -h

bit = Bit(N)     # 要素数を与えてインスタンス化
i = 1
while i < len(S)-1:
    if S[i] == "A":
        if S[i+1] == "C":
            bit.add(i, 1)    # a2に10を加える
        else:
            pass
    i += 1

for left, right in lr:
    print(bit.sum(right-1) - bit.sum(left-1)) # a1～a6の合計を返す => 9

Buggy python submission (verdict: Time Limit Exceeded):
N, Q =  map(int, (input().split(' ')))
S = str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = ''
i = 0
#while i < len(S):
#    if S[i] == "A":
#        if S[i+1] == "C":
#            save += 't'
#        else:
#            save += 'f'
#        i += 1
#    elif S[i] == "C":
#        i += 1
#        save += 'f'
#    else:
#        save += 'f'
#        i += 1

for left, right in lr:
    print(S[left-1: right].count('AC'))
    #save[left-1: right-1].count('t')
    #save[left-1: right-1]





Fixed submission:
N, Q =  map(int, (input().split(' ')))
S = ' '+str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = ''
#i = 0
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, h, x):
        while h <= self.size:
            self.tree[h] += x
            h += h & -h

bit = Bit(N)     # 要素数を与えてインスタンス化
i = 1
while i < len(S)-1:
    if S[i] == "A":
        if S[i+1] == "C":
            bit.add(i, 1)    # a2に10を加える
        else:
            pass
    i += 1

for left, right in lr:
    print(bit.sum(right-1) - bit.sum(left-1)) # a1～a6の合計を返す => 9

Buggy python submission (verdict: Runtime Error):
N, Q =  map(int, (input().split(' ')))
S = str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = [0] * N
print(N)
print(Q)
print(S)
i = 0
while i < len(S):
    if S[i] == "A":
        if S[i+1] == "C":
            save[i] = 1
        i += 1
    elif S[i] == "C":
        i += 1
    else:
        i+=1

for left, right in lr:
    print(sum(save[left-1: right-1]))





Fixed submission:
N, Q =  map(int, (input().split(' ')))
S = ' '+str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = ''
#i = 0
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, h, x):
        while h <= self.size:
            self.tree[h] += x
            h += h & -h

bit = Bit(N)     # 要素数を与えてインスタンス化
i = 1
while i < len(S)-1:
    if S[i] == "A":
        if S[i+1] == "C":
            bit.add(i, 1)    # a2に10を加える
        else:
            pass
    i += 1

for left, right in lr:
    print(bit.sum(right-1) - bit.sum(left-1)) # a1～a6の合計を返す => 9

Buggy python submission (verdict: Runtime Error):
N, Q =  map(int, (input().split(' ')))
S = str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = [0] * N
print(N)
print(Q)
print(S)
i = 0
while i < len(S):
    if S[i] == "A":
        if S[i+1] == "C":
            save[i] = 1
        i += 2N, Q =  map(int, (input().split(' ')))
S = str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = [0] * N
print(N)
print(Q)
print(S)
i = 0
while i < len(S):
    if S[i] == "A":
        if S[i+1] == "C":
            save[i] = 1
        i += 1
    elif S[i] == "C":
        i += 1
    else:
        i+=1

for left, right in lr:
    print(sum(save[left-1: right-1]))




    elif S[i] == "C":
        i += 1
    else:
        i+=1

for left, right in lr:
    print(sum(save[left-1: right-1]))





Fixed submission:
N, Q =  map(int, (input().split(' ')))
S = ' '+str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = ''
#i = 0
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, h, x):
        while h <= self.size:
            self.tree[h] += x
            h += h & -h

bit = Bit(N)     # 要素数を与えてインスタンス化
i = 1
while i < len(S)-1:
    if S[i] == "A":
        if S[i+1] == "C":
            bit.add(i, 1)    # a2に10を加える
        else:
            pass
    i += 1

for left, right in lr:
    print(bit.sum(right-1) - bit.sum(left-1)) # a1～a6の合計を返す => 9