Buggy python submission (verdict: Runtime Error):
# -*- coding:utf-8 -*-

def solve():
    N, Q = list(map(int, input().split()))
    S = input()

    dp = [0]*(N)
    dp[0] = 0
    for i in range(0, N-1):
        if S[i]=="A" and S[i+1]=="C":
            dp[i+1] = dp[i] + 1
        else:
            dp[i+1] = dp[i]
    
    for i in range(Q):
        l, r = list(map(int, input()))
        print(dp[r-1] - dp[l-1])
    
    

if __name__ == "__main__":
    solve()


Fixed submission:
# -*- coding:utf-8 -*-

def solve():
    N, Q = list(map(int, input().split(" ")))
    S = input()
    L, R = [], []
    for i in range(Q):
        l, r = list(map(int, input().split(" ")))
        L.append(l)
        R.append(r)
    
    # 累積話で解く
    accumulations = [0] * N

    for i in range(1, N):
        if S[i-1]+S[i] == "AC":
            accumulations[i] = accumulations[i-1] + 1
        else:
            accumulations[i] = accumulations[i-1]

    for i in range(Q):
        if L[i]-1 == 0:
            print(accumulations[R[i]-1])
            continue
        else:
            print(accumulations[R[i]-1] - accumulations[L[i]-1])
            continue


if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Runtime Error):
# -*- coding:utf-8 -*-

def solve():
    N, Q = list(map(int, input().split()))
    S = input()

    dp = [0]*(N)
    dp[0] = 0
    for i in range(0, N-1):
        if S[i]=="A" and S[i+1]=="C":
            dp[i+1] = dp[i] + 1
        else:
            dp[i+1] = dp[i]
    
    for i in range(Q):
        l, r = list(map(int, input()))
        print(dp[r-1] - dp[l-1])
    
    

if __name__ == "__main__":
    solve()


Fixed submission:
# -*- coding:utf-8 -*-

def solve():
    N, Q = list(map(int, input().split(" ")))
    S = input()
    L, R = [], []
    for i in range(Q):
        l, r = list(map(int, input().split(" ")))
        L.append(l)
        R.append(r)
    
    # 累積話で解く
    accumulations = [0] * N

    for i in range(1, N):
        if S[i-1]+S[i] == "AC":
            accumulations[i] = accumulations[i-1] + 1
        else:
            accumulations[i] = accumulations[i-1]

    for i in range(Q):
        if L[i]-1 == 0:
            print(accumulations[R[i]-1])
            continue
        else:
            print(accumulations[R[i]-1] - accumulations[L[i]-1])
            continue


if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding:utf-8 -*-

def solve():
    N, Q = list(map(int, input().split(" ")))
    S = input()
    L, R = [], []
    for i in range(Q):
        l, r = list(map(int, input().split(" ")))
        L.append(l)
        R.append(r)
    
    for i in range(Q):
        s = S[L[i]-1:R[i]]

        ans = 0
        if len(s) < 2:
            print(ans)
            continue
        
        for i in range(0, len(s)-1):
            if s[i]+s[i+1] == "AC":
                ans += 1
        print(ans)


if __name__ == "__main__":
    solve()

Fixed submission:
# -*- coding:utf-8 -*-

def solve():
    N, Q = list(map(int, input().split(" ")))
    S = input()
    L, R = [], []
    for i in range(Q):
        l, r = list(map(int, input().split(" ")))
        L.append(l)
        R.append(r)
    
    # 累積話で解く
    accumulations = [0] * N

    for i in range(1, N):
        if S[i-1]+S[i] == "AC":
            accumulations[i] = accumulations[i-1] + 1
        else:
            accumulations[i] = accumulations[i-1]

    for i in range(Q):
        if L[i]-1 == 0:
            print(accumulations[R[i]-1])
            continue
        else:
            print(accumulations[R[i]-1] - accumulations[L[i]-1])
            continue


if __name__ == "__main__":
    solve()